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, | ||||
// Search partial merkle tree in proof for our transaction and index in | // Search partial merkle tree in proof for our transaction and index in | ||||
// valid block | // valid block | ||||
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 = | if (locked_chain->getBlockHeight(merkleBlock.header.GetHash()) == | ||||
LookupBlockIndex(merkleBlock.header.GetHash()); | nullopt) { | ||||
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 217 Lines • ▼ Show 20 Lines | bool fGood = true; | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
fsbridge::ifstream file; | fsbridge::ifstream file; | ||||
file.open(request.params[0].get_str(), std::ios::in | std::ios::ate); | file.open(request.params[0].get_str(), 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(); | Optional<int> tip_height = locked_chain->getHeight(); | ||||
nTimeBegin = tip_height ? locked_chain->getBlockTime(*tip_height) : 0; | |||||
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 271 Lines • ▼ Show 20 Lines | for (const auto &entry : mapKeyBirth) { | ||||
} | } | ||||
} | } | ||||
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())); | ||||
const Optional<int> tip_height = locked_chain->getHeight(); | |||||
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(), | tip_height.value_or(-1), | ||||
::ChainActive().Tip()->GetBlockHash().ToString()); | tip_height | ||||
file << strprintf( | ? locked_chain->getBlockHash(*tip_height).ToString() | ||||
"# mined on %s\n", | : "(missing block hash)"); | ||||
FormatISO8601DateTime(::ChainActive().Tip()->GetBlockTime())); | file << strprintf("# mined on %s\n", | ||||
tip_height ? FormatISO8601DateTime( | |||||
locked_chain->getBlockTime(*tip_height)) | |||||
: "(missing block time)"); | |||||
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 601 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() | const Optional<int> tip_height = locked_chain->getHeight(); | ||||
: 0; | now = | ||||
tip_height ? locked_chain->getBlockMedianTimePast(*tip_height) : 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 && tip_height) { | ||||
nLowestTimestamp = ::ChainActive().Tip()->GetBlockTime(); | nLowestTimestamp = locked_chain->getBlockTime(*tip_height); | ||||
} 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 |