Skip to main content

abtc_application/
commands.rs

1//! Command types for the application
2//!
3//! Commands represent actions that modify state (CQRS pattern).
4
5use abtc_domain::primitives::{Block, Transaction};
6
7/// Command to submit a new transaction to the mempool
8#[derive(Clone, Debug)]
9pub struct SendTransaction {
10    pub tx: Transaction,
11}
12
13impl SendTransaction {
14    /// Create a new command to submit a transaction.
15    pub fn new(tx: Transaction) -> Self {
16        SendTransaction { tx }
17    }
18}
19
20/// Command to submit a mined block
21#[derive(Clone, Debug)]
22pub struct SubmitBlock {
23    pub block: Block,
24}
25
26impl SubmitBlock {
27    /// Create a new command to submit a mined block.
28    pub fn new(block: Block) -> Self {
29        SubmitBlock { block }
30    }
31}
32
33/// Command to mine a block
34#[derive(Clone, Debug)]
35pub struct MineBlock {
36    pub coinbase_address: String,
37}
38
39impl MineBlock {
40    /// Create a new command to mine a block to a given address.
41    pub fn new(coinbase_address: String) -> Self {
42        MineBlock { coinbase_address }
43    }
44}
45
46/// Command to update chain tip
47#[derive(Clone, Debug)]
48pub struct UpdateChainTip {
49    pub block_hash: String,
50    pub height: u32,
51}
52
53impl UpdateChainTip {
54    /// Create a new command to update the chain tip.
55    pub fn new(block_hash: String, height: u32) -> Self {
56        UpdateChainTip { block_hash, height }
57    }
58}