From 8c3fdc5b6123374e1267bd5cd92190ddf2623feb Mon Sep 17 00:00:00 2001 From: Brannon King Date: Tue, 9 Nov 2021 15:50:02 -0500 Subject: [PATCH] made estimatesmartfee call estimatefee (for now) --- rpcserver.go | 24 +++++++++++++++++++++--- rpcserverhelp.go | 12 +++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 9848ac6d..588e4179 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -137,6 +137,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{ "decoderawtransaction": handleDecodeRawTransaction, "decodescript": handleDecodeScript, "estimatefee": handleEstimateFee, + "estimatesmartfee": handleEstimateSmartFee, "generate": handleGenerate, "generatetoaddress": handleGenerateToAddress, "getaddednodeinfo": handleGetAddedNodeInfo, @@ -879,23 +880,40 @@ func handleEstimateFee(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) c := cmd.(*btcjson.EstimateFeeCmd) if s.cfg.FeeEstimator == nil { - return nil, errors.New("Fee estimation disabled") + return nil, &btcjson.RPCError{ + Code: btcjson.ErrRPCInternal.Code, + Message: "Fee estimation disabled", + } } if c.NumBlocks <= 0 { - return -1.0, errors.New("Parameter NumBlocks must be positive") + return nil, &btcjson.RPCError{ + Code: btcjson.ErrRPCInvalidParameter, + Message: "Parameter NumBlocks must be positive", + } } feeRate, err := s.cfg.FeeEstimator.EstimateFee(uint32(c.NumBlocks)) if err != nil { - return -1.0, err + return nil, &btcjson.RPCError{ + Code: btcjson.ErrRPCInvalidParameter, + Message: err.Error(), + } } // Convert to satoshis per kb. return float64(feeRate), nil } +func handleEstimateSmartFee(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { + c := cmd.(*btcjson.EstimateSmartFeeCmd) + + rpcsLog.Debugf("EstimateSmartFee is not implemented; falling back to EstimateFee. Requested mode: %s", c.EstimateMode) + + return handleEstimateFee(s, &btcjson.EstimateFeeCmd{NumBlocks: c.ConfTarget}, closeChan) +} + func handleGenerate(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { // Respond with an error if there are no addresses to pay the // created blocks to. diff --git a/rpcserverhelp.go b/rpcserverhelp.go index 2d191649..881cfeb5 100644 --- a/rpcserverhelp.go +++ b/rpcserverhelp.go @@ -123,9 +123,18 @@ var helpDescsEnUS = map[string]string{ "blocks have been generated.", "estimatefee-numblocks": "The maximum number of blocks which can be " + "generated before the transaction is mined.", - "estimatefee--result0": "Estimated fee per kilobyte in satoshis for a block to " + + "estimatefee--result0": "Estimated fee per kilobyte in satoshis necessary for a block to " + "be mined in the next NumBlocks blocks.", + "estimatesmartfee--synopsis": "Estimate the fee per kilobyte in satoshis " + + "required for a transaction to be mined before a certain number of " + + "blocks have been generated. Same as estimatefee presently.", + "estimatesmartfee-conftarget": "The maximum number of blocks which can be " + + "generated before the transaction is mined.", + "estimatesmartfee-estimatemode": "Unused at present.", + "estimatesmartfee--result0": "Estimated fee per kilobyte in satoshis necessary for a block to " + + "be mined in the next ConfTarget blocks.", + // GenerateCmd help "generate--synopsis": "Generates a set number of blocks (simnet or regtest only) and returns a JSON\n" + " array of their hashes.", @@ -841,6 +850,7 @@ var rpcResultTypes = map[string][]interface{}{ "decoderawtransaction": {(*btcjson.TxRawDecodeResult)(nil)}, "decodescript": {(*btcjson.DecodeScriptResult)(nil)}, "estimatefee": {(*float64)(nil)}, + "estimatesmartfee": {(*float64)(nil)}, "generate": {(*[]string)(nil)}, "generatetoaddress": {(*[]string)(nil)}, "getaddednodeinfo": {(*[]string)(nil), (*[]btcjson.GetAddedNodeInfoResult)(nil)},