Struct Block

The block which contains the block header and its body (the transactions).

struct Block ;

Fields

NameTypeDescription
header BlockHeader
merkle_tree geod24.bitblob.BitBlob!(64L)[]
txs Transaction[]

Methods

NameDescription
buildMerkleTree () Build a merkle tree and its root, and store the tree to this Block
buildMerkleTree (txs, merkle_tree) Build a merkle tree and return its root
checkMerklePath (hash, merkle_path, index) Calculate the merkle root using the merkle path.
computeHash (dg) Computes the hash matching this block
findHashIndex (hash) Find the sequence of transactions for the hash.
frozens () Returns a range of any freeze transactions in this block
getMerklePath (index) Get merkle path
payments () Returns a range of any payment transactions in this block
serialize (dg) Block serialization
updateSignature (signature, validators)

Example

immutable Hash merkle =
    Hash(`0xdb6e67f59fe0b30676037e4970705df8287f0de38298dcc09e50a8e85413` ~
    `959ca4c52a9fa1edbe6a47cbb6b5e9b2a19b4d0877cc1f5955a7166fe6884eecd2c3`);

immutable address = `boa1xrra39xpg5q9zwhsq6u7pw508z2let6dj8r5lr4q0d0nff240fvd27yme3h`;
PublicKey pubkey = PublicKey.fromString(address);

Transaction tx = Transaction(
    [
        Output(62_500_000.coins, pubkey),
        Output(62_500_000.coins, pubkey),
        Output(62_500_000.coins, pubkey),
        Output(62_500_000.coins, pubkey),
        Output(62_500_000.coins, pubkey),
        Output(62_500_000.coins, pubkey),
        Output(62_500_000.coins, pubkey),
        Output(62_500_000.coins, pubkey)
    ]);

auto validators = typeof(BlockHeader.validators)(6);
validators[0] = true;
validators[2] = true;
validators[4] = true;

Enrollment[] enrollments;
enrollments ~= Enrollment.init;
enrollments ~= Enrollment.init;

Block block =
{
    header:
    {
        prev_block:  Hash.init,
        height:      Height(0),
        merkle_root: merkle,
        validators:  validators,
        signature:   Signature.fromString(
                        "0x0f55e869b35fdd36a1f5147771c0c2f5ad35ec7b3e4e"
                        ~ "4f77bd37f1e0aef06d1a4b62ed5c610735b73e3175"
                        ~ "47ab3dc3402b05fd57419a2a5def798a03df2ef56a"),
        enrollments: enrollments,
    },
    txs: [ tx ],
    merkle_tree: [ merkle ],
};
testSymmetry!Block();
testSymmetry(block);
assert(block.header.validators[0]);
assert(!block.header.validators[1]);