Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 439 Lines • ▼ Show 20 Lines | UniValue importprunedfunds(const Config &config, | ||||
std::vector<uint256> vMatch; | std::vector<uint256> vMatch; | ||||
std::vector<size_t> vIndex; | std::vector<size_t> vIndex; | ||||
size_t txnIndex = 0; | size_t txnIndex = 0; | ||||
if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) == | if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) == | ||||
merkleBlock.header.hashMerkleRoot) { | merkleBlock.header.hashMerkleRoot) { | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
const CBlockIndex *pindex = | const CBlockIndex *pindex = | ||||
LookupBlockIndex(merkleBlock.header.GetHash()); | LookupBlockIndex(merkleBlock.header.GetHash()); | ||||
if (!pindex || !chainActive.Contains(pindex)) { | if (!pindex || !::ChainActive().Contains(pindex)) { | ||||
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(), txid)) == | ||||
vMatch.end()) { | vMatch.end()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | bool fGood = true; | ||||
std::ifstream file; | std::ifstream file; | ||||
file.open(request.params[0].get_str().c_str(), | file.open(request.params[0].get_str().c_str(), | ||||
std::ios::in | std::ios::ate); | std::ios::in | std::ios::ate); | ||||
if (!file.is_open()) { | if (!file.is_open()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Cannot open wallet dump file"); | "Cannot open wallet dump file"); | ||||
} | } | ||||
nTimeBegin = chainActive.Tip()->GetBlockTime(); | nTimeBegin = ::ChainActive().Tip()->GetBlockTime(); | ||||
int64_t nFilesize = std::max<int64_t>(1, file.tellg()); | int64_t nFilesize = std::max<int64_t>(1, file.tellg()); | ||||
file.seekg(0, file.beg); | file.seekg(0, file.beg); | ||||
// Use uiInterface.ShowProgress instead of pwallet.ShowProgress because | // Use uiInterface.ShowProgress instead of pwallet.ShowProgress because | ||||
// pwallet.ShowProgress has a cancel button tied to AbortRescan which we | // pwallet.ShowProgress has a cancel button tied to AbortRescan which we | ||||
// don't want for this progress bar showing the import progress. | // don't want for this progress bar showing the import progress. | ||||
// uiInterface.ShowProgress does not have a cancel button. | // uiInterface.ShowProgress does not have a cancel button. | ||||
▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
mapKeyBirth.clear(); | mapKeyBirth.clear(); | ||||
std::sort(vKeyBirth.begin(), vKeyBirth.end()); | std::sort(vKeyBirth.begin(), vKeyBirth.end()); | ||||
// produce output | // produce output | ||||
file << strprintf("# Wallet dump created by Bitcoin %s\n", CLIENT_BUILD); | file << strprintf("# Wallet dump created by Bitcoin %s\n", CLIENT_BUILD); | ||||
file << strprintf("# * Created on %s\n", FormatISO8601DateTime(GetTime())); | file << strprintf("# * Created on %s\n", FormatISO8601DateTime(GetTime())); | ||||
file << strprintf("# * Best block at time of backup was %i (%s),\n", | file << strprintf("# * Best block at time of backup was %i (%s),\n", | ||||
chainActive.Height(), | ::ChainActive().Height(), | ||||
chainActive.Tip()->GetBlockHash().ToString()); | ::ChainActive().Tip()->GetBlockHash().ToString()); | ||||
file << strprintf("# mined on %s\n", | file << strprintf( | ||||
FormatISO8601DateTime(chainActive.Tip()->GetBlockTime())); | "# mined on %s\n", | ||||
FormatISO8601DateTime(::ChainActive().Tip()->GetBlockTime())); | |||||
file << "\n"; | file << "\n"; | ||||
// add the base58check encoded extended master if the wallet uses HD | // add the base58check encoded extended master if the wallet uses HD | ||||
CKeyID seed_id = pwallet->GetHDChain().seed_id; | CKeyID seed_id = pwallet->GetHDChain().seed_id; | ||||
if (!seed_id.IsNull()) { | if (!seed_id.IsNull()) { | ||||
CKey seed; | CKey seed; | ||||
if (pwallet->GetKey(seed_id, seed)) { | if (pwallet->GetKey(seed_id, seed)) { | ||||
CExtKey masterKey; | CExtKey masterKey; | ||||
▲ Show 20 Lines • Show All 518 Lines • ▼ Show 20 Lines | UniValue importmulti(const Config &config, const JSONRPCRequest &mainRequest) { | ||||
int64_t nLowestTimestamp = 0; | int64_t nLowestTimestamp = 0; | ||||
UniValue response(UniValue::VARR); | UniValue response(UniValue::VARR); | ||||
{ | { | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
// Verify all timestamps are present before importing any keys. | // Verify all timestamps are present before importing any keys. | ||||
now = chainActive.Tip() ? chainActive.Tip()->GetMedianTimePast() : 0; | now = ::ChainActive().Tip() ? ::ChainActive().Tip()->GetMedianTimePast() | ||||
: 0; | |||||
for (const UniValue &data : requests.getValues()) { | for (const UniValue &data : requests.getValues()) { | ||||
GetImportTimestamp(data, now); | GetImportTimestamp(data, now); | ||||
} | } | ||||
const int64_t minimumTimestamp = 1; | const int64_t minimumTimestamp = 1; | ||||
if (fRescan && chainActive.Tip()) { | if (fRescan && ::ChainActive().Tip()) { | ||||
nLowestTimestamp = chainActive.Tip()->GetBlockTime(); | nLowestTimestamp = ::ChainActive().Tip()->GetBlockTime(); | ||||
} else { | } else { | ||||
fRescan = false; | fRescan = false; | ||||
} | } | ||||
for (const UniValue &data : requests.getValues()) { | for (const UniValue &data : requests.getValues()) { | ||||
const int64_t timestamp = | const int64_t timestamp = | ||||
std::max(GetImportTimestamp(data, now), minimumTimestamp); | std::max(GetImportTimestamp(data, now), minimumTimestamp); | ||||
const UniValue result = ProcessImport(pwallet, data, timestamp); | const UniValue result = ProcessImport(pwallet, data, timestamp); | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |