-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathweb3.go
93 lines (74 loc) · 2.64 KB
/
web3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/********************************************************************************
This file is part of go-web3.
go-web3 is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
go-web3 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with go-web3. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
/**
* @file web3.go
* @authors:
* Reginaldo Costa <regcostajr@gmail.com>
* @date 2017
*/
package web3
import (
"github.com/regcostajr/go-web3/dto"
"github.com/regcostajr/go-web3/eth"
"github.com/regcostajr/go-web3/net"
"github.com/regcostajr/go-web3/personal"
"github.com/regcostajr/go-web3/providers"
)
// Coin - Ethereum value unity value
const Coin int64 = 1000000000000000000
// Web3 - The Web3 Module
type Web3 struct {
provider providers.ProviderInterface
Eth *eth.Eth
Net *net.Net
Personal *personal.Personal
}
// NewWeb3 - Web3 Module constructor to set the default provider, Eth, Net and Personal
func NewWeb3(provider providers.ProviderInterface) *Web3 {
web3 := new(Web3)
web3.Eth = eth.NewEth(provider)
web3.Net = net.NewNet(provider)
web3.Personal = personal.NewPersonal(provider)
web3.provider = provider
return web3
}
// ClientVersion - Returns the current client version.
// Reference: https://github.com/ethereum/wiki/wiki/JSON-RPC#web3_clientversion
// Parameters:
// - none
// Returns:
// - String - The current client version
func (web Web3) ClientVersion() (string, error) {
pointer := &dto.RequestResult{}
err := web.provider.SendRequest(pointer, "web3_clientVersion", nil)
if err != nil {
return "", err
}
return pointer.ToString()
}
// Sha3 - Returns Keccak-256 (not the standardized SHA3-256) of the given data.
// Reference: https://github.com/ethereum/wiki/wiki/JSON-RPC#web3_sha3
// - DATA - the data to convert into a SHA3 hash
// Returns:
// - DATA - The SHA3 result of the given string.
func (web Web3) Sha3(hexData string) (string, error) {
params := make([]string, 1)
params[0] = hexData
pointer := &dto.RequestResult{}
err := web.provider.SendRequest(pointer, "web3_sha3", params)
if err != nil {
return "", err
}
return pointer.ToString()
}