Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show All 20 Lines | |||||
#include <wallet/rpcwallet.h> | #include <wallet/rpcwallet.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <boost/algorithm/string.hpp> | #include <boost/algorithm/string.hpp> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <tuple> | #include <tuple> | ||||
using interfaces::FoundBlock; | |||||
static std::string EncodeDumpString(const std::string &str) { | static std::string EncodeDumpString(const std::string &str) { | ||||
std::stringstream ret; | std::stringstream ret; | ||||
for (const uint8_t c : str) { | for (const uint8_t c : str) { | ||||
if (c <= 32 || c >= 128 || c == '%') { | if (c <= 32 || c >= 128 || c == '%') { | ||||
ret << '%' << HexStr(&c, &c + 1); | ret << '%' << HexStr(&c, &c + 1); | ||||
} else { | } else { | ||||
ret << c; | ret << c; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 383 Lines • ▼ Show 20 Lines | UniValue importprunedfunds(const Config &config, | ||||
std::vector<size_t> vIndex; | std::vector<size_t> vIndex; | ||||
if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != | if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != | ||||
merkleBlock.header.hashMerkleRoot) { | merkleBlock.header.hashMerkleRoot) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Something wrong with merkleblock"); | "Something wrong with merkleblock"); | ||||
} | } | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
Optional<int> height = | LOCK(pwallet->cs_wallet); | ||||
locked_chain->getBlockHeight(merkleBlock.header.GetHash()); | int height; | ||||
if (height == nullopt) { | if (!pwallet->chain().findAncestorByHash(pwallet->GetLastBlockHash(), | ||||
merkleBlock.header.GetHash(), | |||||
FoundBlock().height(height))) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Block not found in chain"); | "Block not found in chain"); | ||||
} | } | ||||
std::vector<uint256>::const_iterator it; | std::vector<uint256>::const_iterator it; | ||||
if ((it = std::find(vMatch.begin(), vMatch.end(), txid)) == vMatch.end()) { | if ((it = std::find(vMatch.begin(), vMatch.end(), txid)) == vMatch.end()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Transaction given doesn't exist in proof"); | "Transaction given doesn't exist in proof"); | ||||
} | } | ||||
size_t txnIndex = vIndex[it - vMatch.begin()]; | size_t txnIndex = vIndex[it - vMatch.begin()]; | ||||
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, *height, | CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, height, | ||||
merkleBlock.header.GetHash(), txnIndex); | merkleBlock.header.GetHash(), txnIndex); | ||||
wtx.m_confirm = confirm; | wtx.m_confirm = confirm; | ||||
LOCK(pwallet->cs_wallet); | |||||
if (pwallet->IsMine(*wtx.tx)) { | if (pwallet->IsMine(*wtx.tx)) { | ||||
pwallet->AddToWallet(wtx, false); | pwallet->AddToWallet(wtx, false); | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_ADDRESS_OR_KEY, | RPC_INVALID_ADDRESS_OR_KEY, | ||||
"No addresses in wallet correspond to included transaction"); | "No addresses in wallet correspond to included transaction"); | ||||
▲ Show 20 Lines • Show All 1,385 Lines • Show Last 20 Lines |