From 4eaeb25a5e954de100e47c8bad2716a42a089cb9 Mon Sep 17 00:00:00 2001 From: CodeFace Date: Thu, 27 Jun 2019 15:10:29 +0800 Subject: [PATCH] qtum feerate check it seems there is an issue with qtum core rpc that "estimatesmartfee" can return feerate lower than minFeeRate sometimes --- bchain/coins/qtum/qtumrpc.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bchain/coins/qtum/qtumrpc.go b/bchain/coins/qtum/qtumrpc.go index a942ce3b..0991c00a 100644 --- a/bchain/coins/qtum/qtumrpc.go +++ b/bchain/coins/qtum/qtumrpc.go @@ -4,6 +4,7 @@ import ( "blockbook/bchain" "blockbook/bchain/coins/btc" "encoding/json" + "math/big" "github.com/golang/glog" ) @@ -11,6 +12,7 @@ import ( // QtumRPC is an interface to JSON-RPC bitcoind service. type QtumRPC struct { *btc.BitcoinRPC + minFeeRate *big.Int // satoshi per kb } // NewQtumRPC returns new QtumRPC instance. @@ -22,6 +24,7 @@ func NewQtumRPC(config json.RawMessage, pushHandler func(bchain.NotificationType s := &QtumRPC{ b.(*btc.BitcoinRPC), + big.NewInt(400000), } s.RPCMarshaler = btc.JSONMarshalerV1{} s.ChainConfig.SupportsEstimateSmartFee = true @@ -61,3 +64,14 @@ func (b *QtumRPC) Initialize() error { func (b *QtumRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) { return b.GetTransaction(txid) } + +// EstimateSmartFee returns fee estimation +func (b *QtumRPC) EstimateSmartFee(blocks int, conservative bool) (big.Int, error) { + feeRate, err := b.BitcoinRPC.EstimateSmartFee(blocks, conservative) + if err != nil { + if b.minFeeRate.Cmp(&feeRate) == 1 { + feeRate = *b.minFeeRate + } + } + return feeRate, err +}