-
Notifications
You must be signed in to change notification settings - Fork 1
/
erc20.go
79 lines (61 loc) · 1.8 KB
/
erc20.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
package ethereumWallet
import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ranjbar-dev/ethereum-wallet/enums"
"github.com/ranjbar-dev/ethereum-wallet/geth"
token "github.com/ranjbar-dev/ethereum-wallet/geth/contractErc20"
"math/big"
)
type Token struct {
ContractAddress enums.ContractAddress
}
func (t *Token) GetName(node Node) (string, error) {
c, err := geth.GetGETHClient(node.Http)
if err != nil {
return "", err
}
contractAddress := common.HexToAddress(t.ContractAddress.String())
tokenInstance, err := token.NewToken(contractAddress, c)
if err != nil {
return "", err
}
return tokenInstance.Name(&bind.CallOpts{})
}
func (t *Token) GetSymbol(node Node) (string, error) {
c, err := geth.GetGETHClient(node.Http)
if err != nil {
return "", err
}
contractAddress := common.HexToAddress(t.ContractAddress.String())
tokenInstance, err := token.NewToken(contractAddress, c)
if err != nil {
return "", err
}
return tokenInstance.Symbol(&bind.CallOpts{})
}
func (t *Token) GetDecimals(node Node) (uint8, error) {
c, err := geth.GetGETHClient(node.Http)
if err != nil {
return 0, err
}
contractAddress := common.HexToAddress(t.ContractAddress.String())
tokenInstance, err := token.NewToken(contractAddress, c)
if err != nil {
return 0, err
}
return tokenInstance.Decimals(&bind.CallOpts{})
}
func (t *Token) GetBalance(node Node, addressHex string) (*big.Int, error) {
c, err := geth.GetGETHClient(node.Http)
if err != nil {
return nil, err
}
contractAddress := common.HexToAddress(t.ContractAddress.String())
address := common.HexToAddress(addressHex)
tokenInstance, err := token.NewToken(contractAddress, c)
if err != nil {
return nil, err
}
return tokenInstance.BalanceOf(&bind.CallOpts{}, address)
}