-
Notifications
You must be signed in to change notification settings - Fork 669
/
client.go
48 lines (40 loc) · 1.49 KB
/
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
// (c) 2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package ipcs
import (
"time"
"github.com/ava-labs/avalanchego/api"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/rpc"
)
type Client struct {
requester rpc.EndpointRequester
}
// NewClient returns a Client for interacting with the IPCS endpoint
func NewClient(uri string, requestTimeout time.Duration) *Client {
return &Client{
requester: rpc.NewEndpointRequester(uri, "/ext/ipcs", "ipcs", requestTimeout),
}
}
// PublishBlockchain requests the node to begin publishing consensus and decision events
func (c *Client) PublishBlockchain(blockchainID string) (*PublishBlockchainReply, error) {
res := &PublishBlockchainReply{}
err := c.requester.SendRequest("publishBlockchain", &PublishBlockchainArgs{
BlockchainID: blockchainID,
}, res)
return res, err
}
// UnpublishBlockchain requests the node to stop publishing consensus and decision events
func (c *Client) UnpublishBlockchain(blockchainID string) (bool, error) {
res := &api.SuccessResponse{}
err := c.requester.SendRequest("unpublishBlockchain", &UnpublishBlockchainArgs{
BlockchainID: blockchainID,
}, res)
return res.Success, err
}
// GetPublishedBlockchains requests the node to get blockchains being published
func (c *Client) GetPublishedBlockchains() ([]ids.ID, error) {
res := &GetPublishedBlockchainsReply{}
err := c.requester.SendRequest("getPublishedBlockchains", nil, res)
return res.Chains, err
}