File : blocks.ads
1 with Ada.Streams; use Ada.Streams;
2 with Interfaces; use Interfaces;
3 with Hashes; use Hashes;
4 with Transactions; use Transactions;
5
6
7 package Blocks is
8
9 -- Bitcoin Block Header (not including txn_count)
10 type BlockHeader is
11 record
12 Version : Integer_32 := 0; -- Block Version (signed)
13 PrevBlockHash : SHA256Hash; -- Hash of previous block
14 MerkleRootHash : SHA256Hash; -- Merkle tree root of this block
15 TimeStamp : Unsigned_32 := 0; -- Unix timestamp of block creation
16 DifficultyBits : Unsigned_32 := 0; -- Traget difficulty used for block
17 Nonce : Unsigned_32 := 0; -- Nonce used to generate block
18 end record;
19
20 -- Quite impossible to have more tx in block than bytes
21 subtype TxnCount_Bounds is Positive range 1 .. MAX_BLOCK_LENGTH;
22
23 -- A Bitcoin Block, represented in fast-indexable form
24 type Block is
25 record
26 Header : BlockHeader; -- Header (just the fixed-length parts)
27 Tx_N : TxnCount_Bounds; -- Number of tx in this block
28 -- ... to be continued
29 end record;
30
31 private
32
33 -- Read a Traditional representation of a Block into its Fast Form
34 procedure Block_Read(Stream : not null access Root_Stream_Type'Class;
35 B : out Block);
36 for Block'Read use Block_Read;
37
38 -- Produce a Traditional representation of a Block from its Fast Form
39 procedure Block_Write(Stream : not null access Root_Stream_Type'Class;
40 B : in Block);
41 for Block'Write use Block_Write;
42
43 end Blocks;