saturn_mempool_oracle/
mempool_entry.rs

1use std::fmt;
2
3use borsh::{BorshDeserialize, BorshSerialize};
4use serde::{Deserialize, Serialize};
5
6use crate::txid::Txid;
7
8/// MempoolEntry structure for the smart contract
9///
10/// `total_fee` and `total_vsize` represent values for this entry and all of
11/// its ancestors
12#[repr(C)]
13#[derive(
14    Default,
15    BorshSerialize,
16    BorshDeserialize,
17    Serialize,
18    Deserialize,
19    Clone,
20    PartialEq,
21    Eq,
22    Copy,
23    Hash,
24)]
25#[serde(rename_all = "camelCase")]
26pub struct MempoolEntry {
27    pub txid: Txid,       // 16 bytes
28    pub total_fee: u64,   // 8 bytes
29    pub total_vsize: u64, // 8 bytes
30    pub descendants: u16, // 2 bytes
31    pub ancestors: u16,   // 2 bytes
32                          // 20 bytes + 16 bytes = 36
33                          // 10MB => 10_000_000 / 36 ~= 300k
34                          // Return:  20 bytes + 1 byte (option) = 21
35                          // 1KB => 1024 / 21 = 48
36}
37
38impl fmt::Display for MempoolEntry {
39    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40        write!(
41            f,
42            "txid: {}, total_fee: {}, total_vsize: {}, descendants: {}, ancestors: {}",
43            self.txid, self.total_fee, self.total_vsize, self.descendants, self.ancestors
44        )
45    }
46}
47
48impl fmt::Debug for MempoolEntry {
49    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50        write!(f, "{}", self)
51    }
52}
53
54#[repr(C)]
55#[derive(Default, BorshSerialize, BorshDeserialize, Debug, Clone, PartialEq, Eq, Copy, Hash)]
56pub struct ReturnedMempoolEntry {
57    pub total_fee: u64,
58    pub total_vsize: u64,
59    pub descendants: u16,
60    pub ancestors: u16,
61}
62
63impl From<MempoolEntry> for ReturnedMempoolEntry {
64    fn from(entry: MempoolEntry) -> Self {
65        Self {
66            total_fee: entry.total_fee,
67            total_vsize: entry.total_vsize,
68            descendants: entry.descendants,
69            ancestors: entry.ancestors,
70        }
71    }
72}