57
57
DefaultDepositorFee = DepositorFee (defaultDepositorFeeRate )
58
58
)
59
59
60
- type RPC interface {
60
+ type BitcoinClient interface {
61
61
GetBlockCount (ctx context.Context ) (int64 , error )
62
62
GetBlockHash (ctx context.Context , blockHeight int64 ) (* chainhash.Hash , error )
63
63
GetBlockHeader (ctx context.Context , hash * chainhash.Hash ) (* wire.BlockHeader , error )
@@ -66,7 +66,7 @@ type RPC interface {
66
66
}
67
67
68
68
// DepositorFeeCalculator is a function type to calculate the Bitcoin depositor fee
69
- type DepositorFeeCalculator func (context.Context , RPC , * btcjson.TxRawResult , * chaincfg.Params ) (float64 , error )
69
+ type DepositorFeeCalculator func (context.Context , BitcoinClient , * btcjson.TxRawResult , * chaincfg.Params ) (float64 , error )
70
70
71
71
// FeeRateToSatPerByte converts a fee rate from BTC/KB to sat/vB.
72
72
func FeeRateToSatPerByte (rate float64 ) (uint64 , error ) {
@@ -237,7 +237,7 @@ func CalcBlockAvgFeeRate(blockVb *btcjson.GetBlockVerboseTxResult, netParams *ch
237
237
// CalcDepositorFee calculates the depositor fee for a given tx result
238
238
func CalcDepositorFee (
239
239
ctx context.Context ,
240
- rpc RPC ,
240
+ bitcoinClient BitcoinClient ,
241
241
rawResult * btcjson.TxRawResult ,
242
242
netParams * chaincfg.Params ,
243
243
) (float64 , error ) {
@@ -247,7 +247,7 @@ func CalcDepositorFee(
247
247
}
248
248
249
249
// get fee rate of the transaction
250
- _ , feeRate , err := rpc .GetTransactionFeeAndRate (ctx , rawResult )
250
+ _ , feeRate , err := bitcoinClient .GetTransactionFeeAndRate (ctx , rawResult )
251
251
if err != nil {
252
252
return 0 , errors .Wrapf (err , "error getting fee rate for tx %s" , rawResult .Txid )
253
253
}
@@ -261,14 +261,17 @@ func CalcDepositorFee(
261
261
262
262
// GetRecentFeeRate gets the highest fee rate from recent blocks
263
263
// Note: this method should be used for testnet ONLY
264
- func GetRecentFeeRate (ctx context.Context , rpc RPC , netParams * chaincfg.Params ) (uint64 , error ) {
264
+ func GetRecentFeeRate (ctx context.Context ,
265
+ bitcoinClient BitcoinClient ,
266
+ netParams * chaincfg.Params ,
267
+ ) (uint64 , error ) {
265
268
// should avoid using this method for mainnet
266
269
if netParams .Name == chaincfg .MainNetParams .Name {
267
270
return 0 , errors .New ("GetRecentFeeRate should not be used for mainnet" )
268
271
}
269
272
270
273
// get the current block number
271
- blockNumber , err := rpc .GetBlockCount (ctx )
274
+ blockNumber , err := bitcoinClient .GetBlockCount (ctx )
272
275
if err != nil {
273
276
return 0 , err
274
277
}
@@ -277,11 +280,11 @@ func GetRecentFeeRate(ctx context.Context, rpc RPC, netParams *chaincfg.Params)
277
280
highestRate := int64 (0 )
278
281
for i := int64 (0 ); i < feeRateCountBackBlocks ; i ++ {
279
282
// get the block
280
- hash , err := rpc .GetBlockHash (ctx , blockNumber - i )
283
+ hash , err := bitcoinClient .GetBlockHash (ctx , blockNumber - i )
281
284
if err != nil {
282
285
return 0 , err
283
286
}
284
- block , err := rpc .GetBlockVerbose (ctx , hash )
287
+ block , err := bitcoinClient .GetBlockVerbose (ctx , hash )
285
288
if err != nil {
286
289
return 0 , err
287
290
}
0 commit comments