whisky_provider/blockfrost/utils/
transaction_utils.rs1use whisky_common::{TransactionInfo, UTxO};
2
3use crate::blockfrost::models::{BlockfrostTxInfo, BlockfrostTxUtxoOutputs, BlockfrostUtxo};
4
5pub fn blockfrost_txinfo_to_txinfo(
6 blockfrost_tx_info: BlockfrostTxInfo,
7 inputs: Vec<UTxO>,
8 outputs: Vec<UTxO>,
9) -> TransactionInfo {
10 TransactionInfo {
11 index: blockfrost_tx_info.index as u32,
12 block: blockfrost_tx_info.block,
13 hash: blockfrost_tx_info.hash,
14 slot: blockfrost_tx_info.slot.to_string(),
15 fees: blockfrost_tx_info.fees,
16 size: blockfrost_tx_info.size as u32,
17 deposit: blockfrost_tx_info.deposit,
18 invalid_before: blockfrost_tx_info.invalid_before.unwrap_or("".to_string()),
19 invalid_after: blockfrost_tx_info
20 .invalid_hereafter
21 .unwrap_or("".to_string()),
22 inputs,
23 outputs,
24 block_height: Some(blockfrost_tx_info.block_height as u32),
25 block_time: Some(blockfrost_tx_info.block_time as u64),
26 }
27}
28
29pub fn blockfrost_tx_output_utxo_to_blockfrost_utxo(
30 utxo: &BlockfrostTxUtxoOutputs,
31 tx_hash: &str,
32) -> BlockfrostUtxo {
33 BlockfrostUtxo {
34 address: utxo.address.clone(),
35 tx_hash: tx_hash.to_string(),
36 tx_index: utxo.output_index,
37 output_index: utxo.output_index,
38 amount: utxo.amount.clone(),
39 block: "".to_string(),
40 data_hash: utxo.data_hash.clone(),
41 inline_datum: utxo.inline_datum.clone(),
42 reference_script_hash: utxo.reference_script_hash.clone(),
43 }
44}