Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show All 19 Lines | |||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <random.h> | #include <random.h> | ||||
#include <script/descriptor.h> | #include <script/descriptor.h> | ||||
#include <script/script.h> | #include <script/script.h> | ||||
#include <script/sighashtype.h> | #include <script/sighashtype.h> | ||||
#include <script/sign.h> | #include <script/sign.h> | ||||
#include <script/signingprovider.h> | #include <script/signingprovider.h> | ||||
#include <util/bip32.h> | #include <util/bip32.h> | ||||
#include <util/check.h> | |||||
#include <util/error.h> | #include <util/error.h> | ||||
#include <util/moneystr.h> | #include <util/moneystr.h> | ||||
#include <util/string.h> | #include <util/string.h> | ||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <util/validation.h> | #include <util/validation.h> | ||||
#include <wallet/coincontrol.h> | #include <wallet/coincontrol.h> | ||||
#include <wallet/fees.h> | #include <wallet/fees.h> | ||||
#include <boost/algorithm/string/replace.hpp> | #include <boost/algorithm/string/replace.hpp> | ||||
#include <cassert> | using interfaces::FoundBlock; | ||||
const std::map<uint64_t, std::string> WALLET_FLAG_CAVEATS{ | const std::map<uint64_t, std::string> WALLET_FLAG_CAVEATS{ | ||||
{WALLET_FLAG_AVOID_REUSE, | {WALLET_FLAG_AVOID_REUSE, | ||||
"You need to rescan the blockchain in order to correctly mark used " | "You need to rescan the blockchain in order to correctly mark used " | ||||
"destinations in the past. Until this is done, some destinations may " | "destinations in the past. Until this is done, some destinations may " | ||||
"be considered unused, even if the opposite is the case."}, | "be considered unused, even if the opposite is the case."}, | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 1,673 Lines • ▼ Show 20 Lines | int64_t CWallet::RescanFromTime(int64_t startTime, | ||||
} | } | ||||
if (!start_block.IsNull()) { | if (!start_block.IsNull()) { | ||||
// TODO: this should take into account failure by ScanResult::USER_ABORT | // TODO: this should take into account failure by ScanResult::USER_ABORT | ||||
ScanResult result = ScanForWalletTransactions(start_block, BlockHash(), | ScanResult result = ScanForWalletTransactions(start_block, BlockHash(), | ||||
reserver, update); | reserver, update); | ||||
if (result.status == ScanResult::FAILURE) { | if (result.status == ScanResult::FAILURE) { | ||||
int64_t time_max; | int64_t time_max; | ||||
if (!chain().findBlock(result.last_failed_block, | CHECK_NONFATAL(chain().findBlock(result.last_failed_block, | ||||
nullptr /* block */, nullptr /* time */, | FoundBlock().maxTime(time_max))); | ||||
&time_max)) { | |||||
throw std::logic_error( | |||||
"ScanForWalletTransactions returned invalid block hash"); | |||||
} | |||||
return time_max + TIMESTAMP_WINDOW + 1; | return time_max + TIMESTAMP_WINDOW + 1; | ||||
} | } | ||||
} | } | ||||
return startTime; | return startTime; | ||||
} | } | ||||
/** | /** | ||||
* Scan the block chain (starting in start_block) for transactions from or to | * Scan the block chain (starting in start_block) for transactions from or to | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | while (block_height && !fAbortRescan && !chain().shutdownRequested()) { | ||||
} | } | ||||
if (GetTime() >= nNow + 60) { | if (GetTime() >= nNow + 60) { | ||||
nNow = GetTime(); | nNow = GetTime(); | ||||
WalletLogPrintf("Still rescanning. At block %d. Progress=%f\n", | WalletLogPrintf("Still rescanning. At block %d. Progress=%f\n", | ||||
*block_height, progress_current); | *block_height, progress_current); | ||||
} | } | ||||
CBlock block; | CBlock block; | ||||
if (chain().findBlock(block_hash, &block) && !block.IsNull()) { | if (chain().findBlock(block_hash, FoundBlock().data(block)) && | ||||
!block.IsNull()) { | |||||
auto locked_chain = chain().lock(); | auto locked_chain = chain().lock(); | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
if (!locked_chain->getBlockHeight(block_hash)) { | if (!locked_chain->getBlockHeight(block_hash)) { | ||||
// Abort scan if current block is no longer active, to | // Abort scan if current block is no longer active, to | ||||
// prevent marking transactions as coming from the wrong | // prevent marking transactions as coming from the wrong | ||||
// block. | // block. | ||||
// TODO: This should return success instead of failure, see | // TODO: This should return success instead of failure, see | ||||
// https://github.com/bitcoin/bitcoin/pull/14711#issuecomment-458342518 | // https://github.com/bitcoin/bitcoin/pull/14711#issuecomment-458342518 | ||||
▲ Show 20 Lines • Show All 2,090 Lines • ▼ Show 20 Lines | |||||
* For more information see CWalletTx::nTimeSmart, | * For more information see CWalletTx::nTimeSmart, | ||||
* https://bitcointalk.org/?topic=54527, or | * https://bitcointalk.org/?topic=54527, or | ||||
* https://github.com/bitcoin/bitcoin/pull/1393. | * https://github.com/bitcoin/bitcoin/pull/1393. | ||||
*/ | */ | ||||
unsigned int CWallet::ComputeTimeSmart(const CWalletTx &wtx) const { | unsigned int CWallet::ComputeTimeSmart(const CWalletTx &wtx) const { | ||||
unsigned int nTimeSmart = wtx.nTimeReceived; | unsigned int nTimeSmart = wtx.nTimeReceived; | ||||
if (!wtx.isUnconfirmed() && !wtx.isAbandoned()) { | if (!wtx.isUnconfirmed() && !wtx.isAbandoned()) { | ||||
int64_t blocktime; | int64_t blocktime; | ||||
if (chain().findBlock(wtx.m_confirm.hashBlock, nullptr /* block */, | if (chain().findBlock(wtx.m_confirm.hashBlock, | ||||
&blocktime)) { | FoundBlock().time(blocktime))) { | ||||
int64_t latestNow = wtx.nTimeReceived; | int64_t latestNow = wtx.nTimeReceived; | ||||
int64_t latestEntry = 0; | int64_t latestEntry = 0; | ||||
// Tolerate times up to the last timestamp in the wallet not more | // Tolerate times up to the last timestamp in the wallet not more | ||||
// than 5 minutes into the future | // than 5 minutes into the future | ||||
int64_t latestTolerated = latestNow + 300; | int64_t latestTolerated = latestNow + 300; | ||||
const TxItems &txOrdered = wtxOrdered; | const TxItems &txOrdered = wtxOrdered; | ||||
for (auto it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) { | for (auto it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) { | ||||
▲ Show 20 Lines • Show All 846 Lines • Show Last 20 Lines |