titan_types/
event.rs

1use {
2    bitcoin::{BlockHash, OutPoint, Txid},
3    borsh::{BorshDeserialize, BorshSerialize},
4    ordinals::RuneId,
5    serde::{Deserialize, Serialize},
6    std::fmt,
7};
8
9#[derive(
10    Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, BorshSerialize, BorshDeserialize,
11)]
12pub enum EventType {
13    RuneEtched,
14    RuneBurned,
15    RuneMinted,
16    RuneTransferred,
17    AddressModified,
18    TransactionsAdded,
19    TransactionsReplaced,
20    NewBlock,
21    Reorg,
22}
23
24impl From<Event> for EventType {
25    fn from(event: Event) -> Self {
26        match event {
27            Event::RuneEtched { .. } => EventType::RuneEtched,
28            Event::RuneBurned { .. } => EventType::RuneBurned,
29            Event::RuneMinted { .. } => EventType::RuneMinted,
30            Event::RuneTransferred { .. } => EventType::RuneTransferred,
31            Event::AddressModified { .. } => EventType::AddressModified,
32            Event::TransactionsAdded { .. } => EventType::TransactionsAdded,
33            Event::TransactionsReplaced { .. } => EventType::TransactionsReplaced,
34            Event::NewBlock { .. } => EventType::NewBlock,
35            Event::Reorg { .. } => EventType::Reorg,
36        }
37    }
38}
39
40impl fmt::Display for EventType {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        // Simply print the variant name.
43        match self {
44            EventType::RuneEtched => write!(f, "RuneEtched"),
45            EventType::RuneBurned => write!(f, "RuneBurned"),
46            EventType::RuneMinted => write!(f, "RuneMinted"),
47            EventType::RuneTransferred => write!(f, "RuneTransferred"),
48            EventType::AddressModified => write!(f, "AddressModified"),
49            EventType::TransactionsAdded => write!(f, "TransactionsAdded"),
50            EventType::TransactionsReplaced => write!(f, "TransactionsReplaced"),
51            EventType::NewBlock => write!(f, "NewBlock"),
52            EventType::Reorg => write!(f, "Reorg"),
53        }
54    }
55}
56
57impl Into<String> for EventType {
58    fn into(self) -> String {
59        self.to_string()
60    }
61}
62
63#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
64pub struct Location {
65    pub mempool: bool,
66    pub block_height: Option<u64>,
67}
68
69impl Location {
70    pub fn mempool() -> Self {
71        Location {
72            mempool: true,
73            block_height: None,
74        }
75    }
76
77    pub fn block(block_height: u64) -> Self {
78        Location {
79            mempool: false,
80            block_height: Some(block_height),
81        }
82    }
83}
84
85impl From<Option<u64>> for Location {
86    fn from(block_height: Option<u64>) -> Self {
87        match block_height {
88            Some(block_height) => Location {
89                mempool: false,
90                block_height: Some(block_height),
91            },
92            None => Location {
93                mempool: true,
94                block_height: None,
95            },
96        }
97    }
98}
99
100#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
101#[serde(tag = "type", content = "data")]
102pub enum Event {
103    RuneEtched {
104        location: Location,
105        rune_id: RuneId,
106        txid: Txid,
107    },
108    RuneBurned {
109        amount: u128,
110        location: Location,
111        rune_id: RuneId,
112        txid: Txid,
113    },
114    RuneMinted {
115        amount: u128,
116        location: Location,
117        rune_id: RuneId,
118        txid: Txid,
119    },
120    RuneTransferred {
121        amount: u128,
122        location: Location,
123        outpoint: OutPoint,
124        rune_id: RuneId,
125        txid: Txid,
126    },
127    AddressModified {
128        address: String,
129        location: Location,
130    },
131    TransactionsAdded {
132        txids: Vec<Txid>,
133    },
134    TransactionsReplaced {
135        txids: Vec<Txid>,
136    },
137    NewBlock {
138        block_hash: BlockHash,
139        block_height: u64,
140    },
141    Reorg {
142        height: u64,
143        depth: u64,
144    },
145}