From 57550ef4c2ec962fcba945415fcb6a56e9fa9ba9 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Wed, 13 Nov 2024 20:45:54 +0900 Subject: [PATCH] remove redundant pub crate --- .../src/assembly/contract_call.rs | 14 ++++------- .../fuels-programs/src/assembly/cursor.rs | 4 ++-- .../assembly/script_and_predicate_loader.rs | 10 ++++---- packages/fuels-programs/src/lib.rs | 23 +------------------ packages/fuels-programs/src/utils.rs | 19 +++++++++++++++ 5 files changed, 31 insertions(+), 39 deletions(-) create mode 100644 packages/fuels-programs/src/utils.rs diff --git a/packages/fuels-programs/src/assembly/contract_call.rs b/packages/fuels-programs/src/assembly/contract_call.rs index 361d37b9b..f5624f632 100644 --- a/packages/fuels-programs/src/assembly/contract_call.rs +++ b/packages/fuels-programs/src/assembly/contract_call.rs @@ -3,7 +3,7 @@ use fuel_tx::{AssetId, ContractId}; use fuels_core::{constants::WORD_SIZE, error, types::errors::Result}; use super::cursor::WasmFriendlyCursor; -pub(crate) struct ContractCallInstructions { +pub struct ContractCallInstructions { instructions: Vec, gas_fwd: bool, } @@ -102,7 +102,7 @@ impl ContractCallInstructions { Self::extract_if_match(instructions, &gas_fwd_instructions) } - pub(crate) fn extract_from(instructions: &[Instruction]) -> Option { + pub fn extract_from(instructions: &[Instruction]) -> Option { if let Some(instructions) = Self::extract_normal_variant(instructions) { return Some(Self { instructions: instructions.to_vec(), @@ -128,7 +128,7 @@ impl ContractCallInstructions { movi.imm18().into() } - pub(crate) fn is_gas_fwd_variant(&self) -> bool { + pub fn is_gas_fwd_variant(&self) -> bool { self.gas_fwd } @@ -173,11 +173,7 @@ impl ContractCallData { /// 6. Encoded function selector - method name /// 7. Encoded arguments /// 8. Gas to be forwarded `(1 * `[`WORD_SIZE`]`)` - Optional - pub(crate) fn encode( - &self, - memory_offset: usize, - buffer: &mut Vec, - ) -> CallOpcodeParamsOffset { + pub fn encode(&self, memory_offset: usize, buffer: &mut Vec) -> CallOpcodeParamsOffset { let amount_offset = memory_offset; let asset_id_offset = amount_offset + WORD_SIZE; let call_data_offset = asset_id_offset + AssetId::LEN; @@ -262,7 +258,7 @@ impl ContractCallData { #[derive(Default)] /// Specifies offsets of [`Opcode::CALL`][`fuel_asm::Opcode::CALL`] parameters stored in the script /// data from which they can be loaded into registers -pub(crate) struct CallOpcodeParamsOffset { +pub struct CallOpcodeParamsOffset { pub call_data_offset: usize, pub amount_offset: usize, pub asset_id_offset: usize, diff --git a/packages/fuels-programs/src/assembly/cursor.rs b/packages/fuels-programs/src/assembly/cursor.rs index a0077ebc3..c5cb4cfa7 100644 --- a/packages/fuels-programs/src/assembly/cursor.rs +++ b/packages/fuels-programs/src/assembly/cursor.rs @@ -1,7 +1,7 @@ use fuels_core::{error, types::errors::Result}; -pub(crate) struct WasmFriendlyCursor<'a> { - pub(crate) data: &'a [u8], +pub struct WasmFriendlyCursor<'a> { + data: &'a [u8], } impl<'a> WasmFriendlyCursor<'a> { diff --git a/packages/fuels-programs/src/assembly/script_and_predicate_loader.rs b/packages/fuels-programs/src/assembly/script_and_predicate_loader.rs index 3f6c5a553..23223ca29 100644 --- a/packages/fuels-programs/src/assembly/script_and_predicate_loader.rs +++ b/packages/fuels-programs/src/assembly/script_and_predicate_loader.rs @@ -1,5 +1,3 @@ -use fuels_core::error; - use fuel_asm::{op, Instruction, RegId}; use fuels_core::{ constants::WORD_SIZE, @@ -124,7 +122,7 @@ impl LoaderCode { } } -pub(crate) fn loader_instructions_no_data_section() -> [Instruction; 8] { +pub fn loader_instructions_no_data_section() -> [Instruction; 8] { const REG_ADDRESS_OF_DATA_AFTER_CODE: u8 = 0x10; const REG_START_OF_LOADED_CODE: u8 = 0x11; const REG_GENERAL_USE: u8 = 0x12; @@ -170,7 +168,7 @@ pub(crate) fn loader_instructions_no_data_section() -> [Instruction; 8] { instructions } -pub(crate) fn loader_instructions() -> [Instruction; 12] { +pub fn loader_instructions() -> [Instruction; 12] { const BLOB_ID_SIZE: u16 = 32; const REG_ADDRESS_OF_DATA_AFTER_CODE: u8 = 0x10; const REG_START_OF_LOADED_CODE: u8 = 0x11; @@ -236,7 +234,7 @@ pub(crate) fn loader_instructions() -> [Instruction; 12] { instructions } -pub(crate) fn extract_data_offset(binary: &[u8]) -> Result { +pub fn extract_data_offset(binary: &[u8]) -> Result { if binary.len() < 16 { return Err(fuels_core::error!( Other, @@ -250,7 +248,7 @@ pub(crate) fn extract_data_offset(binary: &[u8]) -> Result { Ok(u64::from_be_bytes(data_offset) as usize) } -pub(crate) fn split_at_data_offset(binary: &[u8]) -> Result<(&[u8], &[u8])> { +pub fn split_at_data_offset(binary: &[u8]) -> Result<(&[u8], &[u8])> { let offset = extract_data_offset(binary)?; if binary.len() < offset { return Err(fuels_core::error!( diff --git a/packages/fuels-programs/src/lib.rs b/packages/fuels-programs/src/lib.rs index cc1a64516..77ef51275 100644 --- a/packages/fuels-programs/src/lib.rs +++ b/packages/fuels-programs/src/lib.rs @@ -10,25 +10,4 @@ pub mod responses; pub mod debug; pub(crate) mod assembly; - -pub(crate) mod utils { - use fuels_core::types::errors::{error, Error}; - - pub fn prepend_msg<'a>(msg: impl AsRef + 'a) -> impl Fn(Error) -> Error + 'a { - move |err| match err { - Error::IO(orig_msg) => { - error!(IO, "{}: {}", msg.as_ref(), orig_msg) - } - Error::Codec(orig_msg) => { - error!(Codec, "{}: {}", msg.as_ref(), orig_msg) - } - Error::Transaction(reason) => Error::Transaction(reason), - Error::Provider(orig_msg) => { - error!(Provider, "{}: {}", msg.as_ref(), orig_msg) - } - Error::Other(orig_msg) => { - error!(Other, "{}: {}", msg.as_ref(), orig_msg) - } - } - } -} +pub(crate) mod utils; diff --git a/packages/fuels-programs/src/utils.rs b/packages/fuels-programs/src/utils.rs new file mode 100644 index 000000000..cdee3d31d --- /dev/null +++ b/packages/fuels-programs/src/utils.rs @@ -0,0 +1,19 @@ +use fuels_core::types::errors::{error, Error}; + +pub fn prepend_msg<'a>(msg: impl AsRef + 'a) -> impl Fn(Error) -> Error + 'a { + move |err| match err { + Error::IO(orig_msg) => { + error!(IO, "{}: {}", msg.as_ref(), orig_msg) + } + Error::Codec(orig_msg) => { + error!(Codec, "{}: {}", msg.as_ref(), orig_msg) + } + Error::Transaction(reason) => Error::Transaction(reason), + Error::Provider(orig_msg) => { + error!(Provider, "{}: {}", msg.as_ref(), orig_msg) + } + Error::Other(orig_msg) => { + error!(Other, "{}: {}", msg.as_ref(), orig_msg) + } + } +}