Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | UniValue importprivkey(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | 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() > 3) { | request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"importprivkey", | "importprivkey", | ||||
"\nAdds a private key (as returned by dumpprivkey) to " | "\nAdds a private key (as returned by dumpprivkey) to " | ||||
"your wallet. Requires a new wallet backup.\n" | "your wallet. Requires a new wallet backup.\n" | ||||
"Hint: use importmulti to import more than one private key.\n", | "Hint: use importmulti to import more than one private key.\n" | ||||
"\nNote: This call can take minutes to complete if rescan is true, " | |||||
"during that time, other rpc calls\n" | |||||
"may report that the imported key exists but related transactions " | |||||
"are still missing, leading to temporarily incorrect/bogus " | |||||
"balances and unspent outputs until rescan completes.\n", | |||||
{ | { | ||||
{"privkey", RPCArg::Type::STR, /* opt */ false, | {"privkey", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", "The private key (see dumpprivkey)"}, | /* default_val */ "", "The private key (see dumpprivkey)"}, | ||||
{"label", RPCArg::Type::STR, /* opt */ true, | {"label", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ | /* default_val */ | ||||
"current label if address exists, otherwise \"\"", | "current label if address exists, otherwise \"\"", | ||||
"An optional label"}, | "An optional label"}, | ||||
{"rescan", RPCArg::Type::BOOL, /* opt */ true, | {"rescan", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "true", | /* default_val */ "true", | ||||
"Rescan the wallet for transactions"}, | "Rescan the wallet for transactions"}, | ||||
}} | }, | ||||
.ToString() + | RPCResults{}, | ||||
"\nNote: This call can take minutes to complete if rescan is true, " | RPCExamples{ | ||||
"during that time, other rpc calls\n" | |||||
"may report that the imported key exists but related transactions " | |||||
"are still missing, leading to temporarily incorrect/bogus " | |||||
"balances and unspent outputs until rescan completes.\n" | |||||
"\nExamples:\n" | |||||
"\nDump a private key\n" + | "\nDump a private key\n" + | ||||
HelpExampleCli("dumpprivkey", "\"myaddress\"") + | HelpExampleCli("dumpprivkey", "\"myaddress\"") + | ||||
"\nImport the private key with rescan\n" + | "\nImport the private key with rescan\n" + | ||||
HelpExampleCli("importprivkey", "\"mykey\"") + | HelpExampleCli("importprivkey", "\"mykey\"") + | ||||
"\nImport using a label and without rescan\n" + | "\nImport using a label and without rescan\n" + | ||||
HelpExampleCli("importprivkey", "\"mykey\" \"testing\" false") + | HelpExampleCli("importprivkey", "\"mykey\" \"testing\" false") + | ||||
"\nImport using default blank label and without rescan\n" + | "\nImport using default blank label and without rescan\n" + | ||||
HelpExampleCli("importprivkey", "\"mykey\" \"\" false") + | HelpExampleCli("importprivkey", "\"mykey\" \"\" false") + | ||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false")); | HelpExampleRpc("importprivkey", | ||||
"\"mykey\", \"testing\", false")}, | |||||
} | |||||
.ToString()); | |||||
} | } | ||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Cannot import private keys to a wallet with " | "Cannot import private keys to a wallet with " | ||||
"private keys disabled"); | "private keys disabled"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | |||||
UniValue abortrescan(const Config &config, const JSONRPCRequest &request) { | UniValue abortrescan(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | 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( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"abortrescan", | "abortrescan", | ||||
"\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", | ||||
{}} | {}, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" | RPCExamples{"\nImport a private key\n" + | ||||
"\nImport a private key\n" + | |||||
HelpExampleCli("importprivkey", "\"mykey\"") + | HelpExampleCli("importprivkey", "\"mykey\"") + | ||||
"\nAbort the running wallet rescan\n" + | "\nAbort the running wallet rescan\n" + | ||||
HelpExampleCli("abortrescan", "") + "\nAs a JSON-RPC call\n" + | HelpExampleCli("abortrescan", "") + | ||||
HelpExampleRpc("abortrescan", "")); | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("abortrescan", "")}, | |||||
} | |||||
.ToString()); | |||||
} | } | ||||
if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) { | if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) { | ||||
return false; | return false; | ||||
} | } | ||||
pwallet->AbortRescan(); | pwallet->AbortRescan(); | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | UniValue importaddress(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | 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(RPCHelpMan{ | ||||
RPCHelpMan{"importaddress", | "importaddress", | ||||
"\nAdds an address or script (in hex) that can be " | "\nAdds an address or script (in hex) that can be " | ||||
"watched as if it were in your wallet but cannot be " | "watched as if it were in your wallet but cannot be " | ||||
"used to spend. Requires a new wallet backup.\n", | "used to spend. Requires a new wallet backup.\n" | ||||
"\nNote: This call can take minutes to complete if rescan is true, " | |||||
"during that time, other rpc calls\n" | |||||
"may report that the imported address exists but related " | |||||
"transactions are still missing, leading to temporarily " | |||||
"incorrect/bogus balances and unspent outputs until rescan " | |||||
"completes.\n" | |||||
"If you have the full public key, you should call importpubkey " | |||||
"instead of this.\n" | |||||
"\nNote: If you import a non-standard raw script in hex form, " | |||||
"outputs sending to it will be treated\n" | |||||
"as change, and not show up in many RPCs.\n", | |||||
{ | { | ||||
{"address", RPCArg::Type::STR, /* opt */ false, | {"address", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The Bitcoin address (or hex-encoded script)"}, | "The Bitcoin address (or hex-encoded script)"}, | ||||
{"label", RPCArg::Type::STR, /* opt */ true, | {"label", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "\"\"", "An optional label"}, | /* default_val */ "\"\"", "An optional label"}, | ||||
{"rescan", RPCArg::Type::BOOL, /* opt */ true, | {"rescan", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "true", | /* default_val */ "true", | ||||
"Rescan the wallet for transactions"}, | "Rescan the wallet for transactions"}, | ||||
{"p2sh", RPCArg::Type::BOOL, /* opt */ true, | {"p2sh", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "false", | /* default_val */ "false", | ||||
"Add the P2SH version of the script as well"}, | "Add the P2SH version of the script as well"}, | ||||
}} | }, | ||||
.ToString() + | RPCResults{}, | ||||
"\nNote: This call can take minutes to complete if rescan is true, " | RPCExamples{"\nImport an address with rescan\n" + | ||||
"during that time, other rpc calls\n" | |||||
"may report that the imported address exists but related " | |||||
"transactions are still missing, leading to temporarily " | |||||
"incorrect/bogus balances and unspent outputs until rescan " | |||||
"completes.\n" | |||||
"If you have the full public key, you should call importpubkey " | |||||
"instead of this.\n" | |||||
"\nNote: If you import a non-standard raw script in hex form, " | |||||
"outputs sending to it will be treated\n" | |||||
"as change, and not show up in many RPCs.\n" | |||||
"\nExamples:\n" | |||||
"\nImport an address with rescan\n" + | |||||
HelpExampleCli("importaddress", "\"myaddress\"") + | HelpExampleCli("importaddress", "\"myaddress\"") + | ||||
"\nImport using a label without rescan\n" + | "\nImport using a label without rescan\n" + | ||||
HelpExampleCli("importaddress", "\"myaddress\" \"testing\" false") + | HelpExampleCli("importaddress", | ||||
"\"myaddress\" \"testing\" false") + | |||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("importaddress", | HelpExampleRpc("importaddress", | ||||
"\"myaddress\", \"testing\", false")); | "\"myaddress\", \"testing\", false")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
std::string strLabel; | std::string strLabel; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
strLabel = request.params[1].get_str(); | strLabel = request.params[1].get_str(); | ||||
} | } | ||||
// Whether to perform rescan after import | // Whether to perform rescan after import | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 2) { | ||||
{"rawtransaction", RPCArg::Type::STR_HEX, /* opt */ false, | {"rawtransaction", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A raw transaction in hex funding an already-existing " | "A raw transaction in hex funding an already-existing " | ||||
"address in wallet"}, | "address in wallet"}, | ||||
{"txoutproof", RPCArg::Type::STR_HEX, /* opt */ false, | {"txoutproof", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The hex output from gettxoutproof that contains the " | "The hex output from gettxoutproof that contains the " | ||||
"transaction"}, | "transaction"}, | ||||
}}.ToString()); | }, | ||||
RPCResults{}, | |||||
RPCExamples{""}, | |||||
} | |||||
.ToString()); | |||||
} | } | ||||
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(); | uint256 txid = tx.GetId(); | ||||
CWalletTx wtx(pwallet, MakeTransactionRef(std::move(tx))); | CWalletTx wtx(pwallet, MakeTransactionRef(std::move(tx))); | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | UniValue removeprunedfunds(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | 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(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"removeprunedfunds", | "removeprunedfunds", | ||||
"\nDeletes the specified transaction from the wallet. Meant " | "\nDeletes the specified transaction from the wallet. Meant " | ||||
"for use with pruned wallets and as a companion to " | "for use with pruned wallets and as a companion to " | ||||
"importprunedfunds. This will affect wallet balances.\n", | "importprunedfunds. This will affect wallet balances.\n", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, | {"txid", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The hex-encoded id of the transaction you are deleting"}, | "The hex-encoded id of the transaction you are deleting"}, | ||||
}} | }, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" + | RPCExamples{ | ||||
HelpExampleCli("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1" | HelpExampleCli("removeprunedfunds", | ||||
"\"a8d0c0184dde994a09ec054286f1" | |||||
"ce581bebf46446a512166eae762873" | "ce581bebf46446a512166eae762873" | ||||
"4ea0a5\"") + | "4ea0a5\"") + | ||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("removeprunedfunds", | HelpExampleRpc( | ||||
"removeprunedfunds", | |||||
"\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166" | "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166" | ||||
"eae7628734ea0a5\"")); | "eae7628734ea0a5\"")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
TxId txid(ParseHashV(request.params[0], "txid")); | TxId txid(ParseHashV(request.params[0], "txid")); | ||||
std::vector<TxId> txIds; | std::vector<TxId> txIds; | ||||
txIds.push_back(txid); | txIds.push_back(txid); | ||||
Show All 16 Lines | UniValue importpubkey(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | 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(RPCHelpMan{ | ||||
RPCHelpMan{"importpubkey", | "importpubkey", | ||||
"\nAdds a public key (in hex) that can be watched as if " | "\nAdds a public key (in hex) that can be watched as if " | ||||
"it were in your wallet but cannot be used to spend. " | "it were in your wallet but cannot be used to spend. " | ||||
"Requires a new wallet backup.\n", | "Requires a new wallet backup.\n" | ||||
"\nNote: This call can take minutes to complete if rescan is true, " | |||||
"during that time, other rpc calls\n" | |||||
"may report that the imported pubkey exists but related " | |||||
"transactions are still missing, leading to temporarily " | |||||
"incorrect/bogus balances and unspent outputs until rescan " | |||||
"completes.\n", | |||||
{ | { | ||||
{"pubkey", RPCArg::Type::STR, /* opt */ false, | {"pubkey", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", "The hex-encoded public key"}, | /* default_val */ "", "The hex-encoded public key"}, | ||||
{"label", RPCArg::Type::STR, /* opt */ true, | {"label", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "\"\"", "An optional label"}, | /* default_val */ "\"\"", "An optional label"}, | ||||
{"rescan", RPCArg::Type::BOOL, /* opt */ true, | {"rescan", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "true", | /* default_val */ "true", | ||||
"Rescan the wallet for transactions"}, | "Rescan the wallet for transactions"}, | ||||
}} | }, | ||||
.ToString() + | RPCResults{}, | ||||
"\nNote: This call can take minutes to complete if rescan is true, " | RPCExamples{"\nImport a public key with rescan\n" + | ||||
"during that time, other rpc calls\n" | |||||
"may report that the imported pubkey exists but related " | |||||
"transactions are still missing, leading to temporarily " | |||||
"incorrect/bogus balances and unspent outputs until rescan " | |||||
"completes.\n" | |||||
"\nExamples:\n" | |||||
"\nImport a public key with rescan\n" + | |||||
HelpExampleCli("importpubkey", "\"mypubkey\"") + | HelpExampleCli("importpubkey", "\"mypubkey\"") + | ||||
"\nImport using a label without rescan\n" + | "\nImport using a label without rescan\n" + | ||||
HelpExampleCli("importpubkey", "\"mypubkey\" \"testing\" false") + | HelpExampleCli("importpubkey", | ||||
"\"mypubkey\" \"testing\" false") + | |||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("importpubkey", "\"mypubkey\", \"testing\", false")); | HelpExampleRpc("importpubkey", | ||||
"\"mypubkey\", \"testing\", false")}, | |||||
} | |||||
.ToString()); | |||||
} | } | ||||
std::string strLabel; | std::string strLabel; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
strLabel = request.params[1].get_str(); | strLabel = request.params[1].get_str(); | ||||
} | } | ||||
// Whether to perform rescan after import | // Whether to perform rescan after import | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
UniValue importwallet(const Config &config, const JSONRPCRequest &request) { | UniValue importwallet(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | 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(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"importwallet", | "importwallet", | ||||
"\nImports keys from a wallet dump file (see dumpwallet). " | "\nImports keys from a wallet dump file (see dumpwallet). " | ||||
"Requires a new wallet backup to include imported keys.\n", | "Requires a new wallet backup to include imported keys.\n", | ||||
{ | { | ||||
{"filename", RPCArg::Type::STR, /* opt */ false, | {"filename", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", "The wallet file"}, | /* default_val */ "", "The wallet file"}, | ||||
}} | }, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" | RPCExamples{"\nDump the wallet\n" + | ||||
"\nDump the wallet\n" + | HelpExampleCli("dumpwallet", "\"test\"") + | ||||
HelpExampleCli("dumpwallet", "\"test\"") + "\nImport the wallet\n" + | "\nImport the wallet\n" + | ||||
HelpExampleCli("importwallet", "\"test\"") + | HelpExampleCli("importwallet", "\"test\"") + | ||||
"\nImport using the json rpc call\n" + | "\nImport using the json rpc call\n" + | ||||
HelpExampleRpc("importwallet", "\"test\"")); | HelpExampleRpc("importwallet", "\"test\"")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
if (fPruneMode) { | if (fPruneMode) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Importing wallets is disabled in pruned mode"); | "Importing wallets is disabled in pruned mode"); | ||||
} | } | ||||
WalletRescanReserver reserver(pwallet); | WalletRescanReserver reserver(pwallet); | ||||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | |||||
UniValue dumpprivkey(const Config &config, const JSONRPCRequest &request) { | UniValue dumpprivkey(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | 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(RPCHelpMan{ | ||||
RPCHelpMan{"dumpprivkey", | "dumpprivkey", | ||||
"\nReveals the private key corresponding to 'address'.\n" | "\nReveals the private key corresponding to 'address'.\n" | ||||
"Then the importprivkey can be used with this output\n", | "Then the importprivkey can be used with this output\n", | ||||
{ | { | ||||
{"address", RPCArg::Type::STR, /* opt */ false, | {"address", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The bitcoin address for the private key"}, | "The bitcoin address for the private key"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"\"key\" (string) The private key\n"}, | ||||
"\nResult:\n" | RPCExamples{HelpExampleCli("dumpprivkey", "\"myaddress\"") + | ||||
"\"key\" (string) The private key\n" | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("dumpprivkey", "\"myaddress\"") + | |||||
HelpExampleCli("importprivkey", "\"mykey\"") + | HelpExampleCli("importprivkey", "\"mykey\"") + | ||||
HelpExampleRpc("dumpprivkey", "\"myaddress\"")); | HelpExampleRpc("dumpprivkey", "\"myaddress\"")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
std::string strAddress = request.params[0].get_str(); | std::string strAddress = request.params[0].get_str(); | ||||
Show All 18 Lines | |||||
UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | 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(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"dumpwallet", | "dumpwallet", | ||||
"\nDumps all wallet keys in a human-readable format to " | "\nDumps all wallet keys in a human-readable format to " | ||||
"a server-side file. This does not allow overwriting " | "a server-side file. This does not allow overwriting " | ||||
"existing files.\n" | "existing files.\n" | ||||
"Imported scripts are included in the dumpsfile, but " | "Imported scripts are included in the dumpsfile, but " | ||||
"corresponding addresses may not be added automatically " | "corresponding addresses may not be added automatically " | ||||
"by importwallet.\n" | "by importwallet.\n" | ||||
"Note that if your wallet contains keys which are not " | "Note that if your wallet contains keys which are not " | ||||
"derived from your HD seed (e.g. imported keys), these " | "derived from your HD seed (e.g. imported keys), these " | ||||
"are not covered by\n" | "are not covered by\n" | ||||
"only backing up the seed itself, and must be backed up " | "only backing up the seed itself, and must be backed up " | ||||
"too (e.g. ensure you back up the whole dumpfile).\n", | "too (e.g. ensure you back up the whole dumpfile).\n", | ||||
{ | { | ||||
{"filename", RPCArg::Type::STR, /* opt */ false, | {"filename", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The filename with path (either absolute or relative to " | "The filename with path (either absolute or relative to " | ||||
"bitcoind)"}, | "bitcoind)"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"{ (json object)\n" | "{ (json object)\n" | ||||
" \"filename\" : { (string) The filename with full " | " \"filename\" : { (string) The filename with full " | ||||
"absolute path\n" | "absolute path\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("dumpwallet", "\"test\"") + | ||||
HelpExampleCli("dumpwallet", "\"test\"") + | HelpExampleRpc("dumpwallet", "\"test\"")}, | ||||
HelpExampleRpc("dumpwallet", "\"test\"")); | } | ||||
.ToString()); | |||||
} | } | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
fs::path filepath = request.params[0].get_str(); | fs::path filepath = request.params[0].get_str(); | ||||
▲ Show 20 Lines • Show All 503 Lines • ▼ Show 20 Lines | std::shared_ptr<CWallet> const wallet = | ||||
GetWalletForJSONRPCRequest(mainRequest); | GetWalletForJSONRPCRequest(mainRequest); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
if (!EnsureWalletIsAvailable(pwallet, mainRequest.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, mainRequest.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (mainRequest.fHelp || mainRequest.params.size() < 1 || | if (mainRequest.fHelp || mainRequest.params.size() < 1 || | ||||
mainRequest.params.size() > 2) { | mainRequest.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"importmulti", | "importmulti", | ||||
"\nImport addresses/scripts (with private or public keys, " | "\nImport addresses/scripts (with private or public keys, " | ||||
"redeem script (P2SH)), rescanning all addresses in " | "redeem script (P2SH)), rescanning all addresses in " | ||||
"one-shot-only (rescan can be disabled via options). Requires " | "one-shot-only (rescan can be disabled via options). Requires " | ||||
"a new wallet backup.\n", | "a new wallet backup.\n" | ||||
"\nNote: This call can take minutes to complete if rescan is true, " | |||||
"during that time, other rpc calls\n" | |||||
"may report that the imported keys, addresses or scripts exists " | |||||
"but related transactions are still missing.\n", | |||||
{ | { | ||||
{"requests", | {"requests", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"Data to be imported", | "Data to be imported", | ||||
{ | { | ||||
{ | { | ||||
"", | "", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"", | "", | ||||
{ | { | ||||
{"scriptPubKey", | {"scriptPubKey", | ||||
RPCArg::Type::STR, | RPCArg::Type::STR, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"Type of scriptPubKey (string for script, " | "Type of scriptPubKey (string for script, " | ||||
"json for address)", | "json for address)", | ||||
/* oneline_description */ "", | /* oneline_description */ "", | ||||
{"\"<script>\" | { \"address\":\"<address>\" " | {"\"<script>\" | { \"address\":\"<address>\" " | ||||
"}", | "}", | ||||
"string / json"}}, | "string / json"}}, | ||||
{"timestamp", | {"timestamp", | ||||
RPCArg::Type::NUM, | RPCArg::Type::NUM, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"Creation time of the key in seconds since " | "Creation time of the key in seconds since " | ||||
"epoch (Jan 1 1970 GMT),\n" | "epoch (Jan 1 1970 GMT),\n" | ||||
" " | " " | ||||
" or the string \"now\" to " | " or the string \"now\" to " | ||||
"substitute the current synced blockchain " | "substitute the current synced blockchain " | ||||
"time. The timestamp of the oldest\n" | "time. The timestamp of the oldest\n" | ||||
" " | " " | ||||
" key will determine how " | " key will determine how " | ||||
"far back blockchain rescans need to begin " | "far back blockchain rescans need to begin " | ||||
"for missing wallet transactions.\n" | "for missing wallet transactions.\n" | ||||
" " | " " | ||||
" \"now\" can be specified " | " \"now\" can be specified " | ||||
"to bypass scanning, for keys which are " | "to bypass scanning, for keys which are " | ||||
"known to never have been used, and\n" | "known to never have been used, and\n" | ||||
" " | " " | ||||
" 0 can be specified to " | " 0 can be specified to " | ||||
"scan the entire blockchain. Blocks up to 2 " | "scan the entire blockchain. Blocks up to 2 " | ||||
"hours before the earliest key\n" | "hours before the earliest key\n" | ||||
" " | " " | ||||
" creation time of all keys " | " creation time of all keys " | ||||
"being imported by the importmulti call will " | "being imported by the importmulti call will " | ||||
"be scanned.", | "be scanned.", | ||||
/* oneline_description */ "", | /* oneline_description */ "", | ||||
{"timestamp | \"now\"", "integer / string"}}, | {"timestamp | \"now\"", "integer / string"}}, | ||||
{"redeemscript", RPCArg::Type::STR, | {"redeemscript", RPCArg::Type::STR, | ||||
/* opt */ true, /* default_val */ "", | /* opt */ true, /* default_val */ "", | ||||
"Allowed only if the scriptPubKey is a P2SH " | "Allowed only if the scriptPubKey is a P2SH " | ||||
"or P2SH-P2WSH address/scriptPubKey"}, | "or P2SH-P2WSH address/scriptPubKey"}, | ||||
{"pubkeys", | {"pubkeys", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"Array of strings giving pubkeys that must " | "Array of strings giving pubkeys that must " | ||||
"occur in the output or redeemscript", | "occur in the output or redeemscript", | ||||
{ | { | ||||
{"pubKey", RPCArg::Type::STR, | {"pubKey", RPCArg::Type::STR, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", ""}, | ||||
""}, | |||||
}}, | }}, | ||||
{"keys", | {"keys", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"Array of strings giving private keys whose " | "Array of strings giving private keys whose " | ||||
"corresponding public keys must occur in the " | "corresponding public keys must occur in the " | ||||
"output or redeemscript", | "output or redeemscript", | ||||
{ | { | ||||
{"key", RPCArg::Type::STR, | {"key", RPCArg::Type::STR, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", ""}, | ||||
""}, | |||||
}}, | }}, | ||||
{"internal", RPCArg::Type::BOOL, | {"internal", RPCArg::Type::BOOL, | ||||
/* opt */ true, /* default_val */ "false", | /* opt */ true, /* default_val */ "false", | ||||
"Stating whether matching outputs should be " | "Stating whether matching outputs should be " | ||||
"treated as not incoming payments aka " | "treated as not incoming payments aka " | ||||
"change"}, | "change"}, | ||||
{"watchonly", RPCArg::Type::BOOL, | {"watchonly", RPCArg::Type::BOOL, | ||||
/* opt */ true, /* default_val */ "false", | /* opt */ true, /* default_val */ "false", | ||||
"Stating whether matching outputs should be " | "Stating whether matching outputs should be " | ||||
"considered watched even when they're not " | "considered watched even when they're not " | ||||
"spendable, only allowed if keys are empty"}, | "spendable, only allowed if keys are empty"}, | ||||
{"label", RPCArg::Type::STR, /* opt */ true, | {"label", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "''", | /* default_val */ "''", | ||||
"Label to assign to the address, only " | "Label to assign to the address, only " | ||||
"allowed with internal=false"}, | "allowed with internal=false"}, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
"\"requests\""}, | "\"requests\""}, | ||||
{"options", | {"options", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"", | "", | ||||
{ | { | ||||
{"rescan", RPCArg::Type::BOOL, /* opt */ true, | {"rescan", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "true", | /* default_val */ "true", | ||||
"Stating if should rescan the blockchain after all " | "Stating if should rescan the blockchain after all " | ||||
"imports"}, | "imports"}, | ||||
}, | }, | ||||
"\"options\""}, | "\"options\""}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nNote: This call can take minutes to complete if rescan is true, " | "\nResponse is an array with the same size as the input that " | ||||
"during that time, other rpc calls\n" | "has " | ||||
"may report that the imported keys, addresses or scripts exists " | "the execution result :\n" | ||||
"but related transactions are still missing.\n" | " [{ \"success\": true } , { \"success\": false, \"error\": { " | ||||
"\nExamples:\n" + | "\"code\": -1, \"message\": \"Internal Server Error\"} }, ... " | ||||
"]\n"}, | |||||
RPCExamples{ | |||||
HelpExampleCli( | HelpExampleCli( | ||||
"importmulti", | "importmulti", | ||||
"'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, " | "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, " | ||||
"\"timestamp\":1455191478 }, " | "\"timestamp\":1455191478 }, " | ||||
"{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" }, " | "{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" " | ||||
"}, " | |||||
"\"label\": \"example 2\", \"timestamp\": 1455191480 }]'") + | "\"label\": \"example 2\", \"timestamp\": 1455191480 }]'") + | ||||
HelpExampleCli( | HelpExampleCli( | ||||
"importmulti", | "importmulti", | ||||
"'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, " | "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, " | ||||
"\"timestamp\":1455191478 }]' '{ \"rescan\": false}'") + | "\"timestamp\":1455191478 }]' '{ \"rescan\": false}'") | ||||
"\nResponse is an array with the same size as the input that has " | }, | ||||
"the execution result :\n" | } | ||||
" [{ \"success\": true } , { \"success\": false, \"error\": { " | .ToString()); | ||||
"\"code\": -1, \"message\": \"Internal Server Error\"} }, ... ]\n"); | |||||
} | } | ||||
RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ}); | RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ}); | ||||
const UniValue &requests = mainRequest.params[0]; | const UniValue &requests = mainRequest.params[0]; | ||||
// Default options | // Default options | ||||
bool fRescan = true; | bool fRescan = true; | ||||
▲ Show 20 Lines • Show All 137 Lines • Show Last 20 Lines |