titan_types/
event.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use {
    bitcoin::{BlockHash, OutPoint, Txid},
    borsh::{BorshDeserialize, BorshSerialize},
    ordinals::RuneId,
    serde::{Deserialize, Serialize},
    std::fmt,
};

#[derive(
    Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, BorshSerialize, BorshDeserialize,
)]
pub enum EventType {
    RuneEtched,
    RuneBurned,
    RuneMinted,
    RuneTransferred,
    AddressModified,
    TransactionsAdded,
    TransactionsReplaced,
    NewBlock,
}

impl From<Event> for EventType {
    fn from(event: Event) -> Self {
        match event {
            Event::RuneEtched { .. } => EventType::RuneEtched,
            Event::RuneBurned { .. } => EventType::RuneBurned,
            Event::RuneMinted { .. } => EventType::RuneMinted,
            Event::RuneTransferred { .. } => EventType::RuneTransferred,
            Event::AddressModified { .. } => EventType::AddressModified,
            Event::TransactionsAdded { .. } => EventType::TransactionsAdded,
            Event::TransactionsReplaced { .. } => EventType::TransactionsReplaced,
            Event::NewBlock { .. } => EventType::NewBlock,
        }
    }
}

impl fmt::Display for EventType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        // Simply print the variant name.
        match self {
            EventType::RuneEtched => write!(f, "RuneEtched"),
            EventType::RuneBurned => write!(f, "RuneBurned"),
            EventType::RuneMinted => write!(f, "RuneMinted"),
            EventType::RuneTransferred => write!(f, "RuneTransferred"),
            EventType::AddressModified => write!(f, "AddressModified"),
            EventType::TransactionsAdded => write!(f, "TransactionsAdded"),
            EventType::TransactionsReplaced => write!(f, "TransactionsReplaced"),
            EventType::NewBlock => write!(f, "NewBlock"),
        }
    }
}

impl Into<String> for EventType {
    fn into(self) -> String {
        self.to_string()
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Location {
    pub mempool: bool,
    pub block_height: Option<u64>,
}

impl Location {
    pub fn mempool() -> Self {
        Location {
            mempool: true,
            block_height: None,
        }
    }

    pub fn block(block_height: u64) -> Self {
        Location {
            mempool: false,
            block_height: Some(block_height),
        }
    }
}

impl From<Option<u64>> for Location {
    fn from(block_height: Option<u64>) -> Self {
        match block_height {
            Some(block_height) => Location {
                mempool: false,
                block_height: Some(block_height),
            },
            None => Location {
                mempool: true,
                block_height: None,
            },
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(tag = "type", content = "data")]
pub enum Event {
    RuneEtched {
        location: Location,
        rune_id: RuneId,
        txid: Txid,
    },
    RuneBurned {
        amount: u128,
        location: Location,
        rune_id: RuneId,
        txid: Txid,
    },
    RuneMinted {
        amount: u128,
        location: Location,
        rune_id: RuneId,
        txid: Txid,
    },
    RuneTransferred {
        amount: u128,
        location: Location,
        outpoint: OutPoint,
        rune_id: RuneId,
        txid: Txid,
    },
    AddressModified {
        address: String,
        location: Location,
    },
    TransactionsAdded {
        txids: Vec<Txid>,
    },
    TransactionsReplaced {
        txids: Vec<Txid>,
    },
    NewBlock {
        block_hash: BlockHash,
        block_height: u64,
    },
}