[lbry] rpcserver: made estimatesmartfee call estimatefee (for now)

This commit is contained in:
Brannon King 2021-11-09 15:50:02 -05:00 committed by Roy Lee
parent d20a2e53b4
commit 6c0360fa42
2 changed files with 32 additions and 4 deletions

View file

@ -137,6 +137,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{
"decoderawtransaction": handleDecodeRawTransaction, "decoderawtransaction": handleDecodeRawTransaction,
"decodescript": handleDecodeScript, "decodescript": handleDecodeScript,
"estimatefee": handleEstimateFee, "estimatefee": handleEstimateFee,
"estimatesmartfee": handleEstimateSmartFee,
"generate": handleGenerate, "generate": handleGenerate,
"generatetoaddress": handleGenerateToAddress, "generatetoaddress": handleGenerateToAddress,
"getaddednodeinfo": handleGetAddedNodeInfo, "getaddednodeinfo": handleGetAddedNodeInfo,
@ -879,23 +880,40 @@ func handleEstimateFee(s *rpcServer, cmd interface{}, closeChan <-chan struct{})
c := cmd.(*btcjson.EstimateFeeCmd) c := cmd.(*btcjson.EstimateFeeCmd)
if s.cfg.FeeEstimator == nil { 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 { 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)) feeRate, err := s.cfg.FeeEstimator.EstimateFee(uint32(c.NumBlocks))
if err != nil { if err != nil {
return -1.0, err return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidParameter,
Message: err.Error(),
}
} }
// Convert to satoshis per kb. // Convert to satoshis per kb.
return float64(feeRate), nil 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) { func handleGenerate(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
// Respond with an error if there are no addresses to pay the // Respond with an error if there are no addresses to pay the
// created blocks to. // created blocks to.

View file

@ -123,9 +123,18 @@ var helpDescsEnUS = map[string]string{
"blocks have been generated.", "blocks have been generated.",
"estimatefee-numblocks": "The maximum number of blocks which can be " + "estimatefee-numblocks": "The maximum number of blocks which can be " +
"generated before the transaction is mined.", "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.", "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 // GenerateCmd help
"generate--synopsis": "Generates a set number of blocks (simnet or regtest only) and returns a JSON\n" + "generate--synopsis": "Generates a set number of blocks (simnet or regtest only) and returns a JSON\n" +
" array of their hashes.", " array of their hashes.",
@ -841,6 +850,7 @@ var rpcResultTypes = map[string][]interface{}{
"decoderawtransaction": {(*btcjson.TxRawDecodeResult)(nil)}, "decoderawtransaction": {(*btcjson.TxRawDecodeResult)(nil)},
"decodescript": {(*btcjson.DecodeScriptResult)(nil)}, "decodescript": {(*btcjson.DecodeScriptResult)(nil)},
"estimatefee": {(*float64)(nil)}, "estimatefee": {(*float64)(nil)},
"estimatesmartfee": {(*float64)(nil)},
"generate": {(*[]string)(nil)}, "generate": {(*[]string)(nil)},
"generatetoaddress": {(*[]string)(nil)}, "generatetoaddress": {(*[]string)(nil)},
"getaddednodeinfo": {(*[]string)(nil), (*[]btcjson.GetAddedNodeInfoResult)(nil)}, "getaddednodeinfo": {(*[]string)(nil), (*[]btcjson.GetAddedNodeInfoResult)(nil)},