Change asOfHeight to use -1 as default
This commit is contained in:
parent
6421f47ef7
commit
4b2203a1fd
|
@ -555,26 +555,30 @@ std::string asOfHeightMessage(bool hasMinconf) {
|
|||
? " `minconf` must be at least 1 when `asOfHeight` is provided.\n"
|
||||
: "";
|
||||
return
|
||||
"asOfHeight (numeric, optional, default “*”) Execute the query as if it\n"
|
||||
"asOfHeight (numeric, optional, default=-1) Execute the query as if it\n"
|
||||
" were run when the blockchain was at the height specified by\n"
|
||||
" this argument. The default is to use the entire blockchain\n"
|
||||
" that the node is aware of. A “future” height will fall back\n"
|
||||
" to the current height. Any explicit value will cause the\n"
|
||||
" mempool to be ignored, meaning no unconfirmed tx will be\n"
|
||||
" considered.\n"
|
||||
" that the node is aware of. -1 can be used as in other RPC\n"
|
||||
" calls to indicate the current height (including the\n"
|
||||
" mempool), but this does not support negative values in\n"
|
||||
" general. A “future” height will fall back to the current\n"
|
||||
" height. Any explicit value will cause the mempool to be\n"
|
||||
" ignored, meaning no unconfirmed tx will be considered.\n"
|
||||
+ minconfInteraction;
|
||||
}
|
||||
|
||||
std::optional<int> parseAsOfHeight(const UniValue& params, int index) {
|
||||
std::optional<int> asOfHeight;
|
||||
if (params.size() > index && !(params[index].isStr() && params[index].get_str() == "*")) {
|
||||
if (params.size() > index) {
|
||||
auto requestedHeight = params[index].get_int();
|
||||
if (requestedHeight < 0) {
|
||||
if (requestedHeight == -1) {
|
||||
// the default, do nothing
|
||||
} else if (requestedHeight < 0) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Can not perform the query as of a negative block height");
|
||||
} else if (requestedHeight == 0) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Can not perform the query as of the genesis block");
|
||||
} else {
|
||||
asOfHeight = params[index].get_int();
|
||||
asOfHeight = requestedHeight;
|
||||
}
|
||||
}
|
||||
return asOfHeight;
|
||||
|
|
Loading…
Reference in New Issue