iuna

iuna

iuna - experimental devnet protocol
git clone https://getiuna.org/git/iuna.git
Log | Files | Refs | README | LICENSE

types.rs (11989B)


      1 use serde::{Deserialize, Serialize};
      2 
      3 use crate::{
      4     adapters::{config_store::UiConfig, ui_data_store::BlockMetricRow},
      5     domain::{Amount, BurnLeaderRank, OutPoint, Transaction, TxOutput},
      6 };
      7 
      8 #[derive(Debug, Deserialize)]
      9 pub(super) struct AuthForm {
     10     pub(super) password: String,
     11 }
     12 
     13 #[derive(Debug, Deserialize)]
     14 pub(super) struct ChangePasswordForm {
     15     pub(super) old_password: String,
     16     pub(super) new_password: String,
     17 }
     18 
     19 #[derive(Debug, Serialize)]
     20 pub(super) struct AuthStatusResponse {
     21     pub(super) configured: bool,
     22     pub(super) authenticated: bool,
     23 }
     24 
     25 #[derive(Debug, Serialize)]
     26 pub(super) struct NetworkHealthResponse {
     27     pub(super) ok: bool,
     28     pub(super) state: String,
     29     pub(super) local_height: u64,
     30     pub(super) best_known_height: u64,
     31     pub(super) shared_height: u64,
     32     pub(super) lag_blocks: u64,
     33     pub(super) outbound_peers: usize,
     34     pub(super) inbound_peers: usize,
     35     pub(super) healthy_peers: usize,
     36     pub(super) failed_peers: usize,
     37     pub(super) stale_peers: usize,
     38     pub(super) banned_peers: usize,
     39     pub(super) pending_transactions: usize,
     40     pub(super) pending_plain_transactions: usize,
     41     pub(super) pending_blinded_transactions: usize,
     42     pub(super) pending_blinded_reveals: usize,
     43     pub(super) network_time_offset_ms: Option<i64>,
     44     pub(super) bad_clock_peers: usize,
     45     pub(super) last_error: Option<String>,
     46 }
     47 
     48 #[derive(Clone, Copy, Debug, Default)]
     49 pub(super) struct MempoolCounts {
     50     pub(super) plain_transactions: usize,
     51     pub(super) blinded_transactions: usize,
     52     pub(super) blinded_reveals: usize,
     53 }
     54 
     55 impl MempoolCounts {
     56     pub(super) fn total(&self) -> usize {
     57         self.plain_transactions
     58             .saturating_add(self.blinded_transactions)
     59             .saturating_add(self.blinded_reveals)
     60     }
     61 }
     62 
     63 #[derive(Clone, Copy, Debug)]
     64 pub(super) struct NetworkHealthLocalState {
     65     pub(super) height: u64,
     66     pub(super) pending_transactions: usize,
     67 }
     68 
     69 #[derive(Debug, Deserialize)]
     70 pub(super) struct BurnSettingsForm {
     71     pub(super) enabled: Option<bool>,
     72     pub(super) amount: Amount,
     73     pub(super) fee_per_byte: Option<Amount>,
     74 }
     75 
     76 #[derive(Debug, Deserialize)]
     77 pub(super) struct RecoveryVdfSettingsForm {
     78     pub(super) top_rank_percent: u8,
     79 }
     80 
     81 #[derive(Debug, Deserialize)]
     82 pub(super) struct PowMiningForm {
     83     pub(super) enabled: bool,
     84     pub(super) workers: Option<u8>,
     85 }
     86 
     87 #[derive(Debug, Deserialize)]
     88 pub(super) struct MetricsSettingsForm {
     89     pub(super) enabled: bool,
     90 }
     91 
     92 #[derive(Debug, Deserialize)]
     93 pub(super) struct ChainResetForm {
     94     pub(super) confirm: String,
     95 }
     96 
     97 #[derive(Debug, Deserialize)]
     98 pub(super) struct P2pAnnounceForm {
     99     pub(super) addr: String,
    100 }
    101 
    102 #[derive(Debug, Deserialize)]
    103 pub(super) struct P2pInboundForm {
    104     pub(super) enabled: bool,
    105     pub(super) bind_port: Option<u16>,
    106 }
    107 
    108 #[derive(Debug, Serialize)]
    109 pub(super) struct ConfigResponse {
    110     #[serde(flatten)]
    111     pub(super) config: UiConfig,
    112     pub(super) p2p_inbound_runtime_active: bool,
    113     pub(super) p2p_runtime_bind_addr: String,
    114 }
    115 
    116 #[derive(Debug, Deserialize)]
    117 pub(super) struct TransferForm {
    118     pub(super) to: String,
    119     pub(super) amount: Amount,
    120     pub(super) fee_per_byte: Option<Amount>,
    121     #[serde(default)]
    122     pub(super) utxos: String,
    123 }
    124 
    125 #[derive(Debug, Deserialize)]
    126 pub(super) struct PeerForm {
    127     pub(super) peer: String,
    128 }
    129 
    130 #[derive(Debug, Deserialize)]
    131 pub(super) struct AddressBookForm {
    132     pub(super) address: String,
    133     pub(super) name: String,
    134     pub(super) old_address: Option<String>,
    135 }
    136 
    137 #[derive(Debug, Deserialize)]
    138 pub(super) struct AddressBookDeleteForm {
    139     pub(super) address: String,
    140 }
    141 
    142 #[derive(Debug, Deserialize)]
    143 pub(super) struct ConfigForm {
    144     pub(super) setup_complete: bool,
    145     #[serde(default)]
    146     pub(super) peer: String,
    147 }
    148 
    149 #[derive(Debug, Deserialize)]
    150 pub(super) struct SeedPhraseForm {
    151     pub(super) seed_phrase: String,
    152 }
    153 
    154 #[derive(Debug, Deserialize)]
    155 pub(super) struct BlocksQuery {
    156     pub(super) before_height: Option<u64>,
    157     pub(super) limit: Option<usize>,
    158 }
    159 
    160 #[derive(Debug, Deserialize)]
    161 pub(super) struct MetricsQuery {
    162     pub(super) limit: Option<usize>,
    163 }
    164 
    165 #[derive(Debug, Default, Deserialize)]
    166 pub(super) struct PageQuery {
    167     pub(super) offset: Option<usize>,
    168     pub(super) limit: Option<usize>,
    169 }
    170 
    171 #[derive(Debug, Default, Deserialize)]
    172 pub(super) struct WalletTransactionsQuery {
    173     pub(super) tx: Option<bool>,
    174     pub(super) mine: Option<bool>,
    175     pub(super) burn: Option<bool>,
    176     pub(super) offset: Option<usize>,
    177     pub(super) limit: Option<usize>,
    178 }
    179 
    180 impl WalletTransactionsQuery {
    181     pub(super) fn page(&self) -> PageQuery {
    182         PageQuery {
    183             offset: self.offset,
    184             limit: self.limit,
    185         }
    186     }
    187 }
    188 
    189 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
    190 pub(super) struct WalletTransactionFilters {
    191     pub(super) transfer: bool,
    192     pub(super) mine: bool,
    193     pub(super) burn: bool,
    194 }
    195 
    196 impl Default for WalletTransactionFilters {
    197     fn default() -> Self {
    198         Self {
    199             transfer: true,
    200             mine: false,
    201             burn: false,
    202         }
    203     }
    204 }
    205 
    206 impl WalletTransactionFilters {
    207     pub(super) fn from_query(query: WalletTransactionsQuery) -> Self {
    208         Self {
    209             transfer: query.tx.unwrap_or(true),
    210             mine: query.mine.unwrap_or(false),
    211             burn: query.burn.unwrap_or(false),
    212         }
    213     }
    214 
    215     pub(super) fn allows(self, transaction: &Transaction) -> bool {
    216         match transaction {
    217             Transaction::Transfer { .. } => self.transfer,
    218             Transaction::Mine { .. } => self.mine,
    219             Transaction::Burn { .. } => self.burn,
    220         }
    221     }
    222 }
    223 
    224 #[derive(Debug, Serialize)]
    225 pub(super) struct ActionResponse {
    226     pub(super) ok: bool,
    227     pub(super) error: Option<String>,
    228 }
    229 
    230 #[derive(Clone, Debug, Eq, PartialEq, Serialize)]
    231 #[serde(rename_all = "camelCase")]
    232 pub(super) struct Page<T> {
    233     pub(super) items: Vec<T>,
    234     pub(super) offset: usize,
    235     pub(super) limit: usize,
    236     pub(super) total: usize,
    237     pub(super) has_more: bool,
    238     pub(super) next_offset: Option<usize>,
    239 }
    240 
    241 #[derive(Clone, Debug, PartialEq, Serialize)]
    242 #[serde(rename_all = "camelCase")]
    243 pub(super) struct MetricsResponse {
    244     pub(super) enabled: bool,
    245     pub(super) latest: Option<BlockMetricRow>,
    246     pub(super) charts: Vec<MetricsChart>,
    247     pub(super) leaderboards: MetricsLeaderboards,
    248 }
    249 
    250 #[derive(Clone, Debug, Default, PartialEq, Serialize)]
    251 #[serde(rename_all = "camelCase")]
    252 pub(super) struct MetricsLeaderboards {
    253     pub(super) balances: Vec<LeaderboardEntry>,
    254     pub(super) miners: Vec<LeaderboardEntry>,
    255     pub(super) burners: Vec<LeaderboardEntry>,
    256 }
    257 
    258 #[derive(Clone, Debug, Eq, PartialEq, Serialize)]
    259 #[serde(rename_all = "camelCase")]
    260 pub(super) struct LeaderboardEntry {
    261     pub(super) address: String,
    262     pub(super) amount: Amount,
    263     pub(super) count: u64,
    264 }
    265 
    266 #[derive(Clone, Debug, PartialEq, Serialize)]
    267 #[serde(rename_all = "camelCase")]
    268 pub(super) struct MetricsChart {
    269     pub(super) id: &'static str,
    270     pub(super) title: &'static str,
    271     pub(super) unit: &'static str,
    272     pub(super) value_kind: MetricsValueKind,
    273     pub(super) points: Vec<MetricsPoint>,
    274 }
    275 
    276 #[derive(Clone, Debug, PartialEq, Serialize)]
    277 #[serde(rename_all = "camelCase")]
    278 pub(super) struct MetricsPoint {
    279     pub(super) height: u64,
    280     pub(super) value: f64,
    281 }
    282 
    283 #[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
    284 #[serde(rename_all = "camelCase")]
    285 pub(super) enum MetricsValueKind {
    286     Number,
    287     Seconds,
    288     Iuna,
    289 }
    290 
    291 #[derive(Debug, Serialize)]
    292 #[serde(rename_all = "camelCase")]
    293 pub(super) struct FeeEstimateResponse {
    294     pub(super) ok: bool,
    295     pub(super) error: Option<String>,
    296     pub(super) bytes: Option<usize>,
    297     pub(super) fee: Option<Amount>,
    298 }
    299 
    300 #[derive(Debug, Serialize)]
    301 pub(super) struct WalletSetupResponse {
    302     pub(super) ok: bool,
    303     pub(super) error: Option<String>,
    304     pub(super) address: Option<String>,
    305     pub(super) seed_phrase: Option<String>,
    306     pub(super) dev_verify_bypass: bool,
    307     pub(super) requires_peer: bool,
    308 }
    309 
    310 #[derive(Clone, Debug, Eq, PartialEq, Serialize)]
    311 #[serde(rename_all = "camelCase")]
    312 pub(super) struct WalletTransactionRow {
    313     pub(super) kind: &'static str,
    314     pub(super) from: String,
    315     pub(super) to: Option<String>,
    316     pub(super) amount: Amount,
    317     pub(super) fee: Amount,
    318     pub(super) inputs: Vec<UiTxInput>,
    319     pub(super) outputs: Vec<TxOutput>,
    320     pub(super) change: Vec<TxOutput>,
    321     pub(super) signature: String,
    322     pub(super) status: &'static str,
    323     pub(super) block_height: Option<u64>,
    324     pub(super) timestamp_ms: Option<u64>,
    325     pub(super) block_finalizer: Option<String>,
    326     pub(super) direction: &'static str,
    327     pub(super) blinded: bool,
    328     pub(super) difficulty_bits: Option<u32>,
    329     pub(super) proof_bits: Option<u32>,
    330     pub(super) proof_hash: Option<String>,
    331 }
    332 
    333 #[derive(Clone, Debug, Eq, PartialEq, Serialize)]
    334 #[serde(rename_all = "camelCase")]
    335 pub(super) struct WalletUtxoRow {
    336     pub(super) outpoint: OutPoint,
    337     pub(super) address: String,
    338     pub(super) amount: Amount,
    339     pub(super) spendable: bool,
    340 }
    341 
    342 #[derive(Clone, Debug)]
    343 pub(super) struct WalletTransactionContext {
    344     pub(super) status: &'static str,
    345     pub(super) block_height: Option<u64>,
    346     pub(super) timestamp_ms: Option<u64>,
    347     pub(super) block_finalizer: Option<String>,
    348     pub(super) blinded: bool,
    349 }
    350 
    351 #[derive(Clone, Debug, Eq, PartialEq, Serialize)]
    352 pub(super) struct UiBlock {
    353     pub(super) height: u64,
    354     pub(super) prev_hash: String,
    355     pub(super) timestamp_ms: u64,
    356     pub(super) miner: String,
    357     pub(super) finalizer_mode: crate::domain::FinalizerMode,
    358     pub(super) finalizer_rank: u32,
    359     pub(super) reward: Amount,
    360     pub(super) total_fees: Amount,
    361     pub(super) total_bytes: usize,
    362     pub(super) transaction_bytes: usize,
    363     pub(super) transaction_byte_breakdown: Vec<UiByteBreakdown>,
    364     pub(super) blinded_transaction_bytes: usize,
    365     pub(super) reveal_bundle_bytes: usize,
    366     pub(super) reveal_fee_penalty: UiRevealFeePenalty,
    367     pub(super) vdf_rounds: u64,
    368     pub(super) vdf_output: String,
    369     pub(super) leader_proof: Option<crate::domain::LeaderProof>,
    370     pub(super) burn_leader_ranks: Vec<BurnLeaderRank>,
    371     pub(super) transactions: Vec<UiTransaction>,
    372     pub(super) revealed_transactions: Vec<UiTransaction>,
    373     pub(super) reveal_bundles: Vec<UiRevealBundle>,
    374     pub(super) hash: String,
    375 }
    376 
    377 #[derive(Clone, Debug, Eq, PartialEq, Serialize)]
    378 pub(super) struct UiRevealFeePenalty {
    379     pub(super) reveal_lists_included: usize,
    380     pub(super) committee_size: usize,
    381     pub(super) fee_penalty: Amount,
    382 }
    383 
    384 #[derive(Clone, Debug, Eq, PartialEq, Serialize)]
    385 pub(super) struct UiByteBreakdown {
    386     pub(super) label: &'static str,
    387     pub(super) bytes: usize,
    388 }
    389 
    390 #[derive(Clone, Debug, Eq, PartialEq, Serialize)]
    391 #[serde(rename_all = "camelCase")]
    392 pub(super) struct UiRevealBundle {
    393     pub(super) slot: u8,
    394     pub(super) member: String,
    395     pub(super) hash: String,
    396     pub(super) byte_size: usize,
    397     pub(super) reveals: Vec<UiTransaction>,
    398 }
    399 
    400 #[derive(Clone, Debug, Eq, PartialEq, Serialize)]
    401 pub(super) struct UiTransaction {
    402     pub(super) kind: &'static str,
    403     pub(super) from: String,
    404     pub(super) to: Option<String>,
    405     pub(super) amount: Amount,
    406     pub(super) fee: Amount,
    407     pub(super) inputs: Vec<UiTxInput>,
    408     pub(super) outputs: Vec<TxOutput>,
    409     pub(super) change: Vec<TxOutput>,
    410     pub(super) signature: String,
    411     pub(super) difficulty_bits: Option<u32>,
    412     pub(super) proof_bits: Option<u32>,
    413     pub(super) proof_hash: Option<String>,
    414     pub(super) commitment: Option<String>,
    415     pub(super) encrypted_size: Option<u32>,
    416     pub(super) expires_at_height: Option<u64>,
    417     pub(super) revealed: bool,
    418 }
    419 
    420 #[derive(Clone, Debug, Eq, PartialEq, Serialize)]
    421 pub(super) struct UiTxInput {
    422     pub(super) outpoint: OutPoint,
    423     pub(super) owner: String,
    424     pub(super) signature: String,
    425     pub(super) amount: Option<Amount>,
    426     pub(super) address: Option<String>,
    427 }