-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_client.go
107 lines (89 loc) · 2.6 KB
/
api_client.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
package api
import (
"fmt"
"github.com/lasthyphen/beacongo/api/admin"
"github.com/lasthyphen/beacongo/api/health"
"github.com/lasthyphen/beacongo/api/info"
"github.com/lasthyphen/beacongo/api/ipcs"
"github.com/lasthyphen/beacongo/api/keystore"
"github.com/lasthyphen/beacongo/indexer"
"github.com/lasthyphen/beacongo/vms/avm"
"github.com/lasthyphen/beacongo/vms/platformvm"
"github.com/lasthyphen/coreth/plugin/evm"
)
// interface compliance
var (
_ Client = (*APIClient)(nil)
_ NewAPIClientF = NewAPIClient
)
// APIClient gives access to most avalanchego apis (or suitable wrappers)
type APIClient struct {
platform platformvm.Client
xChain avm.Client
xChainWallet avm.WalletClient
cChain evm.Client
cChainEth EthClient
info info.Client
health health.Client
ipcs ipcs.Client
keystore keystore.Client
admin admin.Client
pindex indexer.Client
cindex indexer.Client
}
// Returns a new API client for a node at [ipAddr]:[port].
type NewAPIClientF func(ipAddr string, port uint16) Client
// NewAPIClient initialize most of avalanchego apis
func NewAPIClient(ipAddr string, port uint16) Client {
uri := fmt.Sprintf("http://%s:%d", ipAddr, port)
return &APIClient{
platform: platformvm.NewClient(uri),
xChain: avm.NewClient(uri, "X"),
xChainWallet: avm.NewWalletClient(uri, "X"),
cChain: evm.NewCChainClient(uri),
cChainEth: NewEthClient(ipAddr, uint(port)), // wrapper over ethclient.Client
info: info.NewClient(uri),
health: health.NewClient(uri),
ipcs: ipcs.NewClient(uri),
keystore: keystore.NewClient(uri),
admin: admin.NewClient(uri),
pindex: indexer.NewClient(uri + "/ext/index/P/block"),
cindex: indexer.NewClient(uri + "/ext/index/C/block"),
}
}
func (c APIClient) PChainAPI() platformvm.Client {
return c.platform
}
func (c APIClient) XChainAPI() avm.Client {
return c.xChain
}
func (c APIClient) XChainWalletAPI() avm.WalletClient {
return c.xChainWallet
}
func (c APIClient) CChainAPI() evm.Client {
return c.cChain
}
func (c APIClient) CChainEthAPI() EthClient {
return c.cChainEth
}
func (c APIClient) InfoAPI() info.Client {
return c.info
}
func (c APIClient) HealthAPI() health.Client {
return c.health
}
func (c APIClient) IpcsAPI() ipcs.Client {
return c.ipcs
}
func (c APIClient) KeystoreAPI() keystore.Client {
return c.keystore
}
func (c APIClient) AdminAPI() admin.Client {
return c.admin
}
func (c APIClient) PChainIndexAPI() indexer.Client {
return c.pindex
}
func (c APIClient) CChainIndexAPI() indexer.Client {
return c.cindex
}