avalanche_rs/pvm/parser/
transferable_input_parser.rs1use rust_base58::ToBase58;
2use tracing::{instrument, trace};
3
4use std::borrow::Borrow;
5
6use crate::avm::parser::Context;
7use crate::pvm::parser::input_parser::{input_parser, Input};
8use crate::utils::cb58::encode;
9use crate::utils::conversion::pop_i32;
10use std::error::Error;
11
12#[derive(Serialize, Deserialize, Debug)]
13pub struct TransferableInput {
14 pub tx_id: String,
15 pub utxo_index: i32,
16 pub asset_id: String,
17 pub input: Input,
18}
19
20#[instrument(skip(_raw_msg), fields(tx_id = %_context.tx_id))]
21pub fn transferable_input_parser<'a>(
22 _raw_msg: &'a [u8],
23 _context: &mut Context,
24) -> Result<TransferableInput, Box<dyn Error>> {
25 let tx_id = encode(&_raw_msg[*_context.offset..=(*_context.offset + 31)]).to_base58();
27 trace!("TxId : {:?}", tx_id);
28 *_context.offset += 32;
29
30 let utxo_index = pop_i32(_raw_msg[*_context.offset..=(*_context.offset + 3)].borrow());
32 trace!("UTXO Index : {:?}", utxo_index);
33 *_context.offset += 4;
34
35 let asset_id = encode(&_raw_msg[*_context.offset..=(*_context.offset + 31)]).to_base58();
37 trace!("AssetID : {:?}", asset_id);
38 *_context.offset += 32;
39
40 let input = input_parser(_raw_msg, _context)?;
41
42 Ok(TransferableInput {
43 tx_id,
44 utxo_index,
45 asset_id,
46 input,
47 })
48}