forked from ava-labs/timestampvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
59 lines (45 loc) · 1.53 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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package client
import (
"context"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/rpc"
"github.com/tamil-reddev/zcash-oracle/zcash"
)
// Client defines zcash client operations.
type Client interface {
// GetBlock fetches the contents of a block
GetBlock(ctx context.Context, blockID *ids.ID) (uint64, zcash.ZcashBlock, uint64, ids.ID, ids.ID, error)
GetBlockByHeight(ctx context.Context, blockID uint64) (uint64, zcash.ZcashBlock, uint64, ids.ID, ids.ID, error)
}
// New creates a new client object.
func New(uri string) Client {
req := rpc.NewEndpointRequester(uri)
return &client{req: req}
}
type client struct {
req rpc.EndpointRequester
}
func (cli *client) GetBlock(ctx context.Context, blockID *ids.ID) (uint64, zcash.ZcashBlock, uint64, ids.ID, ids.ID, error) {
resp := new(zcash.GetBlockReply)
err := cli.req.SendRequest(ctx,
"zcash.getBlock",
&zcash.GetBlockArgs{ID: blockID},
resp,
)
if err != nil {
}
return uint64(resp.Timestamp), resp.Data, uint64(resp.Height), resp.ID, resp.ParentID, nil
}
func (cli *client) GetBlockByHeight(ctx context.Context, id uint64) (uint64, zcash.ZcashBlock, uint64, ids.ID, ids.ID, error) {
resp := new(zcash.GetBlockReply)
err := cli.req.SendRequest(ctx,
"zcash.getBlockByHeight",
&zcash.QueryDataArgs{ID: id},
resp,
)
if err != nil {
}
return uint64(resp.Timestamp), resp.Data, uint64(resp.Height), resp.ID, resp.ParentID, nil
}