-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathapi.rs
250 lines (232 loc) Β· 6.06 KB
/
api.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
use {
super::*,
serde_hex::{SerHex, Strict},
};
pub use crate::{
subcommand::decode::RawOutput as Decode,
templates::{
BlocksHtml as Blocks, RuneHtml as Rune, RunesHtml as Runes, StatusHtml as Status,
TransactionHtml as Transaction,
},
};
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Block {
pub best_height: u32,
pub hash: BlockHash,
pub height: u32,
pub inscriptions: Vec<InscriptionId>,
pub runes: Vec<SpacedRune>,
pub target: BlockHash,
pub transactions: Vec<bitcoin::blockdata::transaction::Transaction>,
}
impl Block {
pub(crate) fn new(
block: bitcoin::Block,
height: Height,
best_height: Height,
inscriptions: Vec<InscriptionId>,
runes: Vec<SpacedRune>,
) -> Self {
Self {
hash: block.header.block_hash(),
target: target_as_block_hash(block.header.target()),
height: height.0,
best_height: best_height.0,
inscriptions,
runes,
transactions: block.txdata,
}
}
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct BlockInfo {
pub average_fee: u64,
pub average_fee_rate: u64,
pub bits: u32,
#[serde(with = "SerHex::<Strict>")]
pub chainwork: [u8; 32],
pub confirmations: i32,
pub difficulty: f64,
pub hash: BlockHash,
pub feerate_percentiles: [u64; 5],
pub height: u32,
pub max_fee: u64,
pub max_fee_rate: u64,
pub max_tx_size: u32,
pub median_fee: u64,
pub median_time: Option<u64>,
pub merkle_root: TxMerkleNode,
pub min_fee: u64,
pub min_fee_rate: u64,
pub next_block: Option<BlockHash>,
pub nonce: u32,
pub previous_block: Option<BlockHash>,
pub subsidy: u64,
pub target: BlockHash,
pub timestamp: u64,
pub total_fee: u64,
pub total_size: usize,
pub total_weight: usize,
pub transaction_count: u64,
pub version: u32,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Children {
pub ids: Vec<InscriptionId>,
pub more: bool,
pub page: usize,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct ChildInscriptions {
pub children: Vec<RelativeInscriptionRecursive>,
pub more: bool,
pub page: usize,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct ParentInscriptions {
pub parents: Vec<RelativeInscriptionRecursive>,
pub more: bool,
pub page: usize,
}
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct Inscription {
pub address: Option<String>,
pub charms: Vec<Charm>,
pub child_count: u64,
pub children: Vec<InscriptionId>,
pub content_length: Option<usize>,
pub content_type: Option<String>,
pub effective_content_type: Option<String>,
pub fee: u64,
pub height: u32,
pub id: InscriptionId,
pub next: Option<InscriptionId>,
pub number: i32,
pub parents: Vec<InscriptionId>,
pub previous: Option<InscriptionId>,
pub rune: Option<SpacedRune>,
pub sat: Option<ordinals::Sat>,
pub satpoint: SatPoint,
pub timestamp: i64,
pub value: Option<u64>,
pub metaprotocol: Option<String>,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct InscriptionRecursive {
pub charms: Vec<Charm>,
pub content_type: Option<String>,
pub content_length: Option<usize>,
pub delegate: Option<InscriptionId>,
pub fee: u64,
pub height: u32,
pub id: InscriptionId,
pub number: i32,
pub output: OutPoint,
pub sat: Option<ordinals::Sat>,
pub satpoint: SatPoint,
pub timestamp: i64,
pub value: Option<u64>,
pub address: Option<String>,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct RelativeInscriptionRecursive {
pub charms: Vec<Charm>,
pub fee: u64,
pub height: u32,
pub id: InscriptionId,
pub number: i32,
pub output: OutPoint,
pub sat: Option<ordinals::Sat>,
pub satpoint: SatPoint,
pub timestamp: i64,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Inscriptions {
pub ids: Vec<InscriptionId>,
pub more: bool,
pub page_index: u32,
}
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct UtxoRecursive {
pub inscriptions: Option<Vec<InscriptionId>>,
pub runes: Option<BTreeMap<SpacedRune, Pile>>,
pub sat_ranges: Option<Vec<(u64, u64)>>,
pub value: u64,
}
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct Output {
pub address: Option<Address<NetworkUnchecked>>,
pub indexed: bool,
pub inscriptions: Option<Vec<InscriptionId>>,
pub outpoint: OutPoint,
pub runes: Option<BTreeMap<SpacedRune, Pile>>,
pub sat_ranges: Option<Vec<(u64, u64)>>,
pub script_pubkey: ScriptBuf,
pub spent: bool,
pub transaction: Txid,
pub value: u64,
}
impl Output {
pub fn new(
chain: Chain,
inscriptions: Option<Vec<InscriptionId>>,
outpoint: OutPoint,
tx_out: TxOut,
indexed: bool,
runes: Option<BTreeMap<SpacedRune, Pile>>,
sat_ranges: Option<Vec<(u64, u64)>>,
spent: bool,
) -> Self {
Self {
address: chain
.address_from_script(&tx_out.script_pubkey)
.ok()
.map(|address| uncheck(&address)),
indexed,
inscriptions,
outpoint,
runes,
sat_ranges,
script_pubkey: tx_out.script_pubkey,
spent,
transaction: outpoint.txid,
value: tx_out.value.to_sat(),
}
}
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Sat {
pub address: Option<String>,
pub block: u32,
pub charms: Vec<Charm>,
pub cycle: u32,
pub decimal: String,
pub degree: String,
pub epoch: u32,
pub inscriptions: Vec<InscriptionId>,
pub name: String,
pub number: u64,
pub offset: u64,
pub percentile: String,
pub period: u32,
pub rarity: Rarity,
pub satpoint: Option<SatPoint>,
pub timestamp: i64,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct SatInscription {
pub id: Option<InscriptionId>,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct SatInscriptions {
pub ids: Vec<InscriptionId>,
pub more: bool,
pub page: u64,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct AddressInfo {
pub outputs: Vec<OutPoint>,
pub inscriptions: Option<Vec<InscriptionId>>,
pub sat_balance: u64,
pub runes_balances: Option<Vec<(SpacedRune, Decimal, Option<char>)>>,
}