forked from laizy/web3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ens.go
118 lines (93 loc) · 2.79 KB
/
ens.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
package ens
import (
"fmt"
"math/big"
"github.com/laizy/web3"
"github.com/laizy/web3/contract"
"github.com/laizy/web3/jsonrpc"
)
var (
_ = big.NewInt
)
// ENS is a solidity contract
type ENS struct {
c *contract.Contract
}
// DeployENS deploys a new ENS contract
func DeployENS(provider *jsonrpc.Client, from web3.Address, args ...interface{}) *contract.Txn {
return contract.DeployContract(provider, from, abiENS, binENS, args...)
}
// NewENS creates a new instance of the contract at a specific address
func NewENS(addr web3.Address, provider *jsonrpc.Client) *ENS {
return &ENS{c: contract.NewContract(addr, abiENS, provider)}
}
// Contract returns the contract object
func (a *ENS) Contract() *contract.Contract {
return a.c
}
// calls
// Owner calls the owner method in the solidity contract
func (a *ENS) Owner(node [32]byte, block ...web3.BlockNumber) (val0 web3.Address, err error) {
var out map[string]interface{}
var ok bool
out, err = a.c.Call("owner", web3.EncodeBlock(block...), node)
if err != nil {
return
}
// decode outputs
val0, ok = out["0"].(web3.Address)
if !ok {
err = fmt.Errorf("failed to encode output at index 0")
return
}
return
}
// Resolver calls the resolver method in the solidity contract
func (a *ENS) Resolver(node [32]byte, block ...web3.BlockNumber) (val0 web3.Address, err error) {
var out map[string]interface{}
var ok bool
out, err = a.c.Call("resolver", web3.EncodeBlock(block...), node)
if err != nil {
return
}
// decode outputs
val0, ok = out["0"].(web3.Address)
if !ok {
err = fmt.Errorf("failed to encode output at index 0")
return
}
return
}
// Ttl calls the ttl method in the solidity contract
func (a *ENS) Ttl(node [32]byte, block ...web3.BlockNumber) (val0 uint64, err error) {
var out map[string]interface{}
var ok bool
out, err = a.c.Call("ttl", web3.EncodeBlock(block...), node)
if err != nil {
return
}
// decode outputs
val0, ok = out["0"].(uint64)
if !ok {
err = fmt.Errorf("failed to encode output at index 0")
return
}
return
}
// txns
// SetOwner sends a setOwner transaction in the solidity contract
func (a *ENS) SetOwner(node [32]byte, owner web3.Address) *contract.Txn {
return a.c.Txn("setOwner", node, owner)
}
// SetResolver sends a setResolver transaction in the solidity contract
func (a *ENS) SetResolver(node [32]byte, resolver web3.Address) *contract.Txn {
return a.c.Txn("setResolver", node, resolver)
}
// SetSubnodeOwner sends a setSubnodeOwner transaction in the solidity contract
func (a *ENS) SetSubnodeOwner(node [32]byte, label [32]byte, owner web3.Address) *contract.Txn {
return a.c.Txn("setSubnodeOwner", node, label, owner)
}
// SetTTL sends a setTTL transaction in the solidity contract
func (a *ENS) SetTTL(node [32]byte, ttl uint64) *contract.Txn {
return a.c.Txn("setTTL", node, ttl)
}