Bitcoin Core 31.99.0
P2P Digital Currency
coins.h
Go to the documentation of this file.
1// Copyright (c) 2023-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_TEST_UTIL_COINS_H
6#define BITCOIN_TEST_UTIL_COINS_H
7
8#include <coins.h>
9#include <crypto/hex_base.h>
11#include <tinyformat.h>
12
13#include <ostream>
14
15class CCoinsViewCache;
17
24
26inline bool operator==(const Coin& a, const Coin& b)
27{
28 return a.fCoinBase == b.fCoinBase && a.nHeight == b.nHeight && a.out == b.out;
29}
30
32inline std::ostream& operator<<(std::ostream& os, const Coin& coin)
33{
34 return os << strprintf("Coin(spent=%d, coinbase=%d, height=%d, value=%d, scriptPubKey=%s)",
35 coin.IsSpent(), coin.fCoinBase, coin.nHeight, coin.out.nValue, HexStr(coin.out.scriptPubKey));
36}
37
38#endif // BITCOIN_TEST_UTIL_COINS_H
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:437
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:29
CScript scriptPubKey
Definition: transaction.h:143
CAmount nValue
Definition: transaction.h:142
A UTXO entry.
Definition: coins.h:46
CTxOut out
unspent transaction output
Definition: coins.h:49
bool IsSpent() const
Either this coin never existed (see e.g.
Definition: coins.h:94
bool fCoinBase
whether containing transaction was a coinbase
Definition: coins.h:52
uint32_t nHeight
at which height this containing transaction was included in the active block chain
Definition: coins.h:55
Fast randomness source.
Definition: random.h:386
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Definition: hex_base.cpp:30
FastRandomContext rng
Definition: dbwrapper.cpp:413
bool operator==(const Coin &a, const Coin &b)
Strict equality, including fields of spent coins.
Definition: coins.h:26
COutPoint AddTestCoin(FastRandomContext &rng, CCoinsViewCache &coins_view)
Create a Coin with DynamicMemoryUsage of 80 bytes and add it to the given view.
Definition: coins.cpp:16
std::ostream & operator<<(std::ostream &os, const Coin &coin)
Printed when a coin comparison fails.
Definition: coins.h:32
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1172