0x00 Summary
Block is the basic structure of block chain, is also the carrier of trading information, miners through the form of mining to generate new blocks and get rewards, the new block process is also a transaction packaging process, only to join the block in the transaction will be recognized by all other nodes of the system, is effective. 0x01 Cblockheader
/** * Nodes in the network are constantly collecting new transactions, then a Merkle tree is packaged into a block, the process of packing is to complete the requirements of the work proof, when the node to solve the current random number, * It will broadcast the current block to all other nodes, and add to the block chain. * The first transaction in the block is called the Coinbase transaction, which is the generated SGD, sent to the creator of the Block/class Cblockheader {public://header int32_t nversion; Version uint256 Hashprevblock; The hash uint256 Hashmerkleroot of the previous block; Merkle Root uint32_t ntime; Time Stamp uint32_t nbits; POW difficulty uint32_t nnonce;
The random number to find Cblockheader () {setnull ();
} add_serialize_methods; Template <typename Stream, typename operation> inline void Serializationop (stream& s, Operation ser_action)
{ReadWrite (this->nversion);
ReadWrite (Hashprevblock);
ReadWrite (Hashmerkleroot);
ReadWrite (Ntime);
ReadWrite (nbits);
ReadWrite (nnonce);
} void SetNull () {nversion = 0;
Hashprevblock.setnull ();
Hashmerkleroot.setnull ();
ntime = 0;
nbits = 0;
nnonce = 0; BOOL IsNull () CONST {return (nbits = 0);
} uint256 Gethash () const;
int64_t getblocktime () const {return (int64_t) ntime; }
};
0x02 Cblock
Class Cblock:public Cblockheader {public://Network and disk std::vector<ctransactionref> vtx;//All transactions Memory only mutable bool fchecked;
Whether the transaction has been validated and constitutes the Merkle tree Cblock () {setnull ();
} cblock (const Cblockheader &header) {setnull ();
* ((cblockheader*) this) = header;
} add_serialize_methods; Template <typename Stream, typename operation> inline void Serializationop (stream& s, Operation ser_action)
{ReadWrite (* (cblockheader*) this);
ReadWrite (VTX);
} void SetNull () {cblockheader::setnull ();
Vtx.clear ();
fchecked = false;
} cblockheader Getblockheader () const {Cblockheader block;
Block.nversion = nversion;
Block.hashprevblock = Hashprevblock;
Block.hashmerkleroot = Hashmerkleroot;
Block.ntime = Ntime;
Block.nbits = nbits; Block.nnonce = Nnonce;
return block;
} std::string ToString () const;
};