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