@@ -806,42 +806,59 @@ UniValue estimatesmartfee(const JSONRPCRequest& request)
806
806
{
807
807
if (request.fHelp || request.params .size () < 1 || request.params .size () > 2 )
808
808
throw std::runtime_error (
809
- " estimatesmartfee nblocks (conservative )\n "
809
+ " estimatesmartfee conf_target ( \" estimate_mode \" )\n "
810
810
" \n Estimates the approximate fee per kilobyte needed for a transaction to begin\n "
811
- " confirmation within nblocks blocks if possible and return the number of blocks\n "
811
+ " confirmation within conf_target blocks if possible and return the number of blocks\n "
812
812
" for which the estimate is valid. Uses virtual transaction size as defined\n "
813
813
" in BIP 141 (witness data is discounted).\n "
814
814
" \n Arguments:\n "
815
- " 1. nblocks (numeric)\n "
816
- " 2. conservative (bool, optional, default=true) Whether to return a more conservative estimate which\n "
817
- " also satisfies a longer history. A conservative estimate potentially returns a higher\n "
818
- " feerate and is more likely to be sufficient for the desired target, but is not as\n "
819
- " responsive to short term drops in the prevailing fee market\n "
815
+ " 1. conf_target (numeric) Confirmation target in blocks (1 - 1008)\n "
816
+ " 2. \" estimate_mode\" (string, optional, default=CONSERVATIVE) The fee estimate mode.\n "
817
+ " Whether to return a more conservative estimate which also satisfies\n "
818
+ " a longer history. A conservative estimate potentially returns a\n "
819
+ " higher feerate and is more likely to be sufficient for the desired\n "
820
+ " target, but is not as responsive to short term drops in the\n "
821
+ " prevailing fee market. Must be one of:\n "
822
+ " \" UNSET\" (defaults to CONSERVATIVE)\n "
823
+ " \" ECONOMICAL\"\n "
824
+ " \" CONSERVATIVE\"\n "
820
825
" \n Result:\n "
821
826
" {\n "
822
- " \" feerate\" : x.x, (numeric) estimate fee-per-kilobyte (in BTC)\n "
827
+ " \" feerate\" : x.x, (numeric, optional) estimate fee-per-kilobyte (in BTC)\n "
828
+ " \" errors\" : [ str... ] (json array of strings, optional) Errors encountered during processing\n "
823
829
" \" blocks\" : n (numeric) block number where estimate was found\n "
824
830
" }\n "
825
831
" \n "
826
- " A negative value is returned if not enough transactions and blocks\n "
832
+ " The request target will be clamped between 2 and the highest target\n "
833
+ " fee estimation is able to return based on how long it has been running.\n "
834
+ " An error is returned if not enough transactions and blocks\n "
827
835
" have been observed to make an estimate for any number of blocks.\n "
828
836
" \n Example:\n "
829
837
+ HelpExampleCli (" estimatesmartfee" , " 6" )
830
838
);
831
839
832
- RPCTypeCheck (request.params , {UniValue::VNUM});
833
-
834
- int nBlocks = request.params [0 ]. get_int ( );
840
+ RPCTypeCheck (request.params , {UniValue::VNUM, UniValue::VSTR });
841
+ RPCTypeCheckArgument (request. params [ 0 ], UniValue::VNUM);
842
+ unsigned int conf_target = ParseConfirmTarget ( request.params [0 ]);
835
843
bool conservative = true ;
836
844
if (request.params .size () > 1 && !request.params [1 ].isNull ()) {
837
- RPCTypeCheckArgument (request.params [1 ], UniValue::VBOOL);
838
- conservative = request.params [1 ].get_bool ();
845
+ FeeEstimateMode fee_mode;
846
+ if (!FeeModeFromString (request.params [1 ].get_str (), fee_mode)) {
847
+ throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid estimate_mode parameter" );
848
+ }
849
+ if (fee_mode == FeeEstimateMode::ECONOMICAL) conservative = false ;
839
850
}
840
851
841
852
UniValue result (UniValue::VOBJ);
853
+ UniValue errors (UniValue::VARR);
842
854
FeeCalculation feeCalc;
843
- CFeeRate feeRate = ::feeEstimator.estimateSmartFee (nBlocks, &feeCalc, conservative);
844
- result.push_back (Pair (" feerate" , feeRate == CFeeRate (0 ) ? -1.0 : ValueFromAmount (feeRate.GetFeePerK ())));
855
+ CFeeRate feeRate = ::feeEstimator.estimateSmartFee (conf_target, &feeCalc, conservative);
856
+ if (feeRate != CFeeRate (0 )) {
857
+ result.push_back (Pair (" feerate" , ValueFromAmount (feeRate.GetFeePerK ())));
858
+ } else {
859
+ errors.push_back (" Insufficient data or no feerate found" );
860
+ result.push_back (Pair (" errors" , errors));
861
+ }
845
862
result.push_back (Pair (" blocks" , feeCalc.returnedTarget ));
846
863
return result;
847
864
}
@@ -850,18 +867,18 @@ UniValue estimaterawfee(const JSONRPCRequest& request)
850
867
{
851
868
if (request.fHelp || request.params .size () < 1 || request.params .size () > 2 )
852
869
throw std::runtime_error (
853
- " estimaterawfee nblocks (threshold)\n "
870
+ " estimaterawfee conf_target (threshold)\n "
854
871
" \n WARNING: This interface is unstable and may disappear or change!\n "
855
872
" \n WARNING: This is an advanced API call that is tightly coupled to the specific\n "
856
873
" implementation of fee estimation. The parameters it can be called with\n "
857
874
" and the results it returns will change if the internal implementation changes.\n "
858
875
" \n Estimates the approximate fee per kilobyte needed for a transaction to begin\n "
859
- " confirmation within nblocks blocks if possible. Uses virtual transaction size as defined \n "
860
- " in BIP 141 (witness data is discounted).\n "
876
+ " confirmation within conf_target blocks if possible. Uses virtual transaction size as\n "
877
+ " defined in BIP 141 (witness data is discounted).\n "
861
878
" \n Arguments:\n "
862
- " 1. nblocks (numeric) Confirmation target in blocks (1 - 1008)\n "
879
+ " 1. conf_target (numeric) Confirmation target in blocks (1 - 1008)\n "
863
880
" 2. threshold (numeric, optional) The proportion of transactions in a given feerate range that must have been\n "
864
- " confirmed within nblocks in order to consider those feerates as high enough and proceed to check\n "
881
+ " confirmed within conf_target in order to consider those feerates as high enough and proceed to check\n "
865
882
" lower buckets. Default: 0.95\n "
866
883
" \n Result:\n "
867
884
" {\n "
@@ -889,12 +906,9 @@ UniValue estimaterawfee(const JSONRPCRequest& request)
889
906
+ HelpExampleCli (" estimaterawfee" , " 6 0.9" )
890
907
);
891
908
892
- RPCTypeCheck (request.params , {UniValue::VNUM, UniValue::VNUM, UniValue::VNUM }, true );
909
+ RPCTypeCheck (request.params , {UniValue::VNUM, UniValue::VNUM}, true );
893
910
RPCTypeCheckArgument (request.params [0 ], UniValue::VNUM);
894
- int nBlocks = request.params [0 ].get_int ();
895
- if (nBlocks < 1 || (unsigned int )nBlocks > ::feeEstimator.HighestTargetTracked (FeeEstimateHorizon::LONG_HALFLIFE)) {
896
- throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid nblocks" );
897
- }
911
+ unsigned int conf_target = ParseConfirmTarget (request.params [0 ]);
898
912
double threshold = 0.95 ;
899
913
if (!request.params [1 ].isNull ()) {
900
914
threshold = request.params [1 ].get_real ();
@@ -910,9 +924,9 @@ UniValue estimaterawfee(const JSONRPCRequest& request)
910
924
EstimationResult buckets;
911
925
912
926
// Only output results for horizons which track the target
913
- if (( unsigned int )nBlocks > ::feeEstimator.HighestTargetTracked (horizon)) continue ;
927
+ if (conf_target > ::feeEstimator.HighestTargetTracked (horizon)) continue ;
914
928
915
- feeRate = ::feeEstimator.estimateRawFee (nBlocks , threshold, horizon, &buckets);
929
+ feeRate = ::feeEstimator.estimateRawFee (conf_target , threshold, horizon, &buckets);
916
930
UniValue horizon_result (UniValue::VOBJ);
917
931
UniValue errors (UniValue::VARR);
918
932
UniValue passbucket (UniValue::VOBJ);
@@ -963,9 +977,9 @@ static const CRPCCommand commands[] =
963
977
{ " generating" , " generatetoaddress" , &generatetoaddress, true , {" nblocks" ," address" ," maxtries" } },
964
978
965
979
{ " util" , " estimatefee" , &estimatefee, true , {" nblocks" } },
966
- { " util" , " estimatesmartfee" , &estimatesmartfee, true , {" nblocks " , " conservative " } },
980
+ { " util" , " estimatesmartfee" , &estimatesmartfee, true , {" conf_target " , " estimate_mode " } },
967
981
968
- { " hidden" , " estimaterawfee" , &estimaterawfee, true , {" nblocks " , " threshold" } },
982
+ { " hidden" , " estimaterawfee" , &estimaterawfee, true , {" conf_target " , " threshold" } },
969
983
};
970
984
971
985
void RegisterMiningRPCCommands (CRPCTable &t)
0 commit comments