-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovider.go
More file actions
63 lines (52 loc) · 1.24 KB
/
provider.go
File metadata and controls
63 lines (52 loc) · 1.24 KB
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
package ethutils
import (
"math/big"
"net/http"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/lmittmann/w3"
)
type (
Option func(c *Provider)
Provider struct {
Client *w3.Client
Signer types.Signer
BalanceScannerContractAddress string
DivviConsumerAddress common.Address
DivviClient *http.Client
}
)
func WithSigner(signer types.Signer) Option {
return func(p *Provider) {
p.Signer = signer
}
}
func WithClient(w3Client *w3.Client) Option {
return func(p *Provider) {
p.Client = w3Client
}
}
func WithBalanceScannerAddress(address string) Option {
return func(p *Provider) {
p.BalanceScannerContractAddress = address
}
}
func WithDivviConsumerAddress(address string) Option {
return func(p *Provider) {
p.DivviConsumerAddress = w3.A(address)
p.DivviClient = &http.Client{
Timeout: time.Second * 10,
}
}
}
func NewProvider(url string, chainID int64, opts ...Option) *Provider {
defaultProvider := &Provider{
Client: w3.MustDial(url),
Signer: types.LatestSignerForChainID(big.NewInt(chainID)),
}
for _, opt := range opts {
opt(defaultProvider)
}
return defaultProvider
}