sidan_csl_rs/model/tx_builder_types/
tx_in.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
use serde::{Deserialize, Serialize};

use crate::model::{Asset, Redeemer};

use super::{
    DatumSource, InlineSimpleScriptSource, ProvidedSimpleScriptSource, ScriptSource, UTxO,
    UtxoInput, UtxoOutput,
};

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum TxIn {
    PubKeyTxIn(PubKeyTxIn),
    SimpleScriptTxIn(SimpleScriptTxIn),
    ScriptTxIn(ScriptTxIn),
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RefTxIn {
    pub tx_hash: String,
    pub tx_index: u32,
    pub script_size: Option<usize>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PubKeyTxIn {
    pub tx_in: TxInParameter,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SimpleScriptTxIn {
    pub tx_in: TxInParameter,
    pub simple_script_tx_in: SimpleScriptTxInParameter,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum SimpleScriptTxInParameter {
    ProvidedSimpleScriptSource(ProvidedSimpleScriptSource),
    InlineSimpleScriptSource(InlineSimpleScriptSource),
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ScriptTxIn {
    pub tx_in: TxInParameter,
    pub script_tx_in: ScriptTxInParameter,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TxInParameter {
    pub tx_hash: String,
    pub tx_index: u32,
    pub amount: Option<Vec<Asset>>,
    pub address: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ScriptTxInParameter {
    pub script_source: Option<ScriptSource>,
    pub datum_source: Option<DatumSource>,
    pub redeemer: Option<Redeemer>,
}

impl TxIn {
    pub fn to_utxo(&self) -> UTxO {
        match self {
            TxIn::PubKeyTxIn(pub_key_tx_in) => UTxO {
                input: UtxoInput {
                    output_index: pub_key_tx_in.tx_in.tx_index,
                    tx_hash: pub_key_tx_in.tx_in.tx_hash.clone(),
                },
                output: UtxoOutput {
                    address: pub_key_tx_in.tx_in.address.clone().unwrap(),
                    amount: pub_key_tx_in.tx_in.amount.clone().unwrap(),
                    data_hash: None,
                    plutus_data: None,
                    script_ref: None,
                    script_hash: None,
                },
            },
            TxIn::SimpleScriptTxIn(simple_script_tx_in) => UTxO {
                input: UtxoInput {
                    output_index: simple_script_tx_in.tx_in.tx_index,
                    tx_hash: simple_script_tx_in.tx_in.tx_hash.clone(),
                },
                output: UtxoOutput {
                    address: simple_script_tx_in.tx_in.address.clone().unwrap(),
                    amount: simple_script_tx_in.tx_in.amount.clone().unwrap(),
                    data_hash: None,
                    plutus_data: None,
                    script_ref: None,
                    script_hash: None,
                },
            },
            TxIn::ScriptTxIn(script_tx_in) => UTxO {
                input: UtxoInput {
                    output_index: script_tx_in.tx_in.tx_index,
                    tx_hash: script_tx_in.tx_in.tx_hash.clone(),
                },
                output: UtxoOutput {
                    address: script_tx_in.tx_in.address.clone().unwrap(),
                    amount: script_tx_in.tx_in.amount.clone().unwrap(),
                    data_hash: None,
                    plutus_data: None,
                    script_ref: None,
                    script_hash: None,
                },
            },
        }
    }
}