1use bitcoin::BlockHash;
2use serde::{Deserialize, Serialize};
3use urma_chain::observation::Chain;
4
5pub const API_VERSION: u32 = 1;
6pub const SCAN_RULES_VERSION: u32 = 1;
7
8#[derive(Clone, Debug, Serialize, Deserialize)]
11#[serde(deny_unknown_fields)]
12pub struct PinReceipt {
13 pub root: bitcoin::Txid,
14 pub pinned: bool,
15}
16
17#[derive(Clone, Debug, Serialize, Deserialize)]
20#[serde(deny_unknown_fields)]
21pub struct PruneReceipt {
22 pub records_removed: u64,
23}
24
25#[derive(Clone, Debug, Serialize, Deserialize)]
31#[serde(deny_unknown_fields)]
32pub struct RecordPackage {
33 pub version: u32,
34 pub chain_genesis: BlockHash,
35 pub block: ChainPoint,
36 pub reveal: urma_chain::inclusion::TransactionProof,
37 pub commit: Vec<u8>,
38}
39
40#[derive(Clone, Debug, Serialize, Deserialize)]
43pub struct RecordReceipt {
44 pub generation: u64,
45 pub block: ChainPoint,
46 pub position: u32,
47 pub txid: bitcoin::Txid,
48 pub wtxid: bitcoin::Wtxid,
49}
50
51#[derive(Clone, Debug, Serialize, Deserialize)]
52pub struct ArchivedRecord {
53 pub receipt: RecordReceipt,
54 pub package: RecordPackage,
55}
56
57#[derive(Clone, Debug, Serialize, Deserialize)]
61pub struct ObjectStatus {
62 pub root: bitcoin::Txid,
63 pub verified_generation: u64,
64 pub payload_bytes: u64,
65 pub members_total: u64,
66 pub members_local: u64,
67 pub members_selected: u64,
69 pub pinned: bool,
70}
71
72impl ObjectStatus {
73 pub fn locally_complete(&self) -> bool {
74 self.members_total > 0 && self.members_local == self.members_total
75 }
76
77 pub fn selected_complete(&self) -> bool {
78 self.locally_complete() && self.members_selected == self.members_total
79 }
80}
81
82#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
83pub struct ChainPoint {
84 pub height: u64,
85 pub hash: BlockHash,
86}
87
88#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
89#[serde(rename_all = "kebab-case")]
90pub enum Retention {
91 Pruned,
92 Unpruned,
93}
94
95#[derive(Clone, Debug, Serialize, Deserialize)]
98#[serde(deny_unknown_fields)]
99pub struct ArchiveConfig {
100 pub chain: Chain,
101 pub application_start: ChainPoint,
102 pub retention: Retention,
103}
104
105#[derive(Clone, Debug, Serialize, Deserialize)]
106pub struct ArchiveStatus {
107 pub api_version: u32,
108 pub chain_genesis: BlockHash,
109 pub application_start: ChainPoint,
110 pub retention: Retention,
111 pub generation: u64,
112 pub selected_tip: Option<ChainPoint>,
113 pub indexed_through: Option<ChainPoint>,
116 pub scanned_blocks: u64,
117 pub unresolved_dependencies: u64,
118 pub stored_transactions: u64,
119 pub scan_rules_version: u32,
120 pub peer_synced_through: Option<ChainPoint>,
122 pub peer_omissions: u64,
124 pub unaudited_records: u64,
126}
127
128#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
132pub struct CacheReceipt {
133 pub enabled: bool,
134 pub limit_bytes: u64,
135 pub before_bytes: u64,
136 pub remaining_bytes: u64,
137 pub removed_records: u64,
138 pub removed_transactions: u64,
139 pub over_budget: bool,
140}
141
142#[derive(Clone, Debug, Serialize, Deserialize)]
145pub struct ServiceStatus {
146 pub archive: ArchiveStatus,
147 pub last_sync_error: Option<String>,
148 pub last_sync_error_at: Option<u64>,
149 pub last_retention_error: Option<String>,
150 pub last_retention_error_at: Option<u64>,
151 pub last_names_error: Option<String>,
152 pub last_names_error_at: Option<u64>,
153 pub last_dependency_error: Option<String>,
154 pub last_dependency_error_at: Option<u64>,
155 pub last_inventory_error: Option<String>,
156 pub last_inventory_error_at: Option<u64>,
157 pub last_discovery_error: Option<String>,
158 pub last_discovery_error_at: Option<u64>,
159 pub commit_sources: Vec<CommitSourceStatus>,
160 pub cache_limit_bytes: u64,
161 pub last_cache_error: Option<String>,
162 pub last_cache_error_at: Option<u64>,
163 pub last_cache_maintenance: Option<CacheReceipt>,
164 pub overlay: Option<OverlayStatus>,
165 #[serde(default)]
167 pub chain_peers: u64,
168 pub retention_configured: bool,
169 pub record_sources_configured: u64,
170 pub capabilities: Vec<String>,
171}
172
173#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
174pub struct CommitSourceStatus {
175 pub label: String,
176 pub last_error: Option<String>,
177 pub last_error_at: Option<u64>,
178}
179
180#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
182pub struct OverlayStatus {
183 pub peer_id: String,
184 #[serde(default)]
185 pub listen: Vec<String>,
186 #[serde(default)]
187 pub announce: Vec<String>,
188 pub peer_book: u64,
189 pub connected: u64,
190 pub admitted: u64,
191 pub rejected: u64,
192 pub peers: Vec<OverlayPeerStatus>,
193 pub discovery: Option<DiscoveryStatus>,
194}
195
196#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
200pub struct DiscoveryStatus {
201 pub seeds: u64,
202 pub book: u64,
203 pub reached: u64,
204 pub reached_ever: u64,
205 pub gossip: u64,
206 pub last_seed_round_error: Option<String>,
207 pub last_seed_round_error_at: Option<u64>,
208 pub last_gossip_error: Option<String>,
209 pub last_gossip_error_at: Option<u64>,
210}
211
212#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
214pub struct Omission {
215 pub peer: String,
216 pub block: ChainPoint,
217 pub position: u32,
218 pub txid: bitcoin::Txid,
219 pub generation: u64,
220}
221
222#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
225#[serde(rename_all = "snake_case")]
226pub enum BookOrigin {
227 Gossip,
228 Seed,
229 Manual,
230}
231
232#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
236pub struct BookEntry {
237 pub peer_id: Option<String>,
238 pub addrs: Vec<String>,
239 pub origin: BookOrigin,
240 pub last_success: Option<u64>,
241 pub failures: u32,
242 pub banned_until: Option<u64>,
243}
244
245#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
246pub struct OverlayPeerStatus {
247 pub label: String,
248 pub cursor: u64,
249 pub synced_through: Option<u64>,
250 pub last_error: Option<String>,
251 pub last_error_at: Option<u64>,
252 pub backoff_until: Option<u64>,
254 pub last_progress_at: Option<u64>,
256}