From 8858d3ca533fe560863c1e989836f2c269de39d2 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Sun, 4 Aug 2024 09:01:56 +0800 Subject: [PATCH] Support RPC GetFeeRateStatistics Signed-off-by: Eval EXEC --- rpc/client.go | 15 +++++++++++---- rpc/client_test.go | 4 ++-- types/chain.go | 2 ++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/rpc/client.go b/rpc/client.go index 97a8aac5..d1dc1338 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -98,9 +98,12 @@ type Client interface { // Note that the given block is included in the median time. The included block number range is [MAX(block - 36, 0), block]. GetBlockMedianTime(ctx context.Context, blockHash types.Hash) (uint64, error) - // GetFeeRateStatics Returns the fee_rate statistics of confirmed blocks on the chain + // Deprecated: use GetFeeRateStatistics instead GetFeeRateStatics(ctx context.Context, target interface{}) (*types.FeeRateStatics, error) + // GetFeeRateStatistics Returns the fee_rate statistics of confirmed blocks on the chain + GetFeeRateStatistics(ctx context.Context, target interface{}) (*types.FeeRateStatistics, error) + ////// Experiment // DryRunTransaction dry run transaction and return the execution cycles. // This method will not check the transaction validity, @@ -535,15 +538,19 @@ func (cli *client) GetBlockMedianTime(ctx context.Context, blockHash types.Hash) } func (cli *client) GetFeeRateStatics(ctx context.Context, target interface{}) (*types.FeeRateStatics, error) { - var result types.FeeRateStatics + return cli.GetFeeRateStatistics(ctx, target) +} + +func (cli *client) GetFeeRateStatistics(ctx context.Context, target interface{}) (*types.FeeRateStatistics, error) { + var result types.FeeRateStatistics switch target := target.(type) { case nil: - if err := cli.c.CallContext(ctx, &result, "get_fee_rate_statics", nil); err != nil { + if err := cli.c.CallContext(ctx, &result, "get_fee_rate_statistics", nil); err != nil { return nil, err } break case uint64: - if err := cli.c.CallContext(ctx, &result, "get_fee_rate_statics", hexutil.Uint64(target)); err != nil { + if err := cli.c.CallContext(ctx, &result, "get_fee_rate_statistics", hexutil.Uint64(target)); err != nil { return nil, err } break diff --git a/rpc/client_test.go b/rpc/client_test.go index 2c12eef7..73854d81 100644 --- a/rpc/client_test.go +++ b/rpc/client_test.go @@ -488,10 +488,10 @@ func TestGetTransactionsGrouped(t *testing.T) { } func TestClient_GetFeeRateStatics(t *testing.T) { - statics, err := testClient.GetFeeRateStatics(context.Background(), nil) + statics, err := testClient.GetFeeRateStatistics(context.Background(), nil) assert.NoError(t, err) assert.NotNil(t, statics) - statics2, err := testClient.GetFeeRateStatics(context.Background(), 1) + statics2, err := testClient.GetFeeRateStatistics(context.Background(), 1) assert.NoError(t, err) assert.NotNil(t, statics2) } diff --git a/types/chain.go b/types/chain.go index f92ca0d3..d038ec03 100644 --- a/types/chain.go +++ b/types/chain.go @@ -331,6 +331,8 @@ type FeeRateStatics struct { Median uint64 `json:"median"` } +type FeeRAteStatistics = FeeRateStatics + type TransactionAndWitnessProof struct { BlockHash Hash `json:"block_hash"` TransactionsProof *Proof `json:"transactions_proof"`