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
use crate::*;
use super::{TxBuilder, WData};
impl TxBuilder {
/// ## Transaction building method
///
/// Add a transaction output to the TxBuilder instance
///
/// ### Arguments
///
/// * `address` - The address
/// * `amount` - The amount of assets
///
/// ### Returns
///
/// * `Self` - The TxBuilder instance
pub fn tx_out(&mut self, address: &str, amount: &[Asset]) -> &mut Self {
if self.tx_output.is_some() {
let tx_output = self.tx_output.take();
self.tx_builder_body.outputs.push(tx_output.unwrap());
}
self.tx_output = Some(Output {
address: address.to_string(),
amount: amount.to_vec(),
datum: None,
reference_script: None,
});
self
}
/// ## Transaction building method
///
/// Set the transaction output datum hash value in the TxBuilder instance
///
/// ### Arguments
///
/// * `data` - The datum hash value
///
/// ### Returns
///
/// * `Self` - The TxBuilder instance
pub fn tx_out_datum_hash_value(&mut self, data: &WData) -> &mut Self {
let tx_output = self.tx_output.take();
if tx_output.is_none() {
panic!("Undefined output")
}
let mut tx_output = tx_output.unwrap();
match data.to_cbor() {
Ok(raw_data) => {
tx_output.datum = Some(Datum::Hash(raw_data));
self.tx_output = Some(tx_output);
}
Err(_) => {
panic!("Error converting datum to CBOR");
}
}
self
}
/// ## Transaction building method
///
/// Set the transaction output embedded datum value in the TxBuilder instance
///
/// ### Arguments
///
/// * `data` - The embedded datum value
///
/// ### Returns
///
/// * `Self` - The TxBuilder instance
pub fn tx_out_datum_embed_value(&mut self, data: &WData) -> &mut Self {
let tx_output = self.tx_output.take();
if tx_output.is_none() {
panic!("Undefined output")
}
let mut tx_output = tx_output.unwrap();
match data.to_cbor() {
Ok(raw_data) => {
tx_output.datum = Some(Datum::Embedded(raw_data));
self.tx_output = Some(tx_output);
}
Err(_) => {
panic!("Error converting datum to CBOR");
}
}
self
}
/// ## Transaction building method
///
/// Set the transaction output inline datum value in the TxBuilder instance
///
/// ### Arguments
///
/// * `data` - The inline datum value
///
/// ### Returns
///
/// * `Self` - The TxBuilder instance
pub fn tx_out_inline_datum_value(&mut self, data: &WData) -> &mut Self {
let tx_output = self.tx_output.take();
if tx_output.is_none() {
panic!("Undefined output")
}
let mut tx_output = tx_output.unwrap();
match data.to_cbor() {
Ok(raw_data) => {
tx_output.datum = Some(Datum::Inline(raw_data));
self.tx_output = Some(tx_output);
}
Err(_) => {
panic!("Error converting datum to CBOR");
}
}
self
}
/// ## Transaction building method
///
/// Add a transaction output reference script to the TxBuilder instance
///
/// ### Arguments
///
/// * `script_cbor` - The script in CBOR format
/// * `version` - The language version, if the language version is None, the script is assumed to be a Native Script
///
/// ### Returns
///
/// * `Self` - The TxBuilder instance
pub fn tx_out_reference_script(
&mut self,
script_cbor: &str,
version: Option<LanguageVersion>,
) -> &mut Self {
let tx_output = self.tx_output.take();
if tx_output.is_none() {
panic!("Undefined output")
}
let mut tx_output = tx_output.unwrap();
match version {
Some(language_version) => {
tx_output.reference_script = Some(OutputScriptSource::ProvidedScriptSource(
ProvidedScriptSource {
script_cbor: script_cbor.to_string(),
language_version,
},
));
}
None => {
tx_output.reference_script = Some(OutputScriptSource::ProvidedSimpleScriptSource(
ProvidedSimpleScriptSource {
script_cbor: script_cbor.to_string(),
},
))
}
}
self.tx_output = Some(tx_output);
self
}
}