Skip to content

Commit

Permalink
feat: btc SuggestFeeRate add to chain.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhangguiguang committed Nov 22, 2023
1 parent abc2ffe commit bba9c1a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions core/btc/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ type FeeRate struct {
High int64
}

func (c *Chain) SuggestFeeRate() (rates *FeeRate, err error) {
switch c.Chainnet {
case ChainBitcoin, ChainMainnet:
return SuggestFeeRate()
default:
return &FeeRate{1, 1, 1}, nil
}
}

func SuggestFeeRate() (rates *FeeRate, err error) {
defer base.CatchPanicAndMapToBasicError(&err)

Expand Down
16 changes: 15 additions & 1 deletion core/btc/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,21 @@ func TestChain_FetchTransactionDetail(t *testing.T) {
}

func TestChain_SuggestFeeRate(t *testing.T) {
t.Log(SuggestFeeRate())
chains := []string{
ChainMainnet,
ChainSignet,
ChainTestnet,
}
for _, chainnet := range chains {
t.Run(chainnet, func(t *testing.T) {
t.Logf("===== %v =====", chainnet)
chain, err := NewChainWithChainnet(chainnet)
require.Nil(t, err)
rate, err := chain.SuggestFeeRate()
require.Nil(t, err)
t.Logf("\n high: %v\n average: %v\n low: %v\n", rate.High, rate.Average, rate.Low)
})
}
}

func TestChain_BatchFetchTransactionStatus(t *testing.T) {
Expand Down

0 comments on commit bba9c1a

Please sign in to comment.