koios_sdk/models/
transaction.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

use super::{
    governance::{ProposalWithdrawal, VoterRole},
    AssetItem, ProposalType, Vote,
};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionInfo {
    pub tx_hash: String,
    pub block_hash: String,
    pub block_height: u64,
    pub epoch_no: u64,
    pub epoch_slot: u64,
    pub absolute_slot: u64,
    pub tx_timestamp: u64,
    pub tx_block_index: u64,
    pub tx_size: u64,
    pub total_output: String,
    pub fee: String,
    pub treasury_donation: String,
    pub deposit: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub invalid_before: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub invalid_after: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub collateral_inputs: Option<Vec<TransactionOutput>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub collateral_output: Option<Vec<TransactionOutput>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reference_inputs: Option<Vec<TransactionOutput>>,
    pub inputs: Vec<TransactionOutput>,
    pub outputs: Vec<TransactionOutput>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub withdrawals: Option<Vec<Withdrawal>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub assets_minted: Option<Vec<AssetItem>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<HashMap<String, serde_json::Value>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub certificates: Option<Vec<Certificate>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub native_scripts: Option<Vec<NativeScript>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub plutus_contracts: Option<Vec<PlutusContract>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub voting_procedures: Option<Vec<VotingProcedure>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub proposal_procedures: Option<Vec<ProposalProcedure>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VotingProcedure {
    pub proposal_tx_hash: String,
    pub proposal_index: u64,
    pub voter_role: VoterRole,
    pub voter: String,
    pub voter_hex: String,
    pub vote: Vote,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub meta_url: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub meta_hash: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProposalProcedure {
    pub index: u64,
    #[serde(rename = "type")]
    pub proposal_type: ProposalType,
    pub description: String,
    pub deposit: String,
    pub return_address: String,
    pub expiration: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub meta_url: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub meta_hash: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub withdrawal: Option<ProposalWithdrawal>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub param_proposal: Option<serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionOutput {
    pub payment_addr: PaymentAddress,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stake_addr: Option<String>,
    pub tx_hash: String,
    pub tx_index: 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<InlineDatum>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reference_script: Option<ReferenceScript>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub asset_list: Option<Vec<AssetItem>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaymentAddress {
    pub bech32: String,
    pub cred: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InlineDatum {
    pub bytes: String,
    pub value: serde_json::Value,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReferenceScript {
    pub hash: String,
    pub size: u64,
    #[serde(rename = "type")]
    pub script_type: String,
    pub bytes: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub value: Option<serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Withdrawal {
    pub amount: String,
    pub stake_addr: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Certificate {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub index: Option<u64>,
    #[serde(rename = "type")]
    pub cert_type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub info: Option<serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NativeScript {
    pub script_hash: String,
    pub script_json: Option<serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlutusContract {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub address: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub spends_input: Option<SpendInput>,
    pub script_hash: String,
    pub bytecode: String,
    pub size: u64,
    pub valid_contract: bool,
    pub input: PlutusInput,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpendInput {
    pub tx_hash: String,
    pub tx_index: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlutusInput {
    pub redeemer: Redeemer,
    pub datum: Datum,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Redeemer {
    pub purpose: String,
    pub fee: String,
    pub unit: RedeemerUnit,
    pub datum: Datum,
}

#[derive(Debug, Clone, Serialize, Copy, Deserialize)]
pub struct RedeemerUnit {
    pub steps: u64,
    pub mem: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Datum {
    pub hash: String,
    pub value: serde_json::Value,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionCbor {
    pub tx_hash: String,
    pub block_hash: String,
    pub block_height: u64,
    pub epoch_no: u64,
    pub absolute_slot: u64,
    pub tx_timestamp: u64,
    pub cbor: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionStatus {
    pub tx_hash: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub num_confirmations: Option<u64>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionMetadata {
    pub tx_hash: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<serde_json::Value>,
}

// Implementation blocks for key types
impl TransactionInfo {
    pub fn new(
        tx_hash: String,
        block_hash: String,
        block_height: u64,
        epoch_no: u64,
        epoch_slot: u64,
        absolute_slot: u64,
        tx_timestamp: u64,
        tx_block_index: u64,
        tx_size: u64,
        total_output: String,
        fee: String,
        treasury_donation: String,
        deposit: String,
        inputs: Vec<TransactionOutput>,
        outputs: Vec<TransactionOutput>,
    ) -> Self {
        Self {
            tx_hash,
            block_hash,
            block_height,
            epoch_no,
            epoch_slot,
            absolute_slot,
            tx_timestamp,
            tx_block_index,
            tx_size,
            total_output,
            fee,
            treasury_donation,
            deposit,
            invalid_before: None,
            invalid_after: None,
            collateral_inputs: None,
            collateral_output: None,
            reference_inputs: None,
            inputs,
            outputs,
            withdrawals: None,
            assets_minted: None,
            metadata: None,
            certificates: None,
            native_scripts: None,
            plutus_contracts: None,
            voting_procedures: None,
            proposal_procedures: None,
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TxMetaLabels {
    pub key: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UtxoInfo {
    pub tx_hash: String,
    pub tx_index: u64,
    pub address: String,
    pub value: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stake_address: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub payment_cred: Option<String>,
    pub epoch_no: u64,
    pub block_height: u64,
    pub block_time: u64,
    #[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>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub asset_list: Option<Vec<AssetItem>>,
    pub is_spent: bool,
}
impl UtxoInfo {
    pub fn new(
        tx_hash: String,
        tx_index: u64,
        address: String,
        value: String,
        epoch_no: u64,
        block_height: u64,
        block_time: u64,
        is_spent: bool,
    ) -> Self {
        Self {
            tx_hash,
            tx_index,
            address,
            value,
            stake_address: None,
            payment_cred: None,
            epoch_no,
            block_height,
            block_time,
            datum_hash: None,
            inline_datum: None,
            reference_script: None,
            asset_list: None,
            is_spent,
        }
    }
}