Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 1,864 Lines • ▼ Show 20 Lines | static UniValue listsinceblock(const Config &config, | ||||
// Height of the specified block, even if it's in a deactivated chain. | // Height of the specified block, even if it's in a deactivated chain. | ||||
Optional<int> altheight; | Optional<int> altheight; | ||||
int target_confirms = 1; | int target_confirms = 1; | ||||
isminefilter filter = ISMINE_SPENDABLE; | isminefilter filter = ISMINE_SPENDABLE; | ||||
BlockHash blockId; | BlockHash blockId; | ||||
if (!request.params[0].isNull() && !request.params[0].get_str().empty()) { | if (!request.params[0].isNull() && !request.params[0].get_str().empty()) { | ||||
blockId = BlockHash(ParseHashV(request.params[0], "blockhash")); | blockId = BlockHash(ParseHashV(request.params[0], "blockhash")); | ||||
height = locked_chain->findFork(blockId, &altheight); | height.emplace(); | ||||
if (!height) { | altheight.emplace(); | ||||
if (!pwallet->chain().findCommonAncestor( | |||||
blockId, pwallet->GetLastBlockHash(), | |||||
/* ancestor out */ FoundBlock().height(*height), | |||||
/* blockId out */ FoundBlock().height(*altheight))) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||||
} | } | ||||
} | } | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
target_confirms = request.params[1].get_int(); | target_confirms = request.params[1].get_int(); | ||||
if (target_confirms < 1) { | if (target_confirms < 1) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter"); | ||||
} | } | ||||
} | } | ||||
if (ParseIncludeWatchonly(request.params[2], *pwallet)) { | if (ParseIncludeWatchonly(request.params[2], *pwallet)) { | ||||
filter |= ISMINE_WATCH_ONLY; | filter |= ISMINE_WATCH_ONLY; | ||||
} | } | ||||
bool include_removed = | bool include_removed = | ||||
(request.params[3].isNull() || request.params[3].get_bool()); | (request.params[3].isNull() || request.params[3].get_bool()); | ||||
const Optional<int> tip_height = locked_chain->getHeight(); | int depth = height ? pwallet->GetLastBlockHeight() + 1 - *height : -1; | ||||
int depth = tip_height && height ? (1 + *tip_height - *height) : -1; | |||||
UniValue transactions(UniValue::VARR); | UniValue transactions(UniValue::VARR); | ||||
for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
CWalletTx tx = pairWtx.second; | CWalletTx tx = pairWtx.second; | ||||
if (depth == -1 || tx.GetDepthInMainChain() < depth) { | if (depth == -1 || tx.GetDepthInMainChain() < depth) { | ||||
ListTransactions(*locked_chain, pwallet, tx, 0, true, transactions, | ListTransactions(*locked_chain, pwallet, tx, 0, true, transactions, | ||||
Show All 21 Lines | while (include_removed && altheight && *altheight > *height) { | ||||
true, removed, filter, | true, removed, filter, | ||||
nullptr /* filter_label */); | nullptr /* filter_label */); | ||||
} | } | ||||
} | } | ||||
blockId = block.hashPrevBlock; | blockId = block.hashPrevBlock; | ||||
--*altheight; | --*altheight; | ||||
} | } | ||||
int last_height = tip_height ? *tip_height + 1 - target_confirms : -1; | BlockHash lastblock; | ||||
BlockHash lastblock = last_height >= 0 | CHECK_NONFATAL(pwallet->chain().findAncestorByHeight( | ||||
? locked_chain->getBlockHash(last_height) | pwallet->GetLastBlockHash(), | ||||
: BlockHash(); | pwallet->GetLastBlockHeight() + 1 - target_confirms, | ||||
FoundBlock().hash(lastblock))); | |||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
ret.pushKV("transactions", transactions); | ret.pushKV("transactions", transactions); | ||||
if (include_removed) { | if (include_removed) { | ||||
ret.pushKV("removed", removed); | ret.pushKV("removed", removed); | ||||
} | } | ||||
ret.pushKV("lastblock", lastblock.GetHex()); | ret.pushKV("lastblock", lastblock.GetHex()); | ||||
▲ Show 20 Lines • Show All 2,948 Lines • Show Last 20 Lines |