Skip to content

Commit

Permalink
Support RPC GetFeeRateStatistics
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <execvy@gmail.com>
  • Loading branch information
eval-exec committed Aug 4, 2024
1 parent b4f527f commit 8858d3c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
15 changes: 11 additions & 4 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions types/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 8858d3c

Please sign in to comment.