use fuel_core_types::{
fuel_asm::{
op,
GTFArgs,
Instruction,
RegId,
},
fuel_tx::{
Address,
AssetId,
},
};
pub fn generate(address: Address) -> Vec<u8> {
let start_jump = vec![
op::ji((1 + (Address::LEN / Instruction::SIZE)).try_into().unwrap()),
];
let asset_id_register = 0x10;
let balance_register = 0x11;
let contract_id_register = 0x12;
let output_index_register = 0x13;
let recipient_id_register = 0x14;
let body = vec![
op::gtf_args(asset_id_register, 0x00, GTFArgs::ScriptData),
op::addi(
output_index_register,
asset_id_register,
u16::try_from(AssetId::LEN).expect("The size is 32"),
),
op::lw(output_index_register, output_index_register, 0),
op::move_(contract_id_register, RegId::FP),
op::bal(balance_register, asset_id_register, contract_id_register),
op::jnzf(balance_register, RegId::ZERO, 1),
op::ret(RegId::ONE),
op::addi(
recipient_id_register,
RegId::IS,
Instruction::SIZE.try_into().unwrap(),
),
op::tro(
recipient_id_register,
output_index_register,
balance_register,
asset_id_register,
),
op::ret(RegId::ONE),
];
let mut asm_bytes: Vec<u8> = start_jump.into_iter().collect();
asm_bytes.extend_from_slice(address.as_slice()); let body: Vec<u8> = body.into_iter().collect();
asm_bytes.extend(body.as_slice());
asm_bytes
}