-
Notifications
You must be signed in to change notification settings - Fork 27
/
client_pos.go
112 lines (95 loc) · 4.21 KB
/
client_pos.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
108
109
110
111
112
package sdk
import (
"github.com/Conflux-Chain/go-conflux-sdk/types"
"github.com/Conflux-Chain/go-conflux-sdk/types/cfxaddress"
postypes "github.com/Conflux-Chain/go-conflux-sdk/types/pos"
"github.com/ethereum/go-ethereum/common/hexutil"
)
// RpcPosClient used to access pos namespace RPC of Conflux blockchain.
type RpcPosClient struct {
core *Client
}
// NewRpcPosClient creates a new RpcPosClient instance.
func NewRpcPosClient(core *Client) RpcPosClient {
return RpcPosClient{core}
}
// GetStatus returns pos chain status
func (c *RpcPosClient) GetStatus() (status postypes.Status, err error) {
err = c.core.CallRPC(&status, "pos_getStatus")
return
}
// GetAccount returns account info at block
func (c *RpcPosClient) GetAccount(address postypes.Address, blockNumber ...hexutil.Uint64) (account postypes.Account, err error) {
_view := get1stU64Ify(blockNumber)
if _view == nil {
err = c.core.CallRPC(&account, "pos_getAccount", address)
return
}
err = c.core.CallRPC(&account, "pos_getAccount", address, _view)
return
}
// GetAccount returns pos account of pow address info at block
func (c *RpcPosClient) GetAccountByPowAddress(address cfxaddress.Address, blockNumber ...hexutil.Uint64) (account postypes.Account, err error) {
_view := get1stU64Ify(blockNumber)
if _view == nil {
err = c.core.CallRPC(&account, "pos_getAccountByPowAddress", address)
return
}
err = c.core.CallRPC(&account, "pos_getAccountByPowAddress", address, _view)
return
}
// GetCommittee returns committee info at block
func (c *RpcPosClient) GetCommittee(blockNumber ...hexutil.Uint64) (committee postypes.CommitteeState, err error) {
_view := get1stU64Ify(blockNumber)
if _view == nil {
err = c.core.CallRPC(&committee, "pos_getCommittee")
return
}
err = c.core.CallRPC(&committee, "pos_getCommittee", _view)
return
}
// GetBlockByHash returns block info of block hash
func (c *RpcPosClient) GetBlockByHash(hash types.Hash) (block *postypes.Block, err error) {
err = c.core.CallRPC(&block, "pos_getBlockByHash", hash)
return
}
// GetBlockByHash returns block at block number
func (c *RpcPosClient) GetBlockByNumber(blockNumber postypes.BlockNumber) (block *postypes.Block, err error) {
err = c.core.CallRPC(&block, "pos_getBlockByNumber", blockNumber)
return
}
// GetTransactionByNumber returns transaction info of transaction number
func (c *RpcPosClient) GetTransactionByNumber(txNumber hexutil.Uint64) (transaction *postypes.Transaction, err error) {
err = c.core.CallRPC(&transaction, "pos_getTransactionByNumber", txNumber)
return
}
// GetRewardsByEpoch returns rewards of epoch
func (c *RpcPosClient) GetRewardsByEpoch(epochNumber hexutil.Uint64) (reward postypes.EpochReward, err error) {
err = c.core.CallRPC(&reward, "pos_getRewardsByEpoch", epochNumber)
return
}
// ========================================== debug rpcs =======================================================
func (c *RpcPosClient) GetConsensusBlocks() (blocks []*postypes.Block, err error) {
err = c.core.CallRPC(&blocks, "pos_getConsensusBlocks")
return
}
func (c *RpcPosClient) GetEpochState(epochNumber hexutil.Uint64) (epochState *postypes.EpochState, err error) {
err = c.core.CallRPC(&epochState, "pos_getEpochState", epochNumber)
return
}
func (c *RpcPosClient) GetLedgerInfoByBlockNumber(blockNumber postypes.BlockNumber) (ledgerInfoWithSigs *postypes.LedgerInfoWithSignatures, err error) {
err = c.core.CallRPC(&ledgerInfoWithSigs, "pos_getLedgerInfoByBlockNumber", blockNumber)
return
}
func (c *RpcPosClient) GetLedgerInfoByEpochAndRound(epochNumber hexutil.Uint64, round hexutil.Uint64) (ledgerInfoWithSigs *postypes.LedgerInfoWithSignatures, err error) {
err = c.core.CallRPC(&ledgerInfoWithSigs, "pos_getLedgerInfoByEpochAndRound", epochNumber, round)
return
}
func (c *RpcPosClient) GetLedgerInfoByEpoch(epochNumber hexutil.Uint64) (ledgerInfoWithSigs *postypes.LedgerInfoWithSignatures, err error) {
err = c.core.CallRPC(&ledgerInfoWithSigs, "pos_getLedgerInfoByEpoch", epochNumber)
return
}
func (c *RpcPosClient) GetLedgerInfosByEpoch(startEpoch hexutil.Uint64, endEpoch hexutil.Uint64) (ledgerInfoWithSigs []*postypes.LedgerInfoWithSignatures, err error) {
err = c.core.CallRPC(&ledgerInfoWithSigs, "pos_getLedgerInfosByEpoch", startEpoch, endEpoch)
return
}