whisky_pallas/tx_parser/
parsable.rs1use pallas::ledger::primitives::{conway::Tx, Fragment};
2use whisky_common::{TxParsable, TxTester, WError};
3
4use crate::{tx_parser::parse, WhiskyPallas};
5
6impl TxParsable for WhiskyPallas {
7 fn parse(
8 &mut self,
9 tx_hex: &str,
10 resolved_utxos: &[whisky_common::UTxO],
11 ) -> Result<(), whisky_common::WError> {
12 self.tx_builder_body = parse(tx_hex, resolved_utxos)?;
13 Ok(())
14 }
15
16 fn get_required_inputs(
17 &mut self,
18 tx_hex: &str,
19 ) -> Result<Vec<whisky_common::UtxoInput>, whisky_common::WError> {
20 let tx_bytes = hex::decode(tx_hex)
21 .map_err(|_| WError::new("get_required_inputs", "error deserialising tx_hex"))?;
22 let pallas_tx = Tx::decode_fragment(&tx_bytes)
23 .map_err(|_| WError::new("get_required_inputs", "error decoding tx fragment"))?;
24 let mut required_inputs = Vec::new();
25 for inputs in pallas_tx.transaction_body.inputs.iter() {
26 required_inputs.push(whisky_common::UtxoInput {
27 tx_hash: inputs.transaction_id.to_string(),
28 output_index: inputs.index as u32,
29 });
30 }
31 Ok(required_inputs)
32 }
33
34 fn get_builder_body(&self) -> whisky_common::TxBuilderBody {
35 self.tx_builder_body.clone()
36 }
37
38 fn get_builder_body_without_change(&self) -> whisky_common::TxBuilderBody {
39 let mut tx_body = self.tx_builder_body.clone();
40 if !tx_body.outputs.is_empty() {
41 tx_body.outputs.pop();
42 }
43 tx_body
44 }
45
46 fn to_tester(&self) -> TxTester {
47 TxTester::new(&self.tx_builder_body)
48 }
49}