Skip to content

Commit 8c3fdc5

Browse files
committed
made estimatesmartfee call estimatefee (for now)
1 parent a177146 commit 8c3fdc5

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

rpcserver.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{
137137
"decoderawtransaction": handleDecodeRawTransaction,
138138
"decodescript": handleDecodeScript,
139139
"estimatefee": handleEstimateFee,
140+
"estimatesmartfee": handleEstimateSmartFee,
140141
"generate": handleGenerate,
141142
"generatetoaddress": handleGenerateToAddress,
142143
"getaddednodeinfo": handleGetAddedNodeInfo,
@@ -879,23 +880,40 @@ func handleEstimateFee(s *rpcServer, cmd interface{}, closeChan <-chan struct{})
879880
c := cmd.(*btcjson.EstimateFeeCmd)
880881

881882
if s.cfg.FeeEstimator == nil {
882-
return nil, errors.New("Fee estimation disabled")
883+
return nil, &btcjson.RPCError{
884+
Code: btcjson.ErrRPCInternal.Code,
885+
Message: "Fee estimation disabled",
886+
}
883887
}
884888

885889
if c.NumBlocks <= 0 {
886-
return -1.0, errors.New("Parameter NumBlocks must be positive")
890+
return nil, &btcjson.RPCError{
891+
Code: btcjson.ErrRPCInvalidParameter,
892+
Message: "Parameter NumBlocks must be positive",
893+
}
887894
}
888895

889896
feeRate, err := s.cfg.FeeEstimator.EstimateFee(uint32(c.NumBlocks))
890897

891898
if err != nil {
892-
return -1.0, err
899+
return nil, &btcjson.RPCError{
900+
Code: btcjson.ErrRPCInvalidParameter,
901+
Message: err.Error(),
902+
}
893903
}
894904

895905
// Convert to satoshis per kb.
896906
return float64(feeRate), nil
897907
}
898908

909+
func handleEstimateSmartFee(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
910+
c := cmd.(*btcjson.EstimateSmartFeeCmd)
911+
912+
rpcsLog.Debugf("EstimateSmartFee is not implemented; falling back to EstimateFee. Requested mode: %s", c.EstimateMode)
913+
914+
return handleEstimateFee(s, &btcjson.EstimateFeeCmd{NumBlocks: c.ConfTarget}, closeChan)
915+
}
916+
899917
func handleGenerate(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
900918
// Respond with an error if there are no addresses to pay the
901919
// created blocks to.

rpcserverhelp.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,18 @@ var helpDescsEnUS = map[string]string{
123123
"blocks have been generated.",
124124
"estimatefee-numblocks": "The maximum number of blocks which can be " +
125125
"generated before the transaction is mined.",
126-
"estimatefee--result0": "Estimated fee per kilobyte in satoshis for a block to " +
126+
"estimatefee--result0": "Estimated fee per kilobyte in satoshis necessary for a block to " +
127127
"be mined in the next NumBlocks blocks.",
128128

129+
"estimatesmartfee--synopsis": "Estimate the fee per kilobyte in satoshis " +
130+
"required for a transaction to be mined before a certain number of " +
131+
"blocks have been generated. Same as estimatefee presently.",
132+
"estimatesmartfee-conftarget": "The maximum number of blocks which can be " +
133+
"generated before the transaction is mined.",
134+
"estimatesmartfee-estimatemode": "Unused at present.",
135+
"estimatesmartfee--result0": "Estimated fee per kilobyte in satoshis necessary for a block to " +
136+
"be mined in the next ConfTarget blocks.",
137+
129138
// GenerateCmd help
130139
"generate--synopsis": "Generates a set number of blocks (simnet or regtest only) and returns a JSON\n" +
131140
" array of their hashes.",
@@ -841,6 +850,7 @@ var rpcResultTypes = map[string][]interface{}{
841850
"decoderawtransaction": {(*btcjson.TxRawDecodeResult)(nil)},
842851
"decodescript": {(*btcjson.DecodeScriptResult)(nil)},
843852
"estimatefee": {(*float64)(nil)},
853+
"estimatesmartfee": {(*float64)(nil)},
844854
"generate": {(*[]string)(nil)},
845855
"generatetoaddress": {(*[]string)(nil)},
846856
"getaddednodeinfo": {(*[]string)(nil), (*[]btcjson.GetAddedNodeInfoResult)(nil)},

0 commit comments

Comments
 (0)