zeldhash_protocol/types.rs
1use bitcoin::Txid;
2
3/// 12-byte key identifying a UTXO, derived from txid and vout via xxh3-128.
4pub type UtxoKey = [u8; 12];
5
6/// ZELD amount type (unsigned 64-bit integer).
7pub type Amount = u64;
8
9/// Stored ZELD balance type (signed 64-bit integer).
10/// Positive values represent spendable balances, negative values are spent tombstones.
11pub type Balance = i64;
12
13/// Represents a transaction output with ZELD-relevant data.
14#[derive(Debug, Clone)]
15pub struct ZeldOutput {
16 /// Unique key identifying this UTXO.
17 pub utxo_key: UtxoKey,
18 /// Satoshi value of this output.
19 pub value: Amount,
20 /// ZELD reward assigned to this output.
21 pub reward: Amount,
22 /// Custom distribution amount from OP_RETURN (if any).
23 pub distribution: Amount,
24 /// Output index within the transaction.
25 pub vout: u32,
26 /// Bitcoin address for the reward-carrying output only (first non-OP_RETURN),
27 /// if determinable. `None` for non-standard scripts (e.g., bare multisig),
28 /// or for non-reward outputs where no address is stored.
29 pub address: Option<String>,
30}
31
32/// Represents a transaction input with ZELD-relevant data.
33#[derive(Debug, Clone)]
34pub struct ZeldInput {
35 /// Key of the UTXO being spent.
36 pub utxo_key: UtxoKey,
37}
38
39/// Pre-processed transaction with all ZELD-relevant fields.
40#[derive(Debug, Clone)]
41pub struct ZeldTransaction {
42 /// Transaction ID.
43 pub txid: Txid,
44 /// Transaction inputs.
45 pub inputs: Vec<ZeldInput>,
46 /// Transaction outputs (excluding OP_RETURN).
47 pub outputs: Vec<ZeldOutput>,
48 /// Number of leading zeros in the txid.
49 pub zero_count: u8,
50 /// Total ZELD reward for this transaction.
51 pub reward: Amount,
52 /// Whether custom distribution was specified via OP_RETURN.
53 pub has_op_return_distribution: bool,
54}
55
56/// Pre-processed block with all ZELD-relevant transactions.
57#[derive(Debug, Clone)]
58pub struct PreProcessedZeldBlock {
59 /// Transactions in the block (excluding coinbase).
60 pub transactions: Vec<ZeldTransaction>,
61 /// Highest leading zero count among all transactions.
62 pub max_zero_count: u8,
63}
64
65/// Reward information for a single rewarded output.
66#[derive(Debug, Clone)]
67pub struct Reward {
68 /// Transaction ID that produced the reward.
69 pub txid: Txid,
70 /// Output index carrying the reward.
71 pub vout: u32,
72 /// ZELD reward granted to the output.
73 pub reward: Amount,
74 /// Leading zero count of the transaction ID.
75 pub zero_count: u8,
76 /// Bitcoin address for the reward-carrying output only (first non-OP_RETURN),
77 /// if determinable. `None` for non-standard scripts (e.g., bare multisig),
78 /// or for non-reward outputs where no address is stored.
79 pub address: Option<String>,
80}
81
82/// Fully processed block statistics and reward set.
83#[derive(Debug, Clone)]
84pub struct ProcessedZeldBlock {
85 /// All rewards generated within the block.
86 pub rewards: Vec<Reward>,
87 /// Sum of all rewards in the block.
88 pub total_reward: Amount,
89 /// Highest leading zero count observed in the block.
90 pub max_zero_count: u8,
91 /// TXID of the transaction with the highest zero count.
92 pub nicest_txid: Option<Txid>,
93 /// Number of previously existing UTXOs spent in the block.
94 pub utxo_spent_count: u64,
95 /// Number of new UTXOs created in the block.
96 pub new_utxo_count: u64,
97}