ord/
api.rs

1use {
2  super::*,
3  serde_hex::{SerHex, Strict},
4};
5
6pub use crate::templates::{
7  BlocksHtml as Blocks, RuneHtml as Rune, RunesHtml as Runes, StatusHtml as Status,
8  TransactionHtml as Transaction,
9};
10
11#[derive(Debug, PartialEq, Serialize, Deserialize)]
12pub struct Block {
13  pub best_height: u32,
14  pub hash: BlockHash,
15  pub height: u32,
16  pub inscriptions: Vec<InscriptionId>,
17  pub runes: Vec<SpacedRune>,
18  pub target: BlockHash,
19}
20
21impl Block {
22  pub(crate) fn new(
23    block: bitcoin::Block,
24    height: Height,
25    best_height: Height,
26    inscriptions: Vec<InscriptionId>,
27    runes: Vec<SpacedRune>,
28  ) -> Self {
29    Self {
30      hash: block.header.block_hash(),
31      target: target_as_block_hash(block.header.target()),
32      height: height.0,
33      best_height: best_height.0,
34      inscriptions,
35      runes,
36    }
37  }
38}
39
40#[derive(Debug, PartialEq, Serialize, Deserialize)]
41pub struct BlockInfo {
42  pub average_fee: u64,
43  pub average_fee_rate: u64,
44  pub bits: u32,
45  #[serde(with = "SerHex::<Strict>")]
46  pub chainwork: [u8; 32],
47  pub confirmations: i32,
48  pub difficulty: f64,
49  pub hash: BlockHash,
50  pub height: u32,
51  pub max_fee: u64,
52  pub max_fee_rate: u64,
53  pub max_tx_size: u32,
54  pub median_fee: u64,
55  pub median_time: Option<u64>,
56  pub merkle_root: TxMerkleNode,
57  pub min_fee: u64,
58  pub min_fee_rate: u64,
59  pub next_block: Option<BlockHash>,
60  pub nonce: u32,
61  pub previous_block: Option<BlockHash>,
62  pub subsidy: u64,
63  pub target: BlockHash,
64  pub timestamp: u64,
65  pub total_fee: u64,
66  pub total_size: usize,
67  pub total_weight: usize,
68  pub transaction_count: u64,
69  pub version: u32,
70}
71
72#[derive(Debug, PartialEq, Serialize, Deserialize)]
73pub struct Children {
74  pub ids: Vec<InscriptionId>,
75  pub more: bool,
76  pub page: usize,
77}
78
79#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
80pub struct Inscription {
81  pub address: Option<String>,
82  pub charms: Vec<Charm>,
83  pub children: Vec<InscriptionId>,
84  pub content_length: Option<usize>,
85  pub content_type: Option<String>,
86  pub effective_content_type: Option<String>,
87  pub fee: u64,
88  pub height: u32,
89  pub id: InscriptionId,
90  pub next: Option<InscriptionId>,
91  pub number: i32,
92  pub parents: Vec<InscriptionId>,
93  pub previous: Option<InscriptionId>,
94  pub rune: Option<SpacedRune>,
95  pub sat: Option<ordinals::Sat>,
96  pub satpoint: SatPoint,
97  pub timestamp: i64,
98  pub value: Option<u64>,
99}
100
101#[derive(Debug, PartialEq, Serialize, Deserialize)]
102pub struct InscriptionRecursive {
103  pub charms: Vec<Charm>,
104  pub content_type: Option<String>,
105  pub content_length: Option<usize>,
106  pub fee: u64,
107  pub height: u32,
108  pub id: InscriptionId,
109  pub number: i32,
110  pub output: OutPoint,
111  pub sat: Option<ordinals::Sat>,
112  pub satpoint: SatPoint,
113  pub timestamp: i64,
114  pub value: Option<u64>,
115}
116
117#[derive(Debug, PartialEq, Serialize, Deserialize)]
118pub struct Inscriptions {
119  pub ids: Vec<InscriptionId>,
120  pub more: bool,
121  pub page_index: u32,
122}
123
124#[derive(Debug, PartialEq, Serialize, Deserialize)]
125pub struct Output {
126  pub address: Option<Address<NetworkUnchecked>>,
127  pub indexed: bool,
128  pub inscriptions: Vec<InscriptionId>,
129  pub runes: Vec<(SpacedRune, Pile)>,
130  pub sat_ranges: Option<Vec<(u64, u64)>>,
131  pub script_pubkey: String,
132  pub spent: bool,
133  pub transaction: String,
134  pub value: u64,
135}
136
137impl Output {
138  pub fn new(
139    chain: Chain,
140    inscriptions: Vec<InscriptionId>,
141    outpoint: OutPoint,
142    tx_out: TxOut,
143    indexed: bool,
144    runes: Vec<(SpacedRune, Pile)>,
145    sat_ranges: Option<Vec<(u64, u64)>>,
146    spent: bool,
147  ) -> Self {
148    Self {
149      address: chain
150        .address_from_script(&tx_out.script_pubkey)
151        .ok()
152        .map(|address| uncheck(&address)),
153      indexed,
154      inscriptions,
155      runes,
156      sat_ranges,
157      script_pubkey: tx_out.script_pubkey.to_asm_string(),
158      spent,
159      transaction: outpoint.txid.to_string(),
160      value: tx_out.value,
161    }
162  }
163}
164
165#[derive(Debug, PartialEq, Serialize, Deserialize)]
166pub struct Sat {
167  pub block: u32,
168  pub charms: Vec<Charm>,
169  pub cycle: u32,
170  pub decimal: String,
171  pub degree: String,
172  pub epoch: u32,
173  pub inscriptions: Vec<InscriptionId>,
174  pub name: String,
175  pub number: u64,
176  pub offset: u64,
177  pub percentile: String,
178  pub period: u32,
179  pub rarity: Rarity,
180  pub satpoint: Option<SatPoint>,
181  pub timestamp: i64,
182}
183
184#[derive(Debug, PartialEq, Serialize, Deserialize)]
185pub struct SatInscription {
186  pub id: Option<InscriptionId>,
187}
188
189#[derive(Debug, PartialEq, Serialize, Deserialize)]
190pub struct SatInscriptions {
191  pub ids: Vec<InscriptionId>,
192  pub more: bool,
193  pub page: u64,
194}