rpcwallet: Replace pwallet-> with wallet.

pwallet is never null everywhere where it is dereferenced, so simply
replace it with a reference, which can not be null by definition.
This commit is contained in:
MarcoFalke 2020-05-11 10:05:50 -04:00
parent fa182a8794
commit fa1f840596
No known key found for this signature in database
GPG key ID: CE2B75697E69A548

View file

@ -1482,10 +1482,9 @@ UniValue listtransactions(const JSONRPCRequest& request)
static UniValue listsinceblock(const JSONRPCRequest& request) static UniValue listsinceblock(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet.get(), request.fHelp)) {
return NullUniValue; return NullUniValue;
} }
@ -1542,11 +1541,12 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
}, },
}.Check(request); }.Check(request);
const CWallet& wallet = *pwallet;
// Make sure the results are valid at least up to the most recent block // Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now // the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain(); wallet.BlockUntilSyncedToCurrentChain();
LOCK(pwallet->cs_wallet); LOCK(wallet.cs_wallet);
// The way the 'height' is initialized is just a workaround for the gcc bug #47679 since version 4.6.0. // The way the 'height' is initialized is just a workaround for the gcc bug #47679 since version 4.6.0.
Optional<int> height = MakeOptional(false, int()); // Height of the specified block or the common ancestor, if the block provided was in a deactivated chain. Optional<int> height = MakeOptional(false, int()); // Height of the specified block or the common ancestor, if the block provided was in a deactivated chain.
@ -1559,7 +1559,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
blockId = ParseHashV(request.params[0], "blockhash"); blockId = ParseHashV(request.params[0], "blockhash");
height = int{}; height = int{};
altheight = int{}; altheight = int{};
if (!pwallet->chain().findCommonAncestor(blockId, pwallet->GetLastBlockHash(), /* ancestor out */ FoundBlock().height(*height), /* blockId out */ FoundBlock().height(*altheight))) { if (!wallet.chain().findCommonAncestor(blockId, wallet.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");
} }
} }
@ -1572,21 +1572,21 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
} }
} }
if (ParseIncludeWatchonly(request.params[2], *pwallet)) { if (ParseIncludeWatchonly(request.params[2], wallet)) {
filter |= ISMINE_WATCH_ONLY; filter |= ISMINE_WATCH_ONLY;
} }
bool include_removed = (request.params[3].isNull() || request.params[3].get_bool()); bool include_removed = (request.params[3].isNull() || request.params[3].get_bool());
int depth = height ? pwallet->GetLastBlockHeight() + 1 - *height : -1; int depth = height ? wallet.GetLastBlockHeight() + 1 - *height : -1;
UniValue transactions(UniValue::VARR); UniValue transactions(UniValue::VARR);
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) { for (const std::pair<const uint256, CWalletTx>& pairWtx : wallet.mapWallet) {
const CWalletTx& tx = pairWtx.second; const CWalletTx& tx = pairWtx.second;
if (depth == -1 || abs(tx.GetDepthInMainChain()) < depth) { if (depth == -1 || abs(tx.GetDepthInMainChain()) < depth) {
ListTransactions(pwallet, tx, 0, true, transactions, filter, nullptr /* filter_label */); ListTransactions(&wallet, tx, 0, true, transactions, filter, nullptr /* filter_label */);
} }
} }
@ -1595,15 +1595,15 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
UniValue removed(UniValue::VARR); UniValue removed(UniValue::VARR);
while (include_removed && altheight && *altheight > *height) { while (include_removed && altheight && *altheight > *height) {
CBlock block; CBlock block;
if (!pwallet->chain().findBlock(blockId, FoundBlock().data(block)) || block.IsNull()) { if (!wallet.chain().findBlock(blockId, FoundBlock().data(block)) || block.IsNull()) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
} }
for (const CTransactionRef& tx : block.vtx) { for (const CTransactionRef& tx : block.vtx) {
auto it = pwallet->mapWallet.find(tx->GetHash()); auto it = wallet.mapWallet.find(tx->GetHash());
if (it != pwallet->mapWallet.end()) { if (it != wallet.mapWallet.end()) {
// We want all transactions regardless of confirmation count to appear here, // We want all transactions regardless of confirmation count to appear here,
// even negative confirmation ones, hence the big negative. // even negative confirmation ones, hence the big negative.
ListTransactions(pwallet, it->second, -100000000, true, removed, filter, nullptr /* filter_label */); ListTransactions(&wallet, it->second, -100000000, true, removed, filter, nullptr /* filter_label */);
} }
} }
blockId = block.hashPrevBlock; blockId = block.hashPrevBlock;
@ -1611,7 +1611,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
} }
uint256 lastblock; uint256 lastblock;
CHECK_NONFATAL(pwallet->chain().findAncestorByHeight(pwallet->GetLastBlockHash(), pwallet->GetLastBlockHeight() + 1 - target_confirms, FoundBlock().hash(lastblock))); CHECK_NONFATAL(wallet.chain().findAncestorByHeight(wallet.GetLastBlockHash(), wallet.GetLastBlockHeight() + 1 - target_confirms, FoundBlock().hash(lastblock)));
UniValue ret(UniValue::VOBJ); UniValue ret(UniValue::VOBJ);
ret.pushKV("transactions", transactions); ret.pushKV("transactions", transactions);