use fuel_asm::Instruction;
use fuel_tx::{
field::{Salt, Script},
Bytes32, ConsensusParameters, InputRepr,
};
use fuel_types::{bytes::padded_len_usize, ContractId};
pub fn base_offset_script(consensus_parameters: &ConsensusParameters) -> usize {
consensus_parameters.tx_offset() + fuel_tx::Script::script_offset_static()
}
pub fn base_offset_create(consensus_parameters: &ConsensusParameters) -> usize {
consensus_parameters.tx_offset() + fuel_tx::Create::salt_offset_static() + Bytes32::LEN
}
pub fn call_script_data_offset(
consensus_parameters: &ConsensusParameters,
calls_instructions_len: usize,
) -> usize {
let opcode_len = Instruction::SIZE;
base_offset_script(consensus_parameters) + padded_len_usize(calls_instructions_len + opcode_len)
}
pub fn coin_predicate_data_offset(code_len: usize) -> usize {
InputRepr::Coin
.coin_predicate_offset()
.expect("should have predicate offset")
+ padded_len_usize(code_len)
}
pub fn message_predicate_data_offset(message_data_len: usize, code_len: usize) -> usize {
InputRepr::Message
.data_offset()
.expect("should have data offset")
+ padded_len_usize(message_data_len)
+ padded_len_usize(code_len)
}
pub fn coin_signed_data_offset() -> usize {
InputRepr::Coin
.coin_predicate_offset()
.expect("should have coin offset")
}
pub fn message_signed_data_offset(message_data_len: usize) -> usize {
InputRepr::Message
.data_offset()
.expect("should have data offset")
+ padded_len_usize(message_data_len)
}
pub fn contract_input_offset() -> usize {
InputRepr::Contract.contract_id_offset().unwrap() + ContractId::LEN
}