koios_sdk/models/
script.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct ScriptInfo {
5    #[serde(skip_serializing_if = "Option::is_none")]
6    pub script_hash: Option<String>,
7    pub creation_tx_hash: String,
8    #[serde(rename = "type")]
9    pub script_type: ScriptType,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub value: Option<serde_json::Value>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub bytes: Option<String>,
14    pub size: u64,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize, Copy, PartialEq)]
18#[serde(rename_all = "lowercase")]
19pub enum ScriptType {
20    PlutusV1,
21    PlutusV2,
22    Timelock,
23    Multisig,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct ScriptRedeemer {
28    pub script_hash: String,
29    pub redeemers: Vec<RedeemerData>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct RedeemerData {
34    pub tx_hash: String,
35    pub tx_index: u64,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub unit_mem: Option<RedeemerUnitValue>,
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub unit_steps: Option<RedeemerUnitValue>,
40    pub fee: String,
41    pub purpose: RedeemerPurpose,
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub datum_hash: Option<String>,
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub datum_value: Option<serde_json::Value>,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum RedeemerUnitValue {
51    String(String),
52    Number(u64),
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize, Copy, PartialEq)]
56#[serde(rename_all = "lowercase")]
57pub enum RedeemerPurpose {
58    Spend,
59    Mint,
60    Cert,
61    Reward,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct DatumInfo {
66    pub datum_hash: String,
67    pub creation_tx_hash: String,
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub value: Option<serde_json::Value>,
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub bytes: Option<String>,
72}
73
74// Implementation blocks for key types
75impl ScriptInfo {
76    pub fn new(creation_tx_hash: String, script_type: ScriptType, size: u64) -> Self {
77        Self {
78            script_hash: None,
79            creation_tx_hash,
80            script_type,
81            value: None,
82            bytes: None,
83            size,
84        }
85    }
86}
87
88impl ScriptRedeemer {
89    pub fn new(script_hash: String) -> Self {
90        Self {
91            script_hash,
92            redeemers: Vec::new(),
93        }
94    }
95}
96
97impl RedeemerData {
98    pub fn new(tx_hash: String, tx_index: u64, fee: String, purpose: RedeemerPurpose) -> Self {
99        Self {
100            tx_hash,
101            tx_index,
102            unit_mem: None,
103            unit_steps: None,
104            fee,
105            purpose,
106            datum_hash: None,
107            datum_value: None,
108        }
109    }
110}
111
112impl DatumInfo {
113    pub fn new(datum_hash: String, creation_tx_hash: String) -> Self {
114        Self {
115            datum_hash,
116            creation_tx_hash,
117            value: None,
118            bytes: None,
119        }
120    }
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct ScriptList {
125    pub script_hash: String,
126    pub creation_tx_hash: String,
127    #[serde(rename = "type")]
128    pub script_type: ScriptType,
129    pub size: u64,
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
133pub struct TxUtxos {
134    pub tx_hash: String,
135    pub inputs: Vec<UtxoDetail>,
136    pub outputs: Vec<UtxoDetail>,
137}
138
139#[derive(Debug, Clone, Serialize, Deserialize)]
140pub struct UtxoDetail {
141    pub payment_addr: PaymentAddr,
142    #[serde(skip_serializing_if = "Option::is_none")]
143    pub stake_addr: Option<String>,
144    pub tx_hash: String,
145    pub tx_index: u64,
146    pub value: String,
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize)]
150pub struct PaymentAddr {
151    pub bech32: String,
152    pub cred: String,
153}
154
155// Implementation blocks
156impl ScriptList {
157    pub fn new(
158        script_hash: String,
159        creation_tx_hash: String,
160        script_type: ScriptType,
161        size: u64,
162    ) -> Self {
163        Self {
164            script_hash,
165            creation_tx_hash,
166            script_type,
167            size,
168        }
169    }
170}
171
172impl TxUtxos {
173    pub fn new(tx_hash: String) -> Self {
174        Self {
175            tx_hash,
176            inputs: Vec::new(),
177            outputs: Vec::new(),
178        }
179    }
180}