Improve docs for blockdata::block
Improve the rustdocs for the `blockdata::block` module: - Use full sentences (capitalisation and full stop) - Use third person tense instead of imperative - Improve wording if needed
This commit is contained in:
parent
f03092c380
commit
146d5e83d1
|
@ -44,30 +44,30 @@ use VarInt;
|
|||
pub struct BlockHeader {
|
||||
/// The protocol version. Should always be 1.
|
||||
pub version: i32,
|
||||
/// Reference to the previous block in the chain
|
||||
/// Reference to the previous block in the chain.
|
||||
pub prev_blockhash: BlockHash,
|
||||
/// The root hash of the merkle tree of transactions in the block
|
||||
/// The root hash of the merkle tree of transactions in the block.
|
||||
pub merkle_root: TxMerkleNode,
|
||||
/// The timestamp of the block, as claimed by the miner
|
||||
/// The timestamp of the block, as claimed by the miner.
|
||||
pub time: u32,
|
||||
/// The target value below which the blockhash must lie, encoded as a
|
||||
/// a float (with well-defined rounding, of course)
|
||||
/// a float (with well-defined rounding, of course).
|
||||
pub bits: u32,
|
||||
/// The nonce, selected to obtain a low enough blockhash
|
||||
/// The nonce, selected to obtain a low enough blockhash.
|
||||
pub nonce: u32,
|
||||
}
|
||||
|
||||
impl_consensus_encoding!(BlockHeader, version, prev_blockhash, merkle_root, time, bits, nonce);
|
||||
|
||||
impl BlockHeader {
|
||||
/// Return the block hash.
|
||||
/// Returns the block hash.
|
||||
pub fn block_hash(&self) -> BlockHash {
|
||||
let mut engine = BlockHash::engine();
|
||||
self.consensus_encode(&mut engine).expect("engines don't error");
|
||||
BlockHash::from_engine(engine)
|
||||
}
|
||||
|
||||
/// Computes the target [0, T] that a blockhash must land in to be valid
|
||||
/// Computes the target [0, T] that a blockhash must land in to be valid.
|
||||
pub fn target(&self) -> Uint256 {
|
||||
Self::u256_from_compact_target(self.bits)
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ impl BlockHeader {
|
|||
compact | (size << 24) as u32
|
||||
}
|
||||
|
||||
/// Compute the popular "difficulty" measure for mining
|
||||
/// Computes the popular "difficulty" measure for mining.
|
||||
pub fn difficulty(&self, network: Network) -> u64 {
|
||||
(max_target(network) / self.target()).low_u64()
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ impl BlockHeader {
|
|||
if hash <= target { Ok(block_hash) } else { Err(BlockBadProofOfWork) }
|
||||
}
|
||||
|
||||
/// Returns the total work of the block
|
||||
/// Returns the total work of the block.
|
||||
pub fn work(&self) -> Uint256 {
|
||||
// 2**256 / (target + 1) == ~target / (target+1) + 1 (eqn shamelessly stolen from bitcoind)
|
||||
let mut ret = !self.target();
|
||||
|
@ -169,7 +169,7 @@ pub struct Block {
|
|||
impl_consensus_encoding!(Block, header, txdata);
|
||||
|
||||
impl Block {
|
||||
/// Return the block hash.
|
||||
/// Returns the block hash.
|
||||
pub fn block_hash(&self) -> BlockHash {
|
||||
self.header.block_hash()
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ impl Block {
|
|||
false
|
||||
}
|
||||
|
||||
/// Compute the transaction merkle root.
|
||||
/// Computes the transaction merkle root.
|
||||
pub fn compute_merkle_root(&self) -> Option<TxMerkleNode> {
|
||||
let hashes = self.txdata.iter().map(|obj| obj.txid().as_hash());
|
||||
bitcoin_merkle_root(hashes).map(|h| h.into())
|
||||
|
@ -228,7 +228,7 @@ impl Block {
|
|||
self.compute_merkle_root()
|
||||
}
|
||||
|
||||
/// compute witness commitment for the transaction list
|
||||
/// Computes the witness commitment for the block's transaction list.
|
||||
pub fn compute_witness_commitment (witness_root: &WitnessMerkleNode, witness_reserved_value: &[u8]) -> WitnessCommitment {
|
||||
let mut encoder = WitnessCommitment::engine();
|
||||
witness_root.consensus_encode(&mut encoder).expect("engines don't error");
|
||||
|
@ -236,7 +236,7 @@ impl Block {
|
|||
WitnessCommitment::from_engine(encoder)
|
||||
}
|
||||
|
||||
/// Merkle root of transactions hashed for witness
|
||||
/// Computes the merkle root of transactions hashed for witness.
|
||||
pub fn witness_root(&self) -> Option<WitnessMerkleNode> {
|
||||
let hashes = self.txdata.iter().enumerate().map(|(i, t)|
|
||||
if i == 0 {
|
||||
|
@ -274,7 +274,7 @@ impl Block {
|
|||
base_weight + txs_weight
|
||||
}
|
||||
|
||||
/// Get the coinbase transaction, if one is present.
|
||||
/// Returns the coinbase transaction, if one is present.
|
||||
pub fn coinbase(&self) -> Option<&Transaction> {
|
||||
self.txdata.first()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue