Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | if (!fLabelFound) { | ||||
strAddr = EncodeDestination( | strAddr = EncodeDestination( | ||||
GetDestinationForKey(key.GetPubKey(), | GetDestinationForKey(key.GetPubKey(), | ||||
pwallet->m_default_address_type), | pwallet->m_default_address_type), | ||||
config); | config); | ||||
} | } | ||||
return fLabelFound; | return fLabelFound; | ||||
} | } | ||||
static const int64_t TIMESTAMP_MIN = 0; | |||||
static void RescanWallet(CWallet &wallet, const WalletRescanReserver &reserver, | |||||
int64_t time_begin = TIMESTAMP_MIN, | |||||
bool update = true) { | |||||
int64_t scanned_time = wallet.RescanFromTime(time_begin, reserver, update); | |||||
if (wallet.IsAbortingRescan()) { | |||||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); | |||||
} else if (scanned_time > time_begin) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Rescan was unable to fully rescan the blockchain. " | |||||
"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); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
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( | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | bool fRescan = true; | ||||
if (!pwallet->AddKeyPubKey(key, pubkey)) { | if (!pwallet->AddKeyPubKey(key, pubkey)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error adding key to wallet"); | "Error adding key to wallet"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (fRescan) { | if (fRescan) { | ||||
int64_t scanned_time = | RescanWallet(*pwallet, reserver); | ||||
pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); | |||||
if (pwallet->IsAbortingRescan()) { | |||||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); | |||||
} | |||||
if (scanned_time > TIMESTAMP_MIN) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Rescan was unable to fully rescan the " | |||||
"blockchain. Some transactions may be missing."); | |||||
} | |||||
} | } | ||||
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); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | if (!request.params[3].isNull()) { | ||||
ImportScript(pwallet, CScript(data.begin(), data.end()), strLabel, | ImportScript(pwallet, CScript(data.begin(), data.end()), strLabel, | ||||
fP2SH); | fP2SH); | ||||
} else { | } else { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid Bitcoin address or script"); | "Invalid Bitcoin address or script"); | ||||
} | } | ||||
} | } | ||||
if (fRescan) { | if (fRescan) { | ||||
int64_t scanned_time = | RescanWallet(*pwallet, reserver); | ||||
pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); | |||||
if (pwallet->IsAbortingRescan()) { | |||||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); | |||||
} | |||||
if (scanned_time > TIMESTAMP_MIN) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Rescan was unable to fully rescan the " | |||||
"blockchain. Some transactions may be missing."); | |||||
} | |||||
pwallet->ReacceptWalletTransactions(); | pwallet->ReacceptWalletTransactions(); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue importprunedfunds(const Config &config, | UniValue importprunedfunds(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | if (!pubKey.IsFullyValid()) { | ||||
for (const auto &dest : GetAllDestinationsForKey(pubKey)) { | for (const auto &dest : GetAllDestinationsForKey(pubKey)) { | ||||
ImportAddress(pwallet, dest, strLabel); | ImportAddress(pwallet, dest, strLabel); | ||||
} | } | ||||
ImportScript(pwallet, GetScriptForRawPubKey(pubKey), strLabel, false); | ImportScript(pwallet, GetScriptForRawPubKey(pubKey), strLabel, false); | ||||
pwallet->LearnAllRelatedScripts(pubKey); | pwallet->LearnAllRelatedScripts(pubKey); | ||||
} | } | ||||
if (fRescan) { | if (fRescan) { | ||||
int64_t scanned_time = | RescanWallet(*pwallet, reserver); | ||||
pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); | |||||
if (pwallet->IsAbortingRescan()) { | |||||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); | |||||
} | |||||
if (scanned_time > TIMESTAMP_MIN) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Rescan was unable to fully rescan the " | |||||
"blockchain. Some transactions may be missing."); | |||||
} | |||||
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); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | bool fGood = true; | ||||
file.close(); | file.close(); | ||||
// hide progress dialog in GUI | // hide progress dialog in GUI | ||||
uiInterface.ShowProgress("", 100, false); | uiInterface.ShowProgress("", 100, false); | ||||
pwallet->UpdateTimeFirstKey(nTimeBegin); | pwallet->UpdateTimeFirstKey(nTimeBegin); | ||||
} | } | ||||
// hide progress dialog in GUI | // hide progress dialog in GUI | ||||
uiInterface.ShowProgress("", 100, false); | uiInterface.ShowProgress("", 100, false); | ||||
int64_t scanned_time = | RescanWallet(*pwallet, reserver, nTimeBegin, false /* update */); | ||||
pwallet->RescanFromTime(nTimeBegin, reserver, false /* update */); | |||||
if (pwallet->IsAbortingRescan()) { | |||||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); | |||||
} | |||||
if (scanned_time > nTimeBegin) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Rescan was unable to fully rescan the blockchain. " | |||||
"Some transactions may be missing."); | |||||
} | |||||
pwallet->MarkDirty(); | pwallet->MarkDirty(); | ||||
if (!fGood) { | 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; | ||||
▲ Show 20 Lines • Show All 761 Lines • Show Last 20 Lines |