6#include <chainparams.h>
14#include <validation.h>
21#include <test/util/logging.h>
22#include <test/util/setup_common.h>
25#include <boost/test/unit_test.hpp>
56 wallet->m_chain_notifications_handler.reset();
69 std::map<COutPoint, Coin> coins;
70 coins[
mtx.vin[0].prevout].GetTxOut() =
from.vout[index];
89 .GetBlockFileInfo(
oldTip->GetBlockPos().nFile)
90 ->nSize = MAX_BLOCKFILE_SIZE);
101 wallet.SetLastBlockProcessed(
102 m_node.chainman->ActiveHeight(),
103 m_node.chainman->ActiveTip()->GetBlockHash());
125 wallet.SetLastBlockProcessed(
126 m_node.chainman->ActiveHeight(),
127 m_node.chainman->ActiveTip()->GetBlockHash());
158 wallet.SetLastBlockProcessed(
159 m_node.chainman->ActiveHeight(),
160 m_node.chainman->ActiveTip()->GetBlockHash());
189 wallet.SetLastBlockProcessed(
190 m_node.chainman->ActiveHeight(),
191 m_node.chainman->ActiveTip()->GetBlockHash());
211 chainman.
GetMutex(),
return m_node.chainman->ActiveChain().Tip());
213 .GetBlockFileInfo(
oldTip->GetBlockPos().nFile)
214 ->nSize = MAX_BLOCKFILE_SIZE);
217 chainman.
GetMutex(),
return m_node.chainman->ActiveChain().Tip());
232 std::shared_ptr<CWallet>
wallet = std::make_shared<CWallet>(
234 wallet->SetupLegacyScriptPubKeyMan();
243 key.
pushKV(
"scriptPubKey",
245 key.
pushKV(
"timestamp", 0);
252 key.
pushKV(
"scriptPubKey",
265 strprintf(
"[{\"success\":false,\"error\":{\"code\":-1,\"message\":"
266 "\"Rescan failed for key with creation timestamp %d. "
267 "There was an error reading a block from time %d, which "
268 "is after or within %d seconds of key creation, and "
269 "could contain transactions pertaining to the key. As a "
270 "result, transactions and coins using this key may not "
271 "appear in the wallet. This error could be caused by "
272 "pruning or data corruption (see bitcoind log for "
273 "details) and could be dealt with by downloading and "
274 "rescanning the relevant blocks (see -reindex and "
275 "-rescan options).\"}},{\"success\":true}]",
316 std::shared_ptr<CWallet>
wallet = std::make_shared<CWallet>(
340 std::shared_ptr<CWallet>
wallet = std::make_shared<CWallet>(
343 wallet->SetupLegacyScriptPubKeyMan();
361 bool expected = i >= 100;
410 std::piecewise_construct, std::make_tuple(
GetRandHash()),
462 m_wallet.AddDestData(batch, dest,
"misc",
"val_misc");
463 m_wallet.AddDestData(batch, dest,
"rr0",
"val_rr0");
464 m_wallet.AddDestData(batch, dest,
"rr1",
"val_rr1");
466 auto values =
m_wallet.GetDestValues(
"rr");
527 m_wallet.GetOrCreateLegacyScriptPubKeyMan();
562 wallet = std::make_unique<CWallet>(
m_node.chain.get(),
"",
575 m_node.chainman->ActiveChain().Genesis()->GetBlockHash(),
601 wallet->CommitTransaction(tx, {}, {});
613 wallet->SetLastBlockProcessed(
wallet->GetLastBlockHeight() + 1,
615 auto it =
wallet->mapWallet.find(tx->GetId());
620 it->second.m_confirm =
confirm;
632 std::map<CTxDestination, std::vector<COutput>> list;
667 for (
const auto &
group : list) {
668 for (
const auto &coin :
group.second) {
692 std::shared_ptr<CWallet>
wallet = std::make_shared<CWallet>(
694 wallet->SetupLegacyScriptPubKeyMan();
742 std::string s(
e.what());
743 return s.find(
"Missing checksum") != std::string::npos;
749 vw << std::string(
"notadescriptor");
791 [&](
const std::string *s) {
800 [&](
const std::string *s) {
860 BOOST_CHECK(rescan_completed);
861 m_coinbase_txns.push_back(
862 CreateAndProcessBlock(
static constexpr Amount COIN
RPCHelpMan importwallet()
static constexpr int64_t TIMESTAMP_WINDOW
Timestamp window used as a grace period by code that compares external timestamps (such as timestamps...
#define Assert(val)
Identity function.
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
The block chain is a tree shaped structure starting with the genesis block at the root,...
const BlockHash * phashBlock
pointer to the hash of the block, if any.
int64_t GetBlockTimeMax() const
BlockHash GetBlockHash() const
int nHeight
height of the entry in the chain. The genesis block has height 0
An encapsulated secp256k1 private key.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
A reference to a CKey: the Hash160 of its serialized public key.
A mutable version of CTransaction.
std::vector< CTxOut > vout
An outpoint - a combination of a transaction hash and an index n into its vout.
An encapsulated public key.
bool IsCompressed() const
Check whether this is a compressed public key.
const uint8_t * end() const
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
const uint8_t * begin() const
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
Minimal stream for overwriting and/or appending to an existing byte vector.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
static std::shared_ptr< CWallet > Create(interfaces::Chain &chain, const std::string &name, std::unique_ptr< WalletDatabase > database, uint64_t wallet_creation_flags, bilingual_str &error, std::vector< bilingual_str > &warnings)
Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error.
A transaction with a bunch of additional info that only the owner cares about.
void MarkDirty()
make sure balances are recalculated
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
virtual bool AddKey(const CKey &key)
std::unique_ptr< CWallet > wallet
CWalletTx & AddTx(CRecipient recipient)
UniValue HandleRequest(const Config &config, const JSONRPCRequest &request) const
Signature hash type wrapper class.
Minimal stream for reading from an existing byte array by Span.
void push_back(UniValue val)
void pushKV(std::string key, UniValue val)
Access to the wallet database.
Descriptor with some wallet metadata.
RAII object to check and reserve a wallet rescan.
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark one block file as pruned (modify associated database entries)
const Config & GetConfig()
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
bool error(const char *fmt, const Args &...args)
static std::string PathToString(const path &path)
Convert path object to byte string.
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
int64_t GetVirtualTransactionInputSize(const CTxIn &txin, int64_t nSigChecks, unsigned int bytes_per_sigCheck)
static CTransactionRef MakeTransactionRef()
std::shared_ptr< const CTransaction > CTransactionRef
uint256 GetRandHash() noexcept
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
void SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, const UniValue &hashType, UniValue &result)
Sign a transaction with the given keystore and previous transactions.
Amount CachedTxGetImmatureCredit(const CWallet &wallet, const CWalletTx &wtx, bool fUseCache)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
bool(* handler)(Config &config, const std::any &context, HTTPRequest *req, const std::string &strReq)
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
void UpdateInput(CTxIn &input, const SignatureData &data)
const BaseSignatureCreator & DUMMY_MAXIMUM_SIGNATURE_CREATOR
A signature creator that just produces 72-byte empty signatures.
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
std::map< CTxDestination, std::vector< COutput > > ListCoins(const CWallet &wallet)
Return list of available coins and locked coins grouped by non-change output address.
bool CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, Amount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
void AvailableCoins(const CWallet &wallet, std::vector< COutput > &vCoins, const CCoinControl *coinControl, const Amount nMinimumAmount, const Amount nMaximumAmount, const Amount nMinimumSumAmount, const uint64_t nMaximumCount)
populate vCoins with vector of available COutputs.
Amount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl)
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
static constexpr Amount zero() noexcept
A BlockHash is a unqiue identifier for a block.
std::optional< int > last_scanned_height
BlockHash last_scanned_block
Hash and height of most recent block that was successfully scanned.
enum CWallet::ScanResult::@20 status
BlockHash last_failed_block
Hash of the most recent block that could not be scanned due to read errors or pruning.
Confirmation includes tx status and a triplet of {block height/block hash/tx index in block} at which...
Testing setup and teardown for wallet.
#define ENTER_CRITICAL_SECTION(cs)
#define LEAVE_CRITICAL_SECTION(cs)
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
void CallFunctionInValidationInterfaceQueue(std::function< void()> func)
Pushes a function to callback onto the notification queue, guaranteeing any callbacks generated prior...
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
std::shared_ptr< CWallet > m_wallet
static constexpr size_t DUMMY_P2PKH_INPUT_SIZE
Pre-calculated constants for input size estimation.
constexpr Amount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
std::unique_ptr< interfaces::Handler > HandleLoadWallet(LoadWalletFn load_wallet)
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
bool AddWallet(const std::shared_ptr< CWallet > &wallet)
std::shared_ptr< CWallet > CreateWallet(interfaces::Chain &chain, const std::string &name, std::optional< bool > load_on_start, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
static void PollutePubKey(CPubKey &pubkey)
static size_t CalculateP2PKHInputSize(bool use_max_sig)
static void TestUnloadWallet(std::shared_ptr< CWallet > &&wallet)
static CMutableTransaction TestSimpleSpend(const CTransaction &from, uint32_t index, const CKey &key, const CScript &pubkey)
BOOST_AUTO_TEST_CASE(ComputeTimeSmart)
static int64_t AddTx(ChainstateManager &chainman, CWallet &wallet, uint32_t lockTime, int64_t mockTime, int64_t blockTime)
RecursiveMutex cs_wallets
BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
static void AddKey(CWallet &wallet, const CKey &key)
static void TestWatchOnlyPubKey(LegacyScriptPubKeyMan *spk_man, const CPubKey &add_pubkey)
bool malformed_descriptor(std::ios_base::failure e)
static std::shared_ptr< CWallet > TestLoadWallet(interfaces::Chain &chain)
std::unique_ptr< WalletDatabase > CreateDummyWalletDatabase()
Return object for accessing dummy database with no read/write capabilities.
std::unique_ptr< WalletDatabase > CreateMockWalletDatabase()
Return object for accessing temporary in-memory database.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS