Skip to main content

avalanche_rs/avm/parser/
transferable_output_parser.rs

1use rust_base58::ToBase58;
2use tracing::{instrument, trace};
3
4use std::error::Error;
5
6use crate::avm::parser::output_parser::{output_parser, Output};
7use crate::avm::parser::Context;
8use crate::utils::cb58::encode;
9
10#[derive(Serialize, Deserialize, Debug)]
11pub struct TransferableOutput {
12    pub asset_id: String,
13    pub output: Output,
14}
15
16#[instrument(skip(_raw_msg), fields(tx_id = %_context.tx_id))]
17pub fn transferable_output_parser<'a>(
18    _raw_msg: &[u8],
19    _context: &mut Context,
20) -> Result<TransferableOutput, Box<dyn Error>> {
21    // Asset Id
22    let asset_id = encode(&_raw_msg[*_context.offset..=(*_context.offset + 31)].to_vec());
23    trace!(
24        "{} \n TransferableOutput -- AssetID : {:?} \n +++++++",
25        _context.tx_id,
26        asset_id
27    );
28    *_context.offset += 32;
29
30    let output = output_parser(_raw_msg, _context);
31
32    Ok(TransferableOutput {
33        asset_id: asset_id.to_base58(),
34        output: output?,
35    })
36}