forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
client.go
60 lines (50 loc) · 2.22 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
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package ipcs
import (
"context"
"github.com/MetalBlockchain/metalgo/api"
"github.com/MetalBlockchain/metalgo/ids"
"github.com/MetalBlockchain/metalgo/utils/rpc"
)
var _ Client = (*client)(nil)
// Client interface for interacting with the IPCS endpoint
//
// Deprecated: The IPCs API is deprecated. The Index API should be used instead.
type Client interface {
// PublishBlockchain requests the node to begin publishing consensus and decision events
PublishBlockchain(ctx context.Context, chainID string, options ...rpc.Option) (*PublishBlockchainReply, error)
// UnpublishBlockchain requests the node to stop publishing consensus and decision events
UnpublishBlockchain(ctx context.Context, chainID string, options ...rpc.Option) error
// GetPublishedBlockchains requests the node to get blockchains being published
GetPublishedBlockchains(ctx context.Context, options ...rpc.Option) ([]ids.ID, error)
}
// Client implementation for interacting with the IPCS endpoint
type client struct {
requester rpc.EndpointRequester
}
// NewClient returns a Client for interacting with the IPCS endpoint
//
// Deprecated: The IPCs API is deprecated. The Index API should be used instead.
func NewClient(uri string) Client {
return &client{requester: rpc.NewEndpointRequester(
uri + "/ext/ipcs",
)}
}
func (c *client) PublishBlockchain(ctx context.Context, blockchainID string, options ...rpc.Option) (*PublishBlockchainReply, error) {
res := &PublishBlockchainReply{}
err := c.requester.SendRequest(ctx, "ipcs.publishBlockchain", &PublishBlockchainArgs{
BlockchainID: blockchainID,
}, res, options...)
return res, err
}
func (c *client) UnpublishBlockchain(ctx context.Context, blockchainID string, options ...rpc.Option) error {
return c.requester.SendRequest(ctx, "ipcs.unpublishBlockchain", &UnpublishBlockchainArgs{
BlockchainID: blockchainID,
}, &api.EmptyReply{}, options...)
}
func (c *client) GetPublishedBlockchains(ctx context.Context, options ...rpc.Option) ([]ids.ID, error) {
res := &GetPublishedBlockchainsReply{}
err := c.requester.SendRequest(ctx, "ipcs.getPublishedBlockchains", nil, res, options...)
return res.Chains, err
}