forked from laizy/web3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolver.go
193 lines (155 loc) · 4.64 KB
/
resolver.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package ens
import (
"fmt"
"math/big"
"github.com/laizy/web3"
"github.com/laizy/web3/contract"
"github.com/laizy/web3/jsonrpc"
)
var (
_ = big.NewInt
)
// Resolver is a solidity contract
type Resolver struct {
c *contract.Contract
}
// DeployResolver deploys a new Resolver contract
func DeployResolver(provider *jsonrpc.Client, from web3.Address, args ...interface{}) *contract.Txn {
return contract.DeployContract(provider, from, abiResolver, binResolver, args...)
}
// NewResolver creates a new instance of the contract at a specific address
func NewResolver(addr web3.Address, provider *jsonrpc.Client) *Resolver {
return &Resolver{c: contract.NewContract(addr, abiResolver, provider)}
}
// Contract returns the contract object
func (a *Resolver) Contract() *contract.Contract {
return a.c
}
// calls
// ABI calls the ABI method in the solidity contract
func (a *Resolver) ABI(node [32]byte, contentTypes *big.Int, block ...web3.BlockNumber) (val0 *big.Int, val1 []byte, err error) {
var out map[string]interface{}
var ok bool
out, err = a.c.Call("ABI", web3.EncodeBlock(block...), node, contentTypes)
if err != nil {
return
}
// decode outputs
val0, ok = out["contentType"].(*big.Int)
if !ok {
err = fmt.Errorf("failed to encode output at index 0")
return
}
val1, ok = out["data"].([]byte)
if !ok {
err = fmt.Errorf("failed to encode output at index 1")
return
}
return
}
// Addr calls the addr method in the solidity contract
func (a *Resolver) Addr(node [32]byte, block ...web3.BlockNumber) (val0 web3.Address, err error) {
var out map[string]interface{}
var ok bool
out, err = a.c.Call("addr", web3.EncodeBlock(block...), node)
if err != nil {
return
}
// decode outputs
val0, ok = out["ret"].(web3.Address)
if !ok {
err = fmt.Errorf("failed to encode output at index 0")
return
}
return
}
// Content calls the content method in the solidity contract
func (a *Resolver) Content(node [32]byte, block ...web3.BlockNumber) (val0 [32]byte, err error) {
var out map[string]interface{}
var ok bool
out, err = a.c.Call("content", web3.EncodeBlock(block...), node)
if err != nil {
return
}
// decode outputs
val0, ok = out["ret"].([32]byte)
if !ok {
err = fmt.Errorf("failed to encode output at index 0")
return
}
return
}
// Name calls the name method in the solidity contract
func (a *Resolver) Name(node [32]byte, block ...web3.BlockNumber) (val0 string, err error) {
var out map[string]interface{}
var ok bool
out, err = a.c.Call("name", web3.EncodeBlock(block...), node)
if err != nil {
return
}
// decode outputs
val0, ok = out["ret"].(string)
if !ok {
err = fmt.Errorf("failed to encode output at index 0")
return
}
return
}
// Pubkey calls the pubkey method in the solidity contract
func (a *Resolver) Pubkey(node [32]byte, block ...web3.BlockNumber) (val0 [32]byte, val1 [32]byte, err error) {
var out map[string]interface{}
var ok bool
out, err = a.c.Call("pubkey", web3.EncodeBlock(block...), node)
if err != nil {
return
}
// decode outputs
val0, ok = out["x"].([32]byte)
if !ok {
err = fmt.Errorf("failed to encode output at index 0")
return
}
val1, ok = out["y"].([32]byte)
if !ok {
err = fmt.Errorf("failed to encode output at index 1")
return
}
return
}
// SupportsInterface calls the supportsInterface method in the solidity contract
func (a *Resolver) SupportsInterface(interfaceID [4]byte, block ...web3.BlockNumber) (val0 bool, err error) {
var out map[string]interface{}
var ok bool
out, err = a.c.Call("supportsInterface", web3.EncodeBlock(block...), interfaceID)
if err != nil {
return
}
// decode outputs
val0, ok = out["0"].(bool)
if !ok {
err = fmt.Errorf("failed to encode output at index 0")
return
}
return
}
// txns
// SetABI sends a setABI transaction in the solidity contract
func (a *Resolver) SetABI(node [32]byte, contentType *big.Int, data []byte) *contract.Txn {
return a.c.Txn("setABI", node, contentType, data)
}
// SetAddr sends a setAddr transaction in the solidity contract
func (a *Resolver) SetAddr(node [32]byte, addr web3.Address) *contract.Txn {
return a.c.Txn("setAddr", node, addr)
}
// SetContent sends a setContent transaction in the solidity contract
func (a *Resolver) SetContent(node [32]byte, hash [32]byte) *contract.Txn {
return a.c.Txn("setContent", node, hash)
}
// SetName sends a setName transaction in the solidity contract
func (a *Resolver) SetName(node [32]byte, name string) *contract.Txn {
return a.c.Txn("setName", node, name)
}
// SetPubkey sends a setPubkey transaction in the solidity contract
func (a *Resolver) SetPubkey(node [32]byte, x [32]byte, y [32]byte) *contract.Txn {
return a.c.Txn("setPubkey", node, x, y)
}