/** An outpoint - a combination of a transaction hash and an index n into its vout */
class COutPoint
{
public:
uint256 hash;
uint32_t n;
};
- CTxIn : 交易输入
/** An input of a transaction. It contains the location of the previous
* transaction's output that it claims and a signature that matches the
* output's public key.
*/
class CTxIn
{
public:
COutPoint prevout;
CScript scriptSig;
uint32_t nSequence;
CScriptWitness scriptWitness; //!< Only serialized through CTransaction
/* Setting nSequence to this value for every input in a transaction
* disables nLockTime. */
static const uint32_t SEQUENCE_FINAL = 0xffffffff;
/* Below flags apply in the context of BIP 68*/
/* If this flag set, CTxIn::nSequence is NOT interpreted as a
* relative lock-time. */
static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG = (1U << 31);
/* If CTxIn::nSequence encodes a relative lock-time and this flag
* is set, the relative lock-time has units of 512 seconds,
* otherwise it specifies blocks with a granularity of 1. */
static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG = (1 << 22);
/* If CTxIn::nSequence encodes a relative lock-time, this mask is
* applied to extract that lock-time from the sequence field. */
static const uint32_t SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
/* In order to use the same number of bits to encode roughly the
* same wall-clock duration, and because blocks are naturally
* limited to occur every 600s on average, the minimum granularity
* for time-based relative lock-time is fixed at 512 seconds.
* Converting from CTxIn::nSequence to seconds is performed by
* multiplying by 512 = 2^9, or equivalently shifting up by
* 9 bits. */
static const int SEQUENCE_LOCKTIME_GRANULARITY = 9;
};
- CTxOut : 交易输出 即UTXO
/** An output of a transaction. It contains the public key that the next input
* must be able to sign with to claim it.
*/
class CTxOut
{
public:
CAmount nValue;
CScript scriptPubKey;
};
- CTransaction
/** The basic transaction that is broadcasted on the network and contained in
* blocks. A transaction can contain multiple inputs and outputs.
*/
class CTransaction
{
public:
// Default transaction version.
static const int32_t CURRENT_VERSION=2;
// Changing the default transaction version requires a two step process: first
// adapting relay policy by bumping MAX_STANDARD_VERSION, and then later date
// bumping the default CURRENT_VERSION at which point both CURRENT_VERSION and
// MAX_STANDARD_VERSION will be equal.
static const int32_t MAX_STANDARD_VERSION=2;
// The local variables are made const to prevent unintended modification
// without updating the cached hash value. However, CTransaction is not
// actually immutable; deserialization and assignment are implemented,
// and bypass the constness. This is safe, as they update the entire
// structure, including the hash.
const std::vector<CTxIn> vin;
const std::vector<CTxOut> vout;
const int32_t nVersion;
const uint32_t nLockTime;
private:
/** Memory only. */
const uint256 hash;
const uint256 m_witness_hash;
};
- CMutableTransaction
/** A mutable version of CTransaction. */
struct CMutableTransaction
{
std::vector<CTxIn> vin;
std::vector<CTxOut> vout;
int32_t nVersion;
uint32_t nLockTime;
}
- CBlockHeader
/** Nodes collect new transactions into a block, hash them into a hash tree,
* and scan through nonce values to make the block's hash satisfy proof-of-work
* requirements. When they solve the proof-of-work, they broadcast the block
* to everyone and the block is added to the block chain. The first transaction
* in the block is a special one that creates a new coin owned by the creator
* of the block.
*/
class CBlockHeader
{
public:
// header
int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
uint32_t nTime;
uint32_t nBits;
uint32_t nNonce;
};
- CBlock
typedef std::shared_ptr<const CTransaction> CTransactionRef;
class CBlock : public CBlockHeader
{
public:
// network and disk
std::vector<CTransactionRef> vtx;
// memory only
mutable bool fChecked;
};
通过RPC获取区块内容:
bitcoin-cli -conf=/root/.bitcoin/bitcoin.conf getblock 000000000000000000081907805c7033f2f2bab49ed2bb49d66bb3d041f0df37
{
"hash": "000000000000000000081907805c7033f2f2bab49ed2bb49d66bb3d041f0df37",
"confirmations": 2,
"strippedsize": 929500,
"size": 1204476,
"weight": 3992976,
"height": 632843,
"version": 805298176,
"versionHex": "2fffe000",
"merkleroot": "98a4f6e067fba8d36af3d496809fb312ddcedcb6a6d29ae84c495a3b5ffb4557",
"tx": [
"fec1d4dc75acd742b55ac389e9b168a346f94a923d9de101a54a2bedf75133e3",
"9b3e777d2e0254d230fad0818d2e418ffb239158f5470d397607020e905eb72d",
"da180e71055df22e40b3cba6e43a478e21bd18520138bdae33a3ba1b44f1b854",
"9c711832bc1fc597d76870cef5cebc152109edb3e9103897b538ac39d43a30a2",
"16f484b17a92841223aa462c4dfa96c44da4575987407e4df1cb689c2a6b3d7a",
"1460ae192ba580dda2a036e1127d278bd8be3f0c840fe0d0bf7d809c5330ba46",
"3eb3cca09c759b492d50b638b83ca721e716e339ae86eb6316f6808ba9269db9",
.......
],
"time": 1591168036,
"mediantime": 1591165687,
"nonce": 3096579316,
"bits": "171297f6",
"difficulty": 15138043247082.88,
"chainwork": "00000000000000000000000000000000000000000ffe5faf686c877315279250",
"nTx": 2395,
"previousblockhash": "00000000000000000005c9d07b9d07168e4215af94f3ae562c0b1806b0d658ca",
"nextblockhash": "0000000000000000000587cadf7ff243cd056a31b1bf4b8ef3e313f92518e48b"
}