diff --git a/rpc/client.go b/rpc/client.go index e4f2c457..1e45c583 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -53,8 +53,12 @@ type Client interface { // GetCellbaseOutputCapacityDetails returns each component of the created CKB in this block's cellbase, // which is issued to a block N - 1 - ProposalWindow.farthest, where this block's height is N. + // Deprecated: This method will be disabled by default from v0.40.0 and will be removed from v0.41.0,Please use the method GetBlockEconomicState instead. GetCellbaseOutputCapacityDetails(ctx context.Context, hash types.Hash) (*types.BlockReward, error) + // GetBlockEconomicState return block economic state, It includes the rewards details and when it is finalized. + GetBlockEconomicState(ctx context.Context, hash types.Hash) (*types.BlockEconomicState, error) + // GetBlockByNumber get block by number GetBlockByNumber(ctx context.Context, number uint64) (*types.Block, error) @@ -292,6 +296,7 @@ func (cli *client) GetTransaction(ctx context.Context, hash types.Hash) (*types. }, err } +// Deprecated: This method will be disabled by default from v0.40.0 and will be removed from v0.41.0,Please use the method GetBlockEconomicState instead. func (cli *client) GetCellbaseOutputCapacityDetails(ctx context.Context, hash types.Hash) (*types.BlockReward, error) { var result blockReward err := cli.c.CallContext(ctx, &result, "get_cellbase_output_capacity_details", hash) @@ -692,3 +697,31 @@ func (cli *client) GetTransactions(ctx context.Context, searchKey *indexer.Searc } return cli.indexer.GetTransactions(ctx, searchKey, order, limit, afterCursor) } + +func (cli *client) GetBlockEconomicState(ctx context.Context, blockHash types.Hash) (*types.BlockEconomicState, error) { + var result blockEconomicState + err := cli.c.CallContext(ctx, &result, "get_block_economic_state", blockHash) + if err != nil { + return nil, err + } + + // if FinalizedAt is equal to "0x0000000000000000000000000000000000000000000000000000000000000000" means block economic state is empty + if result.FinalizedAt == types.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000") { + return nil, nil + } + + return &types.BlockEconomicState{ + Issuance: types.BlockIssuance{ + Primary: (*big.Int)(&result.Issuance.Primary), + Secondary: (*big.Int)(&result.Issuance.Secondary), + }, + MinerReward: types.MinerReward{ + Primary: (*big.Int)(&result.MinerReward.Primary), + Secondary: (*big.Int)(&result.MinerReward.Secondary), + Committed: (*big.Int)(&result.MinerReward.Committed), + Proposal: (*big.Int)(&result.MinerReward.Proposal), + }, + TxsFee: (*big.Int)(&result.TxsFee), + FinalizedAt: result.FinalizedAt, + }, err +} diff --git a/rpc/types.go b/rpc/types.go index 27e98eca..47273ce3 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -205,6 +205,25 @@ type blockchainInfo struct { MedianTime hexutil.Uint64 `json:"median_time"` } +type blockEconomicState struct { + Issuance blockIssuance `json:"issuance"` + MinerReward minerReward `json:"miner_reward"` + TxsFee hexutil.Big `json:"txs_fee"` + FinalizedAt types.Hash `json:"finalized_at"` +} + +type blockIssuance struct { + Primary hexutil.Big `json:"primary"` + Secondary hexutil.Big `json:"secondary"` +} + +type minerReward struct { + Primary hexutil.Big `json:"primary"` + Secondary hexutil.Big `json:"secondary"` + Committed hexutil.Big `json:"committed"` + Proposal hexutil.Big `json:"proposal"` +} + func toHeader(head header) *types.Header { return &types.Header{ CompactTarget: uint(head.CompactTarget), diff --git a/types/chain.go b/types/chain.go index 36a93862..fc3b15d7 100644 --- a/types/chain.go +++ b/types/chain.go @@ -219,3 +219,22 @@ type BlockReward struct { Total *big.Int `json:"total"` TxFee *big.Int `json:"tx_fee"` } + +type BlockEconomicState struct { + Issuance BlockIssuance `json:"issuance"` + MinerReward MinerReward `json:"miner_reward"` + TxsFee *big.Int `json:"txs_fee"` + FinalizedAt Hash `json:"finalized_at"` +} + +type BlockIssuance struct { + Primary *big.Int `json:"primary"` + Secondary *big.Int `json:"secondary"` +} + +type MinerReward struct { + Primary *big.Int `json:"primary"` + Secondary *big.Int `json:"secondary"` + Committed *big.Int `json:"committed"` + Proposal *big.Int `json:"proposal"` +}