-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhotpot.go
More file actions
60 lines (48 loc) · 1.2 KB
/
hotpot.go
File metadata and controls
60 lines (48 loc) · 1.2 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
package hotpot
import (
"context"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/lamlv2305/hotpot/contract"
"math/rand"
"time"
)
var (
source = rand.NewSource(time.Now().UnixNano())
rng = rand.New(source)
zeroAddress = common.Address{}
multicallABI, _ = contract.MultiCallMetaData.GetAbi()
erc20ABI, _ = contract.ERC20MetaData.GetAbi()
)
func WithMultiCallAddress(address common.Address) func(*Hotpot) {
return func(h *Hotpot) {
h.multicallAddress = address
}
}
func NewHotpot(rpc []string, options ...func(*Hotpot)) *Hotpot {
hp := &Hotpot{
// https://www.multicall3.com/
multicallAddress: common.HexToAddress("0xcA11bde05977b3631167028862bE2a173976CA11"),
}
for idx := range rpc {
client, err := ethclient.DialContext(context.Background(), rpc[idx])
if err != nil {
continue
}
hp.clients = append(hp.clients, client)
}
for idx := range options {
options[idx](hp)
}
return hp
}
type Hotpot struct {
clients []*ethclient.Client
multicallAddress common.Address
}
func (h Hotpot) randomClient() *ethclient.Client {
if len(h.clients) == 0 {
return nil
}
return h.clients[rng.Intn(len(h.clients))]
}