koios_sdk/models/
address.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
use serde::{Deserialize, Serialize};

use super::AssetItem;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddressInfo {
    pub address: String,
    pub balance: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stake_address: Option<String>,
    pub script_address: bool,
    pub utxo_set: Vec<AddressUtxo>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddressUtxo {
    pub tx_hash: String,
    pub tx_index: u64,
    pub block_height: u64,
    pub block_time: u64,
    pub value: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub datum_hash: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inline_datum: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reference_script: Option<serde_json::Value>,
    pub asset_list: Vec<AssetItem>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddressTransaction {
    pub tx_hash: String,
    pub epoch_no: u64,
    pub block_height: u64,
    pub block_time: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddressAsset {
    pub address: String,
    pub policy_id: String,
    pub asset_name: String,
    pub fingerprint: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub decimals: Option<u64>,
    pub quantity: String,
}

// Implementation blocks for constructors and utility methods
impl AddressInfo {
    pub fn new(
        address: String,
        balance: String,
        stake_address: Option<String>,
        script_address: bool,
    ) -> Self {
        Self {
            address,
            balance,
            stake_address,
            script_address,
            utxo_set: Vec::new(),
        }
    }
}

impl AddressUtxo {
    pub fn new(
        tx_hash: String,
        tx_index: u64,
        block_height: u64,
        block_time: u64,
        value: String,
    ) -> Self {
        Self {
            tx_hash,
            tx_index,
            block_height,
            block_time,
            value,
            datum_hash: None,
            inline_datum: None,
            reference_script: None,
            asset_list: Vec::new(),
        }
    }
}

impl AssetItem {
    pub fn new(
        policy_id: String,
        asset_name: String,
        fingerprint: String,
        quantity: String,
    ) -> Self {
        Self {
            policy_id,
            asset_name,
            fingerprint,
            decimals: None,
            quantity,
        }
    }
}

impl AddressTransaction {
    pub fn new(tx_hash: String, epoch_no: u64, block_height: u64, block_time: u64) -> Self {
        Self {
            tx_hash,
            epoch_no,
            block_height,
            block_time,
        }
    }
}