use crate::{error, types::errors::Result};
use fuel_asm::Instruction;
use fuel_tx::{field::Script, ConsensusParameters};
use fuel_types::bytes::padded_len_usize;
pub fn base_offset_script(consensus_parameters: &ConsensusParameters) -> usize {
consensus_parameters.tx_params().tx_offset() + fuel_tx::Script::script_offset_static()
}
pub fn call_script_data_offset(
consensus_parameters: &ConsensusParameters,
calls_instructions_len: usize,
) -> Result<usize> {
let opcode_len = Instruction::SIZE;
let padded_len = padded_len_usize(calls_instructions_len + opcode_len).ok_or_else(|| {
error!(
Other,
"call script data len overflow: {calls_instructions_len}"
)
})?;
Ok(base_offset_script(consensus_parameters) + padded_len)
}