Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 280 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 2) | ||||
"1. \"rawtransaction\" (string, required) A raw transaction in hex " | "1. \"rawtransaction\" (string, required) A raw transaction in hex " | ||||
"funding an already-existing address in wallet\n" | "funding an already-existing address in wallet\n" | ||||
"2. \"txoutproof\" (string, required) The hex output from " | "2. \"txoutproof\" (string, required) The hex output from " | ||||
"gettxoutproof that contains the transaction\n"); | "gettxoutproof that contains the transaction\n"); | ||||
CMutableTransaction tx; | CMutableTransaction tx; | ||||
if (!DecodeHexTx(tx, request.params[0].get_str())) | if (!DecodeHexTx(tx, request.params[0].get_str())) | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | ||||
uint256 txid = tx.GetId(); | const txhash_t txhash = tx.GetHash(); | ||||
CWalletTx wtx(pwalletMain, MakeTransactionRef(std::move(tx))); | CWalletTx wtx(pwalletMain, MakeTransactionRef(std::move(tx))); | ||||
CDataStream ssMB(ParseHexV(request.params[1], "proof"), SER_NETWORK, | CDataStream ssMB(ParseHexV(request.params[1], "proof"), SER_NETWORK, | ||||
PROTOCOL_VERSION); | PROTOCOL_VERSION); | ||||
CMerkleBlock merkleBlock; | CMerkleBlock merkleBlock; | ||||
ssMB >> merkleBlock; | ssMB >> merkleBlock; | ||||
// Search partial merkle tree in proof for our transaction and index in | // Search partial merkle tree in proof for our transaction and index in | ||||
// valid block | // valid block | ||||
std::vector<uint256> vMatch; | std::vector<uint256> vMatch; | ||||
std::vector<unsigned int> vIndex; | std::vector<unsigned int> vIndex; | ||||
unsigned int txnIndex = 0; | unsigned int txnIndex = 0; | ||||
if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) == | if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) == | ||||
merkleBlock.header.hashMerkleRoot) { | merkleBlock.header.hashMerkleRoot) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (!mapBlockIndex.count(merkleBlock.header.GetHash()) || | if (!mapBlockIndex.count(merkleBlock.header.GetHash()) || | ||||
!chainActive.Contains(mapBlockIndex[merkleBlock.header.GetHash()])) | !chainActive.Contains(mapBlockIndex[merkleBlock.header.GetHash()])) | ||||
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)) == | if ((it = std::find(vMatch.begin(), vMatch.end(), txhash)) == | ||||
vMatch.end()) { | 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"); | ||||
} | } | ||||
txnIndex = vIndex[it - vMatch.begin()]; | txnIndex = vIndex[it - vMatch.begin()]; | ||||
} else { | } else { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
Show All 18 Lines | |||||
UniValue removeprunedfunds(const Config &config, | UniValue removeprunedfunds(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(request.fHelp)) { | if (!EnsureWalletIsAvailable(request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"removeprunedfunds \"txid\"\n" | "removeprunedfunds \"txhash\"\n" | ||||
"\nDeletes the specified transaction from the wallet. Meant for " | "\nDeletes the specified transaction from the wallet. Meant for " | ||||
"use with pruned wallets and as a companion to importprunedfunds. " | "use with pruned wallets and as a companion to importprunedfunds. " | ||||
"This will effect wallet balances.\n" | "This will effect wallet balances.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) The hex-encoded id of " | "1. \"txhash\" (string, required) The hex-encoded hash " | ||||
"of " | |||||
"the transaction you are deleting\n" | "the transaction you are deleting\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1" | HelpExampleCli("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1" | ||||
"ce581bebf46446a512166eae762873" | "ce581bebf46446a512166eae762873" | ||||
"4ea0a5\"") + | "4ea0a5\"") + | ||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("removprunedfunds", "\"a8d0c0184dde994a09ec054286f1c" | HelpExampleRpc("removprunedfunds", "\"a8d0c0184dde994a09ec054286f1c" | ||||
"e581bebf46446a512166eae7628734e" | "e581bebf46446a512166eae7628734e" | ||||
"a0a5\"")); | "a0a5\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwalletMain->cs_wallet); | LOCK2(cs_main, pwalletMain->cs_wallet); | ||||
uint256 hash; | txhash_t hash; | ||||
hash.SetHex(request.params[0].get_str()); | hash.SetHex(request.params[0].get_str()); | ||||
std::vector<uint256> vHash; | std::vector<txhash_t> vHash; | ||||
vHash.push_back(hash); | vHash.push_back(hash); | ||||
std::vector<uint256> vHashOut; | std::vector<txhash_t> vHashOut; | ||||
if (pwalletMain->ZapSelectTx(vHash, vHashOut) != DB_LOAD_OK) { | if (pwalletMain->ZapSelectTx(vHash, vHashOut) != DB_LOAD_OK) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Could not properly delete the transaction."); | "Could not properly delete the transaction."); | ||||
} | } | ||||
if (vHashOut.empty()) { | if (vHashOut.empty()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
▲ Show 20 Lines • Show All 851 Lines • ▼ Show 20 Lines | static const CRPCCommand commands[] = { | ||||
{ "wallet", "dumpprivkey", dumpprivkey, true, {"address"} }, | { "wallet", "dumpprivkey", dumpprivkey, true, {"address"} }, | ||||
{ "wallet", "dumpwallet", dumpwallet, true, {"filename"} }, | { "wallet", "dumpwallet", dumpwallet, true, {"filename"} }, | ||||
{ "wallet", "importmulti", importmulti, true, {"requests","options"} }, | { "wallet", "importmulti", importmulti, true, {"requests","options"} }, | ||||
{ "wallet", "importprivkey", importprivkey, true, {"privkey","label","rescan"} }, | { "wallet", "importprivkey", importprivkey, true, {"privkey","label","rescan"} }, | ||||
{ "wallet", "importwallet", importwallet, true, {"filename"} }, | { "wallet", "importwallet", importwallet, true, {"filename"} }, | ||||
{ "wallet", "importaddress", importaddress, true, {"address","label","rescan","p2sh"} }, | { "wallet", "importaddress", importaddress, true, {"address","label","rescan","p2sh"} }, | ||||
{ "wallet", "importprunedfunds", importprunedfunds, true, {"rawtransaction","txoutproof"} }, | { "wallet", "importprunedfunds", importprunedfunds, true, {"rawtransaction","txoutproof"} }, | ||||
{ "wallet", "importpubkey", importpubkey, true, {"pubkey","label","rescan"} }, | { "wallet", "importpubkey", importpubkey, true, {"pubkey","label","rescan"} }, | ||||
{ "wallet", "removeprunedfunds", removeprunedfunds, true, {"txid"} }, | { "wallet", "removeprunedfunds", removeprunedfunds, true, {"txhash"} }, | ||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
void RegisterDumpRPCCommands(CRPCTable &t) { | void RegisterDumpRPCCommands(CRPCTable &t) { | ||||
if (GetBoolArg("-disablewallet", false)) return; | if (GetBoolArg("-disablewallet", false)) return; | ||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) | for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) | ||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]); | t.appendCommand(commands[vcidx].name, &commands[vcidx]); | ||||
} | } |