Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | if (wallet.IsAbortingRescan()) { | ||||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); | throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); | ||||
} 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."); | ||||
} | } | ||||
} | } | ||||
static LegacyScriptPubKeyMan &GetLegacyScriptPubKeyMan(CWallet &wallet) { | |||||
LegacyScriptPubKeyMan *spk_man = wallet.GetLegacyScriptPubKeyMan(); | |||||
if (!spk_man) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"This type of wallet does not support this command"); | |||||
} | |||||
return *spk_man; | |||||
} | |||||
UniValue importprivkey(const Config &config, const JSONRPCRequest &request) { | 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; | ||||
} | } | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
Show All 32 Lines | RPCHelpMan{ | ||||
.Check(request); | .Check(request); | ||||
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"); | ||||
} | } | ||||
GetLegacyScriptPubKeyMan(*wallet); | EnsureLegacyScriptPubKeyMan(*wallet); | ||||
WalletRescanReserver reserver(pwallet); | WalletRescanReserver reserver(pwallet); | ||||
bool fRescan = true; | bool fRescan = true; | ||||
{ | { | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"\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")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
GetLegacyScriptPubKeyMan(*pwallet); | EnsureLegacyScriptPubKeyMan(*pwallet); | ||||
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 | ||||
bool fRescan = true; | bool fRescan = true; | ||||
▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
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")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
GetLegacyScriptPubKeyMan(*wallet); | EnsureLegacyScriptPubKeyMan(*wallet); | ||||
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 | ||||
bool fRescan = true; | bool fRescan = true; | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
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\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
GetLegacyScriptPubKeyMan(*wallet); | EnsureLegacyScriptPubKeyMan(*wallet); | ||||
if (pwallet->chain().havePruned()) { | if (pwallet->chain().havePruned()) { | ||||
// Exit early and print an error. | // Exit early and print an error. | ||||
// If a block is pruned after this check, we will import the key(s), | // If a block is pruned after this check, we will import the key(s), | ||||
// but fail the rescan with a generic error. | // but fail the rescan with a generic error. | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_ERROR, | RPC_WALLET_ERROR, | ||||
"Importing wallets is disabled when blocks are pruned"); | "Importing wallets is disabled when blocks are pruned"); | ||||
▲ Show 20 Lines • Show All 183 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
}, | }, | ||||
RPCResult{"\"key\" (string) The private key\n"}, | RPCResult{"\"key\" (string) The private key\n"}, | ||||
RPCExamples{HelpExampleCli("dumpprivkey", "\"myaddress\"") + | RPCExamples{HelpExampleCli("dumpprivkey", "\"myaddress\"") + | ||||
HelpExampleCli("importprivkey", "\"mykey\"") + | HelpExampleCli("importprivkey", "\"mykey\"") + | ||||
HelpExampleRpc("dumpprivkey", "\"myaddress\"")}, | HelpExampleRpc("dumpprivkey", "\"myaddress\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
LegacyScriptPubKeyMan &spk_man = GetLegacyScriptPubKeyMan(*wallet); | LegacyScriptPubKeyMan &spk_man = EnsureLegacyScriptPubKeyMan(*wallet); | ||||
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(); | ||||
CTxDestination dest = | CTxDestination dest = | ||||
Show All 40 Lines | RPCHelpMan{ | ||||
" \"filename\" : { (string) The filename with full " | " \"filename\" : { (string) The filename with full " | ||||
"absolute path\n" | "absolute path\n" | ||||
"}\n"}, | "}\n"}, | ||||
RPCExamples{HelpExampleCli("dumpwallet", "\"test\"") + | RPCExamples{HelpExampleCli("dumpwallet", "\"test\"") + | ||||
HelpExampleRpc("dumpwallet", "\"test\"")}, | HelpExampleRpc("dumpwallet", "\"test\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
LegacyScriptPubKeyMan &spk_man = GetLegacyScriptPubKeyMan(*wallet); | LegacyScriptPubKeyMan &spk_man = EnsureLegacyScriptPubKeyMan(*wallet); | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
AssertLockHeld(spk_man.cs_wallet); | AssertLockHeld(spk_man.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 769 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"\"timestamp\":1455191478 }]' '{ \"rescan\": false}'") | "\"timestamp\":1455191478 }]' '{ \"rescan\": false}'") | ||||
}, | }, | ||||
} | } | ||||
.Check(mainRequest); | .Check(mainRequest); | ||||
RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ}); | RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ}); | ||||
GetLegacyScriptPubKeyMan(*wallet); | EnsureLegacyScriptPubKeyMan(*wallet); | ||||
const UniValue &requests = mainRequest.params[0]; | const UniValue &requests = mainRequest.params[0]; | ||||
// Default options | // Default options | ||||
bool fRescan = true; | bool fRescan = true; | ||||
if (!mainRequest.params[1].isNull()) { | if (!mainRequest.params[1].isNull()) { | ||||
const UniValue &options = mainRequest.params[1]; | const UniValue &options = mainRequest.params[1]; | ||||
▲ Show 20 Lines • Show All 141 Lines • Show Last 20 Lines |