Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | static void RescanWallet(CWallet &wallet, const WalletRescanReserver &reserver, | ||||
} else if (scanned_time > time_begin) { | } else if (scanned_time > time_begin) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Rescan was unable to fully rescan the blockchain. " | "Rescan was unable to fully rescan the blockchain. " | ||||
"Some transactions may be missing."); | "Some transactions may be missing."); | ||||
} | } | ||||
} | } | ||||
UniValue importprivkey(const Config &config, const JSONRPCRequest &request) { | UniValue importprivkey(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) | if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"importprivkey \"privkey\" ( \"label\" ) ( rescan )\n" | "importprivkey \"privkey\" ( \"label\" ) ( rescan )\n" | ||||
"\nAdds a private key (as returned by dumpprivkey) to your wallet. " | "\nAdds a private key (as returned by dumpprivkey) to your wallet. " | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | UniValue importprivkey(const Config &config, const JSONRPCRequest &request) { | ||||
if (fRescan) { | if (fRescan) { | ||||
RescanWallet(*pwallet, reserver); | RescanWallet(*pwallet, reserver); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue abortrescan(const Config &config, const JSONRPCRequest &request) { | UniValue abortrescan(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 0) { | if (request.fHelp || request.params.size() > 0) { | ||||
throw std::runtime_error("abortrescan\n" | throw std::runtime_error("abortrescan\n" | ||||
"\nStops current wallet rescan triggered by " | "\nStops current wallet rescan triggered by " | ||||
"an RPC call, e.g. by an importprivkey call.\n" | "an RPC call, e.g. by an importprivkey call.\n" | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | static void ImportAddress(CWallet *const pwallet, const CTxDestination &dest, | ||||
ImportScript(pwallet, script, strLabel, false); | ImportScript(pwallet, script, strLabel, false); | ||||
// add to address book or update label | // add to address book or update label | ||||
if (IsValidDestination(dest)) { | if (IsValidDestination(dest)) { | ||||
pwallet->SetAddressBook(dest, strLabel, "receive"); | pwallet->SetAddressBook(dest, strLabel, "receive"); | ||||
} | } | ||||
} | } | ||||
UniValue importaddress(const Config &config, const JSONRPCRequest &request) { | UniValue importaddress(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 4) { | request.params.size() > 4) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"importaddress \"address\" ( \"label\" rescan p2sh )\n" | "importaddress \"address\" ( \"label\" rescan p2sh )\n" | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | if (fRescan) { | ||||
pwallet->ReacceptWalletTransactions(); | pwallet->ReacceptWalletTransactions(); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue importprunedfunds(const Config &config, | UniValue importprunedfunds(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 2) { | if (request.fHelp || request.params.size() != 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"importprunedfunds\n" | "importprunedfunds\n" | ||||
"\nImports funds without rescan. Corresponding address or script " | "\nImports funds without rescan. Corresponding address or script " | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | UniValue importprunedfunds(const Config &config, | ||||
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"); | ||||
} | } | ||||
UniValue removeprunedfunds(const Config &config, | UniValue removeprunedfunds(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, 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 \"txid\"\n" | ||||
"\nDeletes the specified transaction from the wallet. Meant for " | "\nDeletes the specified transaction from the wallet. Meant for " | ||||
Show All 29 Lines | if (txIdsOut.empty()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Transaction does not exist in wallet."); | "Transaction does not exist in wallet."); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue importpubkey(const Config &config, const JSONRPCRequest &request) { | UniValue importpubkey(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 4) { | request.params.size() > 4) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"importpubkey \"pubkey\" ( \"label\" rescan )\n" | "importpubkey \"pubkey\" ( \"label\" rescan )\n" | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | if (fRescan) { | ||||
RescanWallet(*pwallet, reserver); | RescanWallet(*pwallet, reserver); | ||||
pwallet->ReacceptWalletTransactions(); | pwallet->ReacceptWalletTransactions(); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue importwallet(const Config &config, const JSONRPCRequest &request) { | UniValue importwallet(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, 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( | ||||
"importwallet \"filename\"\n" | "importwallet \"filename\"\n" | ||||
"\nImports keys from a wallet dump file (see dumpwallet). Requires " | "\nImports keys from a wallet dump file (see dumpwallet). Requires " | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | if (!fGood) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error adding some keys/scripts to wallet"); | "Error adding some keys/scripts to wallet"); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue dumpprivkey(const Config &config, const JSONRPCRequest &request) { | UniValue dumpprivkey(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, 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( | ||||
"dumpprivkey \"address\"\n" | "dumpprivkey \"address\"\n" | ||||
"\nReveals the private key corresponding to 'address'.\n" | "\nReveals the private key corresponding to 'address'.\n" | ||||
Show All 28 Lines | UniValue dumpprivkey(const Config &config, const JSONRPCRequest &request) { | ||||
if (!pwallet->GetKey(keyid, vchSecret)) { | if (!pwallet->GetKey(keyid, vchSecret)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + | throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + | ||||
strAddress + " is not known"); | strAddress + " is not known"); | ||||
} | } | ||||
return EncodeSecret(vchSecret); | return EncodeSecret(vchSecret); | ||||
} | } | ||||
UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, 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( | ||||
"dumpwallet \"filename\"\n" | "dumpwallet \"filename\"\n" | ||||
"\nDumps all wallet keys in a human-readable format to a " | "\nDumps all wallet keys in a human-readable format to a " | ||||
▲ Show 20 Lines • Show All 508 Lines • ▼ Show 20 Lines | if (data.exists("timestamp")) { | ||||
"value for key. got type %s", | "value for key. got type %s", | ||||
uvTypeName(timestamp.type()))); | uvTypeName(timestamp.type()))); | ||||
} | } | ||||
throw JSONRPCError(RPC_TYPE_ERROR, | throw JSONRPCError(RPC_TYPE_ERROR, | ||||
"Missing required timestamp field for key"); | "Missing required timestamp field for key"); | ||||
} | } | ||||
UniValue importmulti(const Config &config, const JSONRPCRequest &mainRequest) { | UniValue importmulti(const Config &config, const JSONRPCRequest &mainRequest) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(mainRequest); | std::shared_ptr<CWallet> const wallet = | ||||
GetWalletForJSONRPCRequest(mainRequest); | |||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, mainRequest.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, mainRequest.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
// clang-format off | // clang-format off | ||||
if (mainRequest.fHelp || mainRequest.params.size() < 1 || mainRequest.params.size() > 2) { | if (mainRequest.fHelp || mainRequest.params.size() < 1 || mainRequest.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"importmulti \"requests\" ( \"options\" )\n\n" | "importmulti \"requests\" ( \"options\" )\n\n" | ||||
▲ Show 20 Lines • Show All 179 Lines • Show Last 20 Lines |