diff --git a/.github/workflows/checks-quick.yml b/.github/workflows/checks-quick.yml index ff88fa6ff9f72..71b00dbfb55e3 100644 --- a/.github/workflows/checks-quick.yml +++ b/.github/workflows/checks-quick.yml @@ -102,7 +102,6 @@ jobs: --exclude "substrate/frame/contracts/fixtures/build" "substrate/frame/contracts/fixtures/contracts/common" - "substrate/frame/revive/fixtures/contracts/common" - name: deny git deps run: python3 .github/scripts/deny-git-deps.py . check-markdown: diff --git a/Cargo.lock b/Cargo.lock index af2076874f12e..bfa7949ebf275 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12924,6 +12924,8 @@ name = "pallet-revive-fixtures" version = "0.1.0" dependencies = [ "anyhow", + "cargo_metadata", + "pallet-revive-uapi", "polkavm-linker 0.21.0", "sp-core 28.0.0", "sp-io 30.0.0", diff --git a/prdoc/pr_7844.prdoc b/prdoc/pr_7844.prdoc new file mode 100644 index 0000000000000..62901e7fd14dd --- /dev/null +++ b/prdoc/pr_7844.prdoc @@ -0,0 +1,13 @@ +title: '[pallet-revive] Update fixture build script' +doc: +- audience: Runtime Dev + description: |- + Update the fixture build script so that it can be built from crates.io registry +crates: +- name: pallet-revive-uapi + bump: patch +- name: pallet-revive-fixtures + bump: patch +- name: pallet-revive-eth-rpc + bump: patch + diff --git a/substrate/frame/revive/fixtures/Cargo.toml b/substrate/frame/revive/fixtures/Cargo.toml index ab5030b4a09b7..6075d9f8fb0a0 100644 --- a/substrate/frame/revive/fixtures/Cargo.toml +++ b/substrate/frame/revive/fixtures/Cargo.toml @@ -22,6 +22,8 @@ sp-io = { workspace = true, default-features = true, optional = true } [build-dependencies] anyhow = { workspace = true, default-features = true } +cargo_metadata = { workspace = true } +pallet-revive-uapi = { workspace = true } polkavm-linker = { version = "0.21.0" } toml = { workspace = true } diff --git a/substrate/frame/revive/fixtures/build.rs b/substrate/frame/revive/fixtures/build.rs index 38d3b6439ec0e..969d4bd2aa4f3 100644 --- a/substrate/frame/revive/fixtures/build.rs +++ b/substrate/frame/revive/fixtures/build.rs @@ -16,9 +16,8 @@ // limitations under the License. //! Compile text fixtures to PolkaVM binaries. -use anyhow::Result; - -use anyhow::{bail, Context}; +use anyhow::{bail, Context, Result}; +use cargo_metadata::MetadataCommand; use std::{ env, fs, io::Write, @@ -84,14 +83,32 @@ fn create_cargo_toml<'a>( output_dir: &Path, ) -> Result<()> { let mut cargo_toml: toml::Value = toml::from_str(include_str!("./build/_Cargo.toml"))?; - let mut set_dep = |name, path| -> Result<()> { - cargo_toml["dependencies"][name]["path"] = toml::Value::String( - fixtures_dir.join(path).canonicalize()?.to_str().unwrap().to_string(), + let uapi_dep = cargo_toml["dependencies"]["uapi"].as_table_mut().unwrap(); + + let metadata = MetadataCommand::new() + .manifest_path(fixtures_dir.join("Cargo.toml")) + .exec() + .expect("Failed to fetch cargo metadata"); + + let mut uapi_pkgs: Vec<_> = metadata + .packages + .iter() + .filter(|pkg| pkg.name == "pallet-revive-uapi") + .collect(); + + uapi_pkgs.sort_by(|a, b| b.version.cmp(&a.version)); + let uapi_pkg = uapi_pkgs.first().unwrap(); + + if uapi_pkg.source.is_none() { + uapi_dep.insert( + "path".to_string(), + toml::Value::String( + fixtures_dir.join("../uapi").canonicalize()?.to_str().unwrap().to_string(), + ), ); - Ok(()) - }; - set_dep("uapi", "../uapi")?; - set_dep("common", "./contracts/common")?; + } else { + uapi_dep.insert("version".to_string(), toml::Value::String(uapi_pkg.version.to_string())); + } cargo_toml["bin"] = toml::Value::Array( entries diff --git a/substrate/frame/revive/fixtures/build/_Cargo.toml b/substrate/frame/revive/fixtures/build/_Cargo.toml index a5d505e066e5c..52108d8bcaf95 100644 --- a/substrate/frame/revive/fixtures/build/_Cargo.toml +++ b/substrate/frame/revive/fixtures/build/_Cargo.toml @@ -12,8 +12,7 @@ edition = "2021" # All paths are injected dynamically by the build script. [dependencies] -uapi = { package = 'pallet-revive-uapi', path = "", features = ["unstable-hostfn"], default-features = false } -common = { package = 'pallet-revive-fixtures-common', path = "" } +uapi = { package = 'pallet-revive-uapi', features = ["unstable-hostfn"], default-features = false } hex-literal = { version = "0.4.1", default-features = false } polkavm-derive = { version = "0.21.0" } diff --git a/substrate/frame/revive/fixtures/contracts/balance.rs b/substrate/frame/revive/fixtures/contracts/balance.rs index 4606135d9807a..4247079919a4d 100644 --- a/substrate/frame/revive/fixtures/contracts/balance.rs +++ b/substrate/frame/revive/fixtures/contracts/balance.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::u64_output; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{u64_output, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/balance_of.rs b/substrate/frame/revive/fixtures/contracts/balance_of.rs index 1f94d3e506c93..706ba0fcfe3d0 100644 --- a/substrate/frame/revive/fixtures/contracts/balance_of.rs +++ b/substrate/frame/revive/fixtures/contracts/balance_of.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::{input, u64_output}; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, u64_output, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/base_fee.rs b/substrate/frame/revive/fixtures/contracts/base_fee.rs index 157909463ee41..dbb2bd79f130d 100644 --- a/substrate/frame/revive/fixtures/contracts/base_fee.rs +++ b/substrate/frame/revive/fixtures/contracts/base_fee.rs @@ -19,8 +19,8 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; use uapi::{HostFn, HostFnImpl as api, ReturnFlags}; #[no_mangle] diff --git a/substrate/frame/revive/fixtures/contracts/basic_block.rs b/substrate/frame/revive/fixtures/contracts/basic_block.rs index 0cde7a264632a..4fd50f0f709f8 100644 --- a/substrate/frame/revive/fixtures/contracts/basic_block.rs +++ b/substrate/frame/revive/fixtures/contracts/basic_block.rs @@ -19,8 +19,7 @@ #![no_std] #![no_main] - -extern crate common; +include!("../panic_handler.rs"); use core::arch::asm; diff --git a/substrate/frame/revive/fixtures/contracts/block_author.rs b/substrate/frame/revive/fixtures/contracts/block_author.rs index 59886a19cc619..a7e0364dfcc86 100644 --- a/substrate/frame/revive/fixtures/contracts/block_author.rs +++ b/substrate/frame/revive/fixtures/contracts/block_author.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/block_hash.rs b/substrate/frame/revive/fixtures/contracts/block_hash.rs index 1331c46014637..948f2e5d42910 100644 --- a/substrate/frame/revive/fixtures/contracts/block_hash.rs +++ b/substrate/frame/revive/fixtures/contracts/block_hash.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/call.rs b/substrate/frame/revive/fixtures/contracts/call.rs index 7c4c0882c6b87..1feb5875a80ef 100644 --- a/substrate/frame/revive/fixtures/contracts/call.rs +++ b/substrate/frame/revive/fixtures/contracts/call.rs @@ -18,9 +18,9 @@ //! This calls another contract as passed as its account id. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/call_and_return.rs b/substrate/frame/revive/fixtures/contracts/call_and_return.rs index 3fc16fc16706b..36c9ee850cb04 100644 --- a/substrate/frame/revive/fixtures/contracts/call_and_return.rs +++ b/substrate/frame/revive/fixtures/contracts/call_and_return.rs @@ -18,9 +18,9 @@ //! This calls another contract as passed as its account id. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::{input, u256_bytes}; -use uapi::{HostFn, HostFnImpl as api, ReturnErrorCode, ReturnFlags}; +use uapi::{input, u256_bytes, HostFn, HostFnImpl as api, ReturnErrorCode, ReturnFlags}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/call_data_copy.rs b/substrate/frame/revive/fixtures/contracts/call_data_copy.rs index ccf1664058e83..a3f0966f82972 100644 --- a/substrate/frame/revive/fixtures/contracts/call_data_copy.rs +++ b/substrate/frame/revive/fixtures/contracts/call_data_copy.rs @@ -20,8 +20,8 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; use uapi::{HostFn, HostFnImpl as api}; const TEST_DATA: [u8; 32] = [ diff --git a/substrate/frame/revive/fixtures/contracts/call_data_load.rs b/substrate/frame/revive/fixtures/contracts/call_data_load.rs index d3df9433f5d10..38f7aa7ec9935 100644 --- a/substrate/frame/revive/fixtures/contracts/call_data_load.rs +++ b/substrate/frame/revive/fixtures/contracts/call_data_load.rs @@ -22,8 +22,8 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; use uapi::{HostFn, HostFnImpl as api, ReturnFlags}; #[no_mangle] diff --git a/substrate/frame/revive/fixtures/contracts/call_data_size.rs b/substrate/frame/revive/fixtures/contracts/call_data_size.rs index 7caf18d440b88..3d2cf35486b62 100644 --- a/substrate/frame/revive/fixtures/contracts/call_data_size.rs +++ b/substrate/frame/revive/fixtures/contracts/call_data_size.rs @@ -19,8 +19,8 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; use uapi::{HostFn, HostFnImpl as api, ReturnFlags}; #[no_mangle] diff --git a/substrate/frame/revive/fixtures/contracts/call_diverging_out_len.rs b/substrate/frame/revive/fixtures/contracts/call_diverging_out_len.rs index d084c4aed6df7..9e208845c3362 100644 --- a/substrate/frame/revive/fixtures/contracts/call_diverging_out_len.rs +++ b/substrate/frame/revive/fixtures/contracts/call_diverging_out_len.rs @@ -25,8 +25,7 @@ #![no_std] #![no_main] - -extern crate common; +include!("../panic_handler.rs"); use uapi::{HostFn, HostFnImpl as api}; diff --git a/substrate/frame/revive/fixtures/contracts/call_return_code.rs b/substrate/frame/revive/fixtures/contracts/call_return_code.rs index 19b3ae3fdb262..c721988c2301e 100644 --- a/substrate/frame/revive/fixtures/contracts/call_return_code.rs +++ b/substrate/frame/revive/fixtures/contracts/call_return_code.rs @@ -20,9 +20,9 @@ //! It also forwards its input to the callee. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -42,10 +42,10 @@ pub extern "C" fn call() { let err_code = match api::call( uapi::CallFlags::empty(), callee_addr, - u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all. - u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all. + u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all. + u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all. &[u8::MAX; 32], // No deposit limit. - value, // Value transferred to the contract. + value, // Value transferred to the contract. input, None, ) { diff --git a/substrate/frame/revive/fixtures/contracts/call_runtime.rs b/substrate/frame/revive/fixtures/contracts/call_runtime.rs index 2b132398fb680..e6e4c855269d5 100644 --- a/substrate/frame/revive/fixtures/contracts/call_runtime.rs +++ b/substrate/frame/revive/fixtures/contracts/call_runtime.rs @@ -18,9 +18,9 @@ //! This passes its input to `call_runtime` and returns the return value to its caller. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/call_runtime_and_call.rs b/substrate/frame/revive/fixtures/contracts/call_runtime_and_call.rs index 78b275459f0e0..7ac21bff94dd1 100644 --- a/substrate/frame/revive/fixtures/contracts/call_runtime_and_call.rs +++ b/substrate/frame/revive/fixtures/contracts/call_runtime_and_call.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -42,10 +42,10 @@ pub extern "C" fn call() { api::call( uapi::CallFlags::empty(), callee_addr, - u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all. - u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all. - &[u8::MAX; 32], // No deposit limit. - &[0u8; 32], // Value transferred to the contract. + u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all. + u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all. + &[u8::MAX; 32], // No deposit limit. + &[0u8; 32], // Value transferred to the contract. callee_input, None, ) diff --git a/substrate/frame/revive/fixtures/contracts/call_with_flags_and_value.rs b/substrate/frame/revive/fixtures/contracts/call_with_flags_and_value.rs index 155a4b41bd95f..fe53472564fe2 100644 --- a/substrate/frame/revive/fixtures/contracts/call_with_flags_and_value.rs +++ b/substrate/frame/revive/fixtures/contracts/call_with_flags_and_value.rs @@ -18,9 +18,9 @@ //! This fixture calls the account_id with the flags and value. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::{input, u256_bytes}; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, u256_bytes, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -40,10 +40,10 @@ pub extern "C" fn call() { api::call( uapi::CallFlags::from_bits(flags).unwrap(), callee_addr, - u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all. - u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all. - &[u8::MAX; 32], // No deposit limit. - &u256_bytes(value), // Value transferred to the contract. + u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all. + u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all. + &[u8::MAX; 32], // No deposit limit. + &u256_bytes(value), // Value transferred to the contract. forwarded_input, None, ) diff --git a/substrate/frame/revive/fixtures/contracts/call_with_limit.rs b/substrate/frame/revive/fixtures/contracts/call_with_limit.rs index af5c301a353c9..abbcf001206ac 100644 --- a/substrate/frame/revive/fixtures/contracts/call_with_limit.rs +++ b/substrate/frame/revive/fixtures/contracts/call_with_limit.rs @@ -19,9 +19,9 @@ //! It returns the result of the call as output data. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -43,8 +43,8 @@ pub extern "C" fn call() { callee_addr, ref_time, proof_size, - &[u8::MAX; 32], // No deposit limit. - &[0u8; 32], // value transferred to the contract. + &[u8::MAX; 32], // No deposit limit. + &[0u8; 32], // value transferred to the contract. forwarded_input, None, ) diff --git a/substrate/frame/revive/fixtures/contracts/caller_contract.rs b/substrate/frame/revive/fixtures/contracts/caller_contract.rs index bb5e76b7fb421..8e1ab82b63ba6 100644 --- a/substrate/frame/revive/fixtures/contracts/caller_contract.rs +++ b/substrate/frame/revive/fixtures/contracts/caller_contract.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::{input, u256_bytes}; -use uapi::{HostFn, HostFnImpl as api, ReturnErrorCode}; +use uapi::{input, u256_bytes, HostFn, HostFnImpl as api, ReturnErrorCode}; const INPUT: [u8; 8] = [0u8, 1, 34, 51, 68, 85, 102, 119]; const REVERTED_INPUT: [u8; 7] = [1u8, 34, 51, 68, 85, 102, 119]; @@ -122,9 +122,9 @@ pub extern "C" fn call() { let res = api::call( uapi::CallFlags::empty(), &callee, - load_code_ref_time, // just enough to load the contract + load_code_ref_time, // just enough to load the contract load_code_proof_size, // just enough to load the contract - &[u8::MAX; 32], // No deposit limit. + &[u8::MAX; 32], // No deposit limit. &value, &INPUT, None, diff --git a/substrate/frame/revive/fixtures/contracts/caller_is_origin_n.rs b/substrate/frame/revive/fixtures/contracts/caller_is_origin_n.rs index fd6f59802fa08..f176dae12b8de 100644 --- a/substrate/frame/revive/fixtures/contracts/caller_is_origin_n.rs +++ b/substrate/frame/revive/fixtures/contracts/caller_is_origin_n.rs @@ -19,9 +19,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/chain_extension.rs b/substrate/frame/revive/fixtures/contracts/chain_extension.rs index 474df00d69129..bd142b321c01f 100644 --- a/substrate/frame/revive/fixtures/contracts/chain_extension.rs +++ b/substrate/frame/revive/fixtures/contracts/chain_extension.rs @@ -18,9 +18,9 @@ //! Call chain extension by passing through input and output of this contract. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/chain_extension_temp_storage.rs b/substrate/frame/revive/fixtures/contracts/chain_extension_temp_storage.rs index 9b76b9d39ee94..70aedf35fea56 100644 --- a/substrate/frame/revive/fixtures/contracts/chain_extension_temp_storage.rs +++ b/substrate/frame/revive/fixtures/contracts/chain_extension_temp_storage.rs @@ -19,9 +19,9 @@ //! It then calls itself once #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/chain_id.rs b/substrate/frame/revive/fixtures/contracts/chain_id.rs index ce7a0cc671ce6..6b712a36e3781 100644 --- a/substrate/frame/revive/fixtures/contracts/chain_id.rs +++ b/substrate/frame/revive/fixtures/contracts/chain_id.rs @@ -17,8 +17,7 @@ #![no_std] #![no_main] - -extern crate common; +include!("../panic_handler.rs"); use uapi::{HostFn, HostFnImpl as api, ReturnFlags}; diff --git a/substrate/frame/revive/fixtures/contracts/code_hash.rs b/substrate/frame/revive/fixtures/contracts/code_hash.rs index b598a485a8c72..050447b1e4f16 100644 --- a/substrate/frame/revive/fixtures/contracts/code_hash.rs +++ b/substrate/frame/revive/fixtures/contracts/code_hash.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -28,13 +28,13 @@ pub extern "C" fn deploy() {} #[no_mangle] #[polkavm_derive::polkavm_export] pub extern "C" fn call() { - input!( - address: &[u8; 20], - expected_code_hash: &[u8; 32], - ); + input!( + address: &[u8; 20], + expected_code_hash: &[u8; 32], + ); - let mut code_hash = [0u8; 32]; - api::code_hash(address, &mut code_hash); + let mut code_hash = [0u8; 32]; + api::code_hash(address, &mut code_hash); - assert!(&code_hash == expected_code_hash); + assert!(&code_hash == expected_code_hash); } diff --git a/substrate/frame/revive/fixtures/contracts/common/Cargo.toml b/substrate/frame/revive/fixtures/contracts/common/Cargo.toml deleted file mode 100644 index 7dadb7b821a2e..0000000000000 --- a/substrate/frame/revive/fixtures/contracts/common/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "pallet-revive-fixtures-common" -publish = false -version = "1.0.0" -authors.workspace = true -edition.workspace = true -license.workspace = true -description = "Common utilities for pallet-revive-fixtures." - -[dependencies] -uapi = { package = 'pallet-revive-uapi', path = "../../../uapi", default-features = false } diff --git a/substrate/frame/revive/fixtures/contracts/create1_with_value.rs b/substrate/frame/revive/fixtures/contracts/create1_with_value.rs index a694a9b091898..3e7b76744c73d 100644 --- a/substrate/frame/revive/fixtures/contracts/create1_with_value.rs +++ b/substrate/frame/revive/fixtures/contracts/create1_with_value.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/create_storage_and_call.rs b/substrate/frame/revive/fixtures/contracts/create_storage_and_call.rs index 5bb11e27903e7..e13bd6a8513c1 100644 --- a/substrate/frame/revive/fixtures/contracts/create_storage_and_call.rs +++ b/substrate/frame/revive/fixtures/contracts/create_storage_and_call.rs @@ -18,9 +18,9 @@ //! This calls another contract as passed as its account id. It also creates some storage. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{input, HostFn, HostFnImpl as api, StorageFlags}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -43,10 +43,12 @@ pub extern "C" fn call() { let ret = api::call( uapi::CallFlags::empty(), callee, - u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all resources. - u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all resources. + u64::MAX, /* How much ref_time weight to devote for the execution. u64::MAX = use all + * resources. */ + u64::MAX, /* How much proof_size weight to devote for the execution. u64::MAX = use all + * resources. */ deposit_limit, - &[0u8; 32], // Value transferred to the contract. + &[0u8; 32], // Value transferred to the contract. input, None, ); diff --git a/substrate/frame/revive/fixtures/contracts/create_storage_and_instantiate.rs b/substrate/frame/revive/fixtures/contracts/create_storage_and_instantiate.rs index 0ee0bd70db97c..fa679886c5d55 100644 --- a/substrate/frame/revive/fixtures/contracts/create_storage_and_instantiate.rs +++ b/substrate/frame/revive/fixtures/contracts/create_storage_and_instantiate.rs @@ -18,9 +18,9 @@ //! This instantiates another contract and passes some input to its constructor. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::{input, u256_bytes}; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{input, u256_bytes, HostFn, HostFnImpl as api, StorageFlags}; static BUFFER: [u8; 16 * 1024 + 1] = [0u8; 16 * 1024 + 1]; diff --git a/substrate/frame/revive/fixtures/contracts/create_transient_storage_and_call.rs b/substrate/frame/revive/fixtures/contracts/create_transient_storage_and_call.rs index 0244967a05565..5a5514a55ac12 100644 --- a/substrate/frame/revive/fixtures/contracts/create_transient_storage_and_call.rs +++ b/substrate/frame/revive/fixtures/contracts/create_transient_storage_and_call.rs @@ -18,9 +18,9 @@ //! This calls another contract as passed as its account id. It also creates some transient storage. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{input, HostFn, HostFnImpl as api, StorageFlags}; static BUFFER: [u8; 416] = [0u8; 416]; diff --git a/substrate/frame/revive/fixtures/contracts/crypto_hashes.rs b/substrate/frame/revive/fixtures/contracts/crypto_hashes.rs index 35cc03f1e7237..f673c5b3b42df 100644 --- a/substrate/frame/revive/fixtures/contracts/crypto_hashes.rs +++ b/substrate/frame/revive/fixtures/contracts/crypto_hashes.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/delegate_call.rs b/substrate/frame/revive/fixtures/contracts/delegate_call.rs index 0dedd5f704cb9..fea2992e186fb 100644 --- a/substrate/frame/revive/fixtures/contracts/delegate_call.rs +++ b/substrate/frame/revive/fixtures/contracts/delegate_call.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{input, HostFn, HostFnImpl as api, StorageFlags}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -53,8 +53,9 @@ pub extern "C" fn call() { proof_size, &[u8::MAX; 32], &input, - None - ).unwrap(); + None, + ) + .unwrap(); api::get_storage(StorageFlags::empty(), &key, value).unwrap(); assert!(value[0] == 1u8); diff --git a/substrate/frame/revive/fixtures/contracts/delegate_call_deposit_limit.rs b/substrate/frame/revive/fixtures/contracts/delegate_call_deposit_limit.rs index 0c503aa93c565..3861379df6327 100644 --- a/substrate/frame/revive/fixtures/contracts/delegate_call_deposit_limit.rs +++ b/substrate/frame/revive/fixtures/contracts/delegate_call_deposit_limit.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::{input, u256_bytes}; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{input, u256_bytes, HostFn, HostFnImpl as api, StorageFlags}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -41,7 +41,7 @@ pub extern "C" fn call() { u64::MAX, &u256_bytes(deposit_limit), &input, - None + None, ); if let Err(code) = ret { @@ -53,6 +53,6 @@ pub extern "C" fn call() { let mut value = [0u8; 32]; - api::get_storage(StorageFlags::empty(), &key, &mut &mut value[..]).unwrap(); + api::get_storage(StorageFlags::empty(), &key, &mut &mut value[..]).unwrap(); assert!(value[0] == 1u8); } diff --git a/substrate/frame/revive/fixtures/contracts/delegate_call_lib.rs b/substrate/frame/revive/fixtures/contracts/delegate_call_lib.rs index 95c1bd2aa6cd6..2a3364f46c4a5 100644 --- a/substrate/frame/revive/fixtures/contracts/delegate_call_lib.rs +++ b/substrate/frame/revive/fixtures/contracts/delegate_call_lib.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::u64_output; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{u64_output, HostFn, HostFnImpl as api, StorageFlags}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/delegate_call_simple.rs b/substrate/frame/revive/fixtures/contracts/delegate_call_simple.rs index b7bdb792c76c5..c90b42ca1bdef 100644 --- a/substrate/frame/revive/fixtures/contracts/delegate_call_simple.rs +++ b/substrate/frame/revive/fixtures/contracts/delegate_call_simple.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -39,6 +39,7 @@ pub extern "C" fn call() { u64::MAX, &[u8::MAX; 32], &input, - None - ).unwrap(); + None, + ) + .unwrap(); } diff --git a/substrate/frame/revive/fixtures/contracts/destroy_and_transfer.rs b/substrate/frame/revive/fixtures/contracts/destroy_and_transfer.rs index b5face97e2360..919dded0f060d 100644 --- a/substrate/frame/revive/fixtures/contracts/destroy_and_transfer.rs +++ b/substrate/frame/revive/fixtures/contracts/destroy_and_transfer.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::{input, u256_bytes}; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{input, u256_bytes, HostFn, HostFnImpl as api, StorageFlags}; const ADDRESS_KEY: [u8; 32] = [0u8; 32]; const VALUE: [u8; 32] = u256_bytes(65536); @@ -33,8 +33,9 @@ pub extern "C" fn deploy() { let salt = [47u8; 32]; api::instantiate( - u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all. - u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all. + u64::MAX, /* How much ref_time weight to devote for the execution. u64::MAX = use + * all. */ + u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all. &[u8::MAX; 32], // No deposit limit. &VALUE, code_hash, @@ -60,8 +61,8 @@ pub extern "C" fn call() { let res = api::call( uapi::CallFlags::empty(), &callee_addr, - u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all. - u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all. + u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all. + u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all. &[u8::MAX; 32], // No deposit limit. &VALUE, &[0u8; 1], @@ -73,8 +74,8 @@ pub extern "C" fn call() { api::call( uapi::CallFlags::empty(), &callee_addr, - u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all. - u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all. + u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all. + u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all. &[u8::MAX; 32], // No deposit limit. &VALUE, &[0u8; 0], diff --git a/substrate/frame/revive/fixtures/contracts/drain.rs b/substrate/frame/revive/fixtures/contracts/drain.rs index 53fb213143c48..13698205eb20a 100644 --- a/substrate/frame/revive/fixtures/contracts/drain.rs +++ b/substrate/frame/revive/fixtures/contracts/drain.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::{u256_bytes, u64_output}; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{u256_bytes, u64_output, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/dummy.rs b/substrate/frame/revive/fixtures/contracts/dummy.rs index c7294e99139e8..34cefb8f7f6cc 100644 --- a/substrate/frame/revive/fixtures/contracts/dummy.rs +++ b/substrate/frame/revive/fixtures/contracts/dummy.rs @@ -16,8 +16,7 @@ // limitations under the License. #![no_std] #![no_main] - -extern crate common; +include!("../panic_handler.rs"); use uapi::{HostFn, HostFnImpl as api, ReturnFlags}; diff --git a/substrate/frame/revive/fixtures/contracts/event_and_return_on_deploy.rs b/substrate/frame/revive/fixtures/contracts/event_and_return_on_deploy.rs index 5c438c1a75a13..2b0c1b2a0d1e2 100644 --- a/substrate/frame/revive/fixtures/contracts/event_and_return_on_deploy.rs +++ b/substrate/frame/revive/fixtures/contracts/event_and_return_on_deploy.rs @@ -17,8 +17,8 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; use uapi::{HostFn, HostFnImpl as api}; #[no_mangle] diff --git a/substrate/frame/revive/fixtures/contracts/event_size.rs b/substrate/frame/revive/fixtures/contracts/event_size.rs index 7f04ae42765aa..92f5caf115f61 100644 --- a/substrate/frame/revive/fixtures/contracts/event_size.rs +++ b/substrate/frame/revive/fixtures/contracts/event_size.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; static BUFFER: [u8; 16 * 1024 + 1] = [0u8; 16 * 1024 + 1]; diff --git a/substrate/frame/revive/fixtures/contracts/extcodesize.rs b/substrate/frame/revive/fixtures/contracts/extcodesize.rs index 3f51b69b46db2..be25ac0c36928 100644 --- a/substrate/frame/revive/fixtures/contracts/extcodesize.rs +++ b/substrate/frame/revive/fixtures/contracts/extcodesize.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/float_instruction.rs b/substrate/frame/revive/fixtures/contracts/float_instruction.rs index b1eaaf8543c67..654b1a22b40b4 100644 --- a/substrate/frame/revive/fixtures/contracts/float_instruction.rs +++ b/substrate/frame/revive/fixtures/contracts/float_instruction.rs @@ -17,8 +17,7 @@ #![no_std] #![no_main] - -extern crate common; +include!("../panic_handler.rs"); #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/gas_limit.rs b/substrate/frame/revive/fixtures/contracts/gas_limit.rs index 9ce82227b64da..ff53eb4324959 100644 --- a/substrate/frame/revive/fixtures/contracts/gas_limit.rs +++ b/substrate/frame/revive/fixtures/contracts/gas_limit.rs @@ -19,8 +19,8 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; use uapi::{HostFn, HostFnImpl as api, ReturnFlags}; #[no_mangle] diff --git a/substrate/frame/revive/fixtures/contracts/gas_price.rs b/substrate/frame/revive/fixtures/contracts/gas_price.rs index c1c8109fafbee..6abe1c8c03ddc 100644 --- a/substrate/frame/revive/fixtures/contracts/gas_price.rs +++ b/substrate/frame/revive/fixtures/contracts/gas_price.rs @@ -19,8 +19,8 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; use uapi::{HostFn, HostFnImpl as api, ReturnFlags}; #[no_mangle] diff --git a/substrate/frame/revive/fixtures/contracts/immutable_data.rs b/substrate/frame/revive/fixtures/contracts/immutable_data.rs index ac50e61a400b9..d27b25d097dac 100644 --- a/substrate/frame/revive/fixtures/contracts/immutable_data.rs +++ b/substrate/frame/revive/fixtures/contracts/immutable_data.rs @@ -19,9 +19,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/instantiate_return_code.rs b/substrate/frame/revive/fixtures/contracts/instantiate_return_code.rs index a3643bdedbdbd..a1904415e88f4 100644 --- a/substrate/frame/revive/fixtures/contracts/instantiate_return_code.rs +++ b/substrate/frame/revive/fixtures/contracts/instantiate_return_code.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::{input, u256_bytes}; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, u256_bytes, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -31,8 +31,9 @@ pub extern "C" fn call() { input!(buffer: &[u8; 36],); let err_code = match api::instantiate( - u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all. - u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all. + u64::MAX, /* How much ref_time weight to devote for the execution. u64::MAX = use + * all. */ + u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all. &[u8::MAX; 32], // No deposit limit. &u256_bytes(10_000u64), // Value to transfer. buffer, diff --git a/substrate/frame/revive/fixtures/contracts/multi_store.rs b/substrate/frame/revive/fixtures/contracts/multi_store.rs index 079a4548e78d7..85b7b250f91f1 100644 --- a/substrate/frame/revive/fixtures/contracts/multi_store.rs +++ b/substrate/frame/revive/fixtures/contracts/multi_store.rs @@ -18,9 +18,9 @@ //! Does two stores to two separate storage items #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{input, HostFn, HostFnImpl as api, StorageFlags}; static BUFFER: [u8; 512] = [0u8; 512]; diff --git a/substrate/frame/revive/fixtures/contracts/new_set_code_hash_contract.rs b/substrate/frame/revive/fixtures/contracts/new_set_code_hash_contract.rs index 2a59b6e33d89a..02318ae705252 100644 --- a/substrate/frame/revive/fixtures/contracts/new_set_code_hash_contract.rs +++ b/substrate/frame/revive/fixtures/contracts/new_set_code_hash_contract.rs @@ -17,8 +17,8 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; use uapi::{HostFn, HostFnImpl as api}; #[no_mangle] diff --git a/substrate/frame/revive/fixtures/contracts/noop.rs b/substrate/frame/revive/fixtures/contracts/noop.rs index 48d8a6896d62b..4eb111e8406d0 100644 --- a/substrate/frame/revive/fixtures/contracts/noop.rs +++ b/substrate/frame/revive/fixtures/contracts/noop.rs @@ -16,11 +16,9 @@ // limitations under the License. #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; - -use common::input; -use uapi::HostFn; +use uapi::{input, HostFn}; #[polkavm_derive::polkavm_import] extern "C" { diff --git a/substrate/frame/revive/fixtures/contracts/ok_trap_revert.rs b/substrate/frame/revive/fixtures/contracts/ok_trap_revert.rs index 55115f8642f3e..c670d16f8f355 100644 --- a/substrate/frame/revive/fixtures/contracts/ok_trap_revert.rs +++ b/substrate/frame/revive/fixtures/contracts/ok_trap_revert.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/oom_ro.rs b/substrate/frame/revive/fixtures/contracts/oom_ro.rs index 41c080d5847e8..78c524f4f13d2 100644 --- a/substrate/frame/revive/fixtures/contracts/oom_ro.rs +++ b/substrate/frame/revive/fixtures/contracts/oom_ro.rs @@ -21,8 +21,7 @@ #![no_std] #![no_main] - -extern crate common; +include!("../panic_handler.rs"); use uapi::{HostFn, HostFnImpl as api, ReturnFlags}; diff --git a/substrate/frame/revive/fixtures/contracts/oom_rw_included.rs b/substrate/frame/revive/fixtures/contracts/oom_rw_included.rs index 123ee38a52004..21d1a4afe3a89 100644 --- a/substrate/frame/revive/fixtures/contracts/oom_rw_included.rs +++ b/substrate/frame/revive/fixtures/contracts/oom_rw_included.rs @@ -21,8 +21,7 @@ #![no_std] #![no_main] - -extern crate common; +include!("../panic_handler.rs"); use uapi::{HostFn, HostFnImpl as api, ReturnFlags}; diff --git a/substrate/frame/revive/fixtures/contracts/oom_rw_trailing.rs b/substrate/frame/revive/fixtures/contracts/oom_rw_trailing.rs index e127effca20c6..fdb45e9fdaf96 100644 --- a/substrate/frame/revive/fixtures/contracts/oom_rw_trailing.rs +++ b/substrate/frame/revive/fixtures/contracts/oom_rw_trailing.rs @@ -21,8 +21,7 @@ #![no_std] #![no_main] - -extern crate common; +include!("../panic_handler.rs"); use uapi::{HostFn, HostFnImpl as api, ReturnFlags}; diff --git a/substrate/frame/revive/fixtures/contracts/origin.rs b/substrate/frame/revive/fixtures/contracts/origin.rs index 151ca3da77cd0..c4aeacc3309e1 100644 --- a/substrate/frame/revive/fixtures/contracts/origin.rs +++ b/substrate/frame/revive/fixtures/contracts/origin.rs @@ -21,8 +21,8 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; use uapi::{HostFn, HostFnImpl as api}; #[no_mangle] diff --git a/substrate/frame/revive/fixtures/contracts/read_only_call.rs b/substrate/frame/revive/fixtures/contracts/read_only_call.rs index 0a87ecbb9b140..e8454e1e30acf 100644 --- a/substrate/frame/revive/fixtures/contracts/read_only_call.rs +++ b/substrate/frame/revive/fixtures/contracts/read_only_call.rs @@ -18,9 +18,9 @@ // This fixture tests if read-only call works as expected. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -39,10 +39,10 @@ pub extern "C" fn call() { api::call( uapi::CallFlags::READ_ONLY, callee_addr, - u64::MAX, // How much ref_time to devote for the execution. u64::MAX = all. - u64::MAX, // How much proof_size to devote for the execution. u64::MAX = all. - &[u8::MAX; 32], // No deposit limit. - &[0u8; 32], // Value transferred to the contract. + u64::MAX, // How much ref_time to devote for the execution. u64::MAX = all. + u64::MAX, // How much proof_size to devote for the execution. u64::MAX = all. + &[u8::MAX; 32], // No deposit limit. + &[0u8; 32], // Value transferred to the contract. callee_input, None, ) diff --git a/substrate/frame/revive/fixtures/contracts/recurse.rs b/substrate/frame/revive/fixtures/contracts/recurse.rs index ead565c01459e..b59f140d4e60d 100644 --- a/substrate/frame/revive/fixtures/contracts/recurse.rs +++ b/substrate/frame/revive/fixtures/contracts/recurse.rs @@ -19,9 +19,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -43,10 +43,10 @@ pub extern "C" fn call() { api::call( uapi::CallFlags::ALLOW_REENTRY, &addr, - u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all resources. - u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all resources. + u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all resources. + u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all resources. &[u8::MAX; 32], // No deposit limit. - &[0u8; 32], // Value transferred to the contract. + &[0u8; 32], // Value transferred to the contract. &(calls_left - 1).to_le_bytes(), None, ) diff --git a/substrate/frame/revive/fixtures/contracts/ref_time_left.rs b/substrate/frame/revive/fixtures/contracts/ref_time_left.rs index aa892a8ba440e..81a74b056de74 100644 --- a/substrate/frame/revive/fixtures/contracts/ref_time_left.rs +++ b/substrate/frame/revive/fixtures/contracts/ref_time_left.rs @@ -17,8 +17,8 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; use uapi::{HostFn, HostFnImpl as api, ReturnFlags}; #[no_mangle] diff --git a/substrate/frame/revive/fixtures/contracts/return_data_api.rs b/substrate/frame/revive/fixtures/contracts/return_data_api.rs index e8aeeea44bde7..4066531b602a0 100644 --- a/substrate/frame/revive/fixtures/contracts/return_data_api.rs +++ b/substrate/frame/revive/fixtures/contracts/return_data_api.rs @@ -25,9 +25,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::{input, u256_bytes}; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, u256_bytes, HostFn, HostFnImpl as api}; const INPUT_BUF_SIZE: usize = 128; static INPUT_DATA: [u8; INPUT_BUF_SIZE] = [0xFF; INPUT_BUF_SIZE]; diff --git a/substrate/frame/revive/fixtures/contracts/return_with_data.rs b/substrate/frame/revive/fixtures/contracts/return_with_data.rs index 47a1cc9111928..8f18803ad71cd 100644 --- a/substrate/frame/revive/fixtures/contracts/return_with_data.rs +++ b/substrate/frame/revive/fixtures/contracts/return_with_data.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{input, HostFn, HostFnImpl as api, StorageFlags}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/rpc_demo.rs b/substrate/frame/revive/fixtures/contracts/rpc_demo.rs index 4c61f2ea82ec5..3d788aaa9f4e6 100644 --- a/substrate/frame/revive/fixtures/contracts/rpc_demo.rs +++ b/substrate/frame/revive/fixtures/contracts/rpc_demo.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::{input, u64_output}; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, u64_output, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/run_out_of_gas.rs b/substrate/frame/revive/fixtures/contracts/run_out_of_gas.rs index 11eaaa7c86247..e4e074dcb79c0 100644 --- a/substrate/frame/revive/fixtures/contracts/run_out_of_gas.rs +++ b/substrate/frame/revive/fixtures/contracts/run_out_of_gas.rs @@ -17,8 +17,7 @@ #![no_std] #![no_main] - -extern crate common; +include!("../panic_handler.rs"); #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/sbrk.rs b/substrate/frame/revive/fixtures/contracts/sbrk.rs index 5b0bba99df81f..2a4e904509c90 100644 --- a/substrate/frame/revive/fixtures/contracts/sbrk.rs +++ b/substrate/frame/revive/fixtures/contracts/sbrk.rs @@ -19,8 +19,7 @@ #![no_std] #![no_main] - -extern crate common; +include!("../panic_handler.rs"); // Export that is never called. We can put code here that should be in the binary // but is never supposed to be run. diff --git a/substrate/frame/revive/fixtures/contracts/self_destruct.rs b/substrate/frame/revive/fixtures/contracts/self_destruct.rs index eed7f40ddfed7..22611be548aa0 100644 --- a/substrate/frame/revive/fixtures/contracts/self_destruct.rs +++ b/substrate/frame/revive/fixtures/contracts/self_destruct.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; const DJANGO_FALLBACK: [u8; 20] = [4u8; 20]; @@ -45,10 +45,10 @@ pub extern "C" fn call() { api::call( uapi::CallFlags::ALLOW_REENTRY, &addr, - u64::MAX, // How much ref_time to devote for the execution. u64 = all. - u64::MAX, // How much proof_size to devote for the execution. u64 = all. - &[u8::MAX; 32], // No deposit limit. - &[0u8; 32], // Value to transfer. + u64::MAX, // How much ref_time to devote for the execution. u64 = all. + u64::MAX, // How much proof_size to devote for the execution. u64 = all. + &[u8::MAX; 32], // No deposit limit. + &[0u8; 32], // Value to transfer. &[0u8; 0], None, ) diff --git a/substrate/frame/revive/fixtures/contracts/self_destructing_constructor.rs b/substrate/frame/revive/fixtures/contracts/self_destructing_constructor.rs index 3285aecbe7809..fb80afd70ba35 100644 --- a/substrate/frame/revive/fixtures/contracts/self_destructing_constructor.rs +++ b/substrate/frame/revive/fixtures/contracts/self_destructing_constructor.rs @@ -17,8 +17,8 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; use uapi::{HostFn, HostFnImpl as api}; #[no_mangle] diff --git a/substrate/frame/revive/fixtures/contracts/set_code_hash.rs b/substrate/frame/revive/fixtures/contracts/set_code_hash.rs index 7292c6fd10ae7..cd9a3665f03c2 100644 --- a/substrate/frame/revive/fixtures/contracts/set_code_hash.rs +++ b/substrate/frame/revive/fixtures/contracts/set_code_hash.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/set_empty_storage.rs b/substrate/frame/revive/fixtures/contracts/set_empty_storage.rs index f8bbfe3faa5be..1d2773278bd3a 100644 --- a/substrate/frame/revive/fixtures/contracts/set_empty_storage.rs +++ b/substrate/frame/revive/fixtures/contracts/set_empty_storage.rs @@ -17,8 +17,8 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -extern crate common; use uapi::{HostFn, HostFnImpl as api, StorageFlags}; #[no_mangle] diff --git a/substrate/frame/revive/fixtures/contracts/set_transient_storage.rs b/substrate/frame/revive/fixtures/contracts/set_transient_storage.rs index a8a1fbd651489..bc980756608db 100644 --- a/substrate/frame/revive/fixtures/contracts/set_transient_storage.rs +++ b/substrate/frame/revive/fixtures/contracts/set_transient_storage.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{input, HostFn, HostFnImpl as api, StorageFlags}; static BUFFER: [u8; 512] = [0u8; 512]; diff --git a/substrate/frame/revive/fixtures/contracts/sr25519_verify.rs b/substrate/frame/revive/fixtures/contracts/sr25519_verify.rs index 8920ce0d4f6c2..8ef39848c53fe 100644 --- a/substrate/frame/revive/fixtures/contracts/sr25519_verify.rs +++ b/substrate/frame/revive/fixtures/contracts/sr25519_verify.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/storage.rs b/substrate/frame/revive/fixtures/contracts/storage.rs index dc21e322466cc..02d3cf0d1a138 100644 --- a/substrate/frame/revive/fixtures/contracts/storage.rs +++ b/substrate/frame/revive/fixtures/contracts/storage.rs @@ -19,9 +19,9 @@ //! versions of the storage APIs. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::unwrap_output; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{unwrap_output, HostFn, HostFnImpl as api, StorageFlags}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/storage_size.rs b/substrate/frame/revive/fixtures/contracts/storage_size.rs index 617e8d2ea79ff..6fbb078555328 100644 --- a/substrate/frame/revive/fixtures/contracts/storage_size.rs +++ b/substrate/frame/revive/fixtures/contracts/storage_size.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{input, HostFn, HostFnImpl as api, StorageFlags}; static mut BUFFER: [u8; 16 * 1024 + 1] = [0u8; 16 * 1024 + 1]; @@ -32,9 +32,7 @@ pub extern "C" fn deploy() {} pub extern "C" fn call() { input!(len: u32, ); - let data = unsafe { - &BUFFER[..len as usize] - }; + let data = unsafe { &BUFFER[..len as usize] }; // Place a garbage value in storage, the size of which is specified by the call input. let mut key = [0u8; 32]; @@ -42,9 +40,7 @@ pub extern "C" fn call() { api::set_storage(StorageFlags::empty(), &key, data); - let data = unsafe { - &mut &mut BUFFER[..] - }; + let data = unsafe { &mut &mut BUFFER[..] }; api::get_storage(StorageFlags::empty(), &key, data).unwrap(); assert_eq!(data.len(), len as usize); } diff --git a/substrate/frame/revive/fixtures/contracts/store_call.rs b/substrate/frame/revive/fixtures/contracts/store_call.rs index b08d445191e57..920c31d373e99 100644 --- a/substrate/frame/revive/fixtures/contracts/store_call.rs +++ b/substrate/frame/revive/fixtures/contracts/store_call.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{input, HostFn, HostFnImpl as api, StorageFlags}; static BUFFER: [u8; 512] = [0u8; 512]; diff --git a/substrate/frame/revive/fixtures/contracts/store_deploy.rs b/substrate/frame/revive/fixtures/contracts/store_deploy.rs index e08c79d78f3ba..a2e9440bfc18b 100644 --- a/substrate/frame/revive/fixtures/contracts/store_deploy.rs +++ b/substrate/frame/revive/fixtures/contracts/store_deploy.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{input, HostFn, HostFnImpl as api, StorageFlags}; static BUFFER: [u8; 16 * 1024 + 1] = [0u8; 16 * 1024 + 1]; diff --git a/substrate/frame/revive/fixtures/contracts/terminate_and_send_to_argument.rs b/substrate/frame/revive/fixtures/contracts/terminate_and_send_to_argument.rs index d34736de30a65..b1891d813d001 100644 --- a/substrate/frame/revive/fixtures/contracts/terminate_and_send_to_argument.rs +++ b/substrate/frame/revive/fixtures/contracts/terminate_and_send_to_argument.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/to_account_id.rs b/substrate/frame/revive/fixtures/contracts/to_account_id.rs index c2a8fce3ec995..a0b359c628577 100644 --- a/substrate/frame/revive/fixtures/contracts/to_account_id.rs +++ b/substrate/frame/revive/fixtures/contracts/to_account_id.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] @@ -28,13 +28,13 @@ pub extern "C" fn deploy() {} #[no_mangle] #[polkavm_derive::polkavm_export] pub extern "C" fn call() { - input!( - address: &[u8; 20], - expected_account_id: &[u8; 32], - ); + input!( + address: &[u8; 20], + expected_account_id: &[u8; 32], + ); - let mut account_id = [0u8; 32]; - api::to_account_id(address, &mut account_id); + let mut account_id = [0u8; 32]; + api::to_account_id(address, &mut account_id); - assert!(&account_id == expected_account_id); + assert!(&account_id == expected_account_id); } diff --git a/substrate/frame/revive/fixtures/contracts/tracing.rs b/substrate/frame/revive/fixtures/contracts/tracing.rs index 451769b87cefd..8e79665b23446 100644 --- a/substrate/frame/revive/fixtures/contracts/tracing.rs +++ b/substrate/frame/revive/fixtures/contracts/tracing.rs @@ -19,9 +19,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::{input, u256_bytes}; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, u256_bytes, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/tracing_callee.rs b/substrate/frame/revive/fixtures/contracts/tracing_callee.rs index d44771e417f9d..f59ad5fdf12ed 100644 --- a/substrate/frame/revive/fixtures/contracts/tracing_callee.rs +++ b/substrate/frame/revive/fixtures/contracts/tracing_callee.rs @@ -16,9 +16,9 @@ // limitations under the License. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/transfer_return_code.rs b/substrate/frame/revive/fixtures/contracts/transfer_return_code.rs index 053f97feda4a8..4c55f0c53af27 100644 --- a/substrate/frame/revive/fixtures/contracts/transfer_return_code.rs +++ b/substrate/frame/revive/fixtures/contracts/transfer_return_code.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::u256_bytes; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{u256_bytes, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/transient_storage.rs b/substrate/frame/revive/fixtures/contracts/transient_storage.rs index aa0a69435a694..f3d891e3919c0 100644 --- a/substrate/frame/revive/fixtures/contracts/transient_storage.rs +++ b/substrate/frame/revive/fixtures/contracts/transient_storage.rs @@ -18,9 +18,9 @@ //! This contract tests the transient storage APIs. #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::unwrap_output; -use uapi::{HostFn, HostFnImpl as api, StorageFlags}; +use uapi::{unwrap_output, HostFn, HostFnImpl as api, StorageFlags}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/unknown_syscall.rs b/substrate/frame/revive/fixtures/contracts/unknown_syscall.rs index 93ea86754f55a..ce3fb923596ed 100644 --- a/substrate/frame/revive/fixtures/contracts/unknown_syscall.rs +++ b/substrate/frame/revive/fixtures/contracts/unknown_syscall.rs @@ -16,8 +16,7 @@ // limitations under the License. #![no_std] #![no_main] - -extern crate common; +include!("../panic_handler.rs"); #[polkavm_derive::polkavm_import] extern "C" { diff --git a/substrate/frame/revive/fixtures/contracts/unstable_interface.rs b/substrate/frame/revive/fixtures/contracts/unstable_interface.rs index d73ae041dc068..b4812a793f3ba 100644 --- a/substrate/frame/revive/fixtures/contracts/unstable_interface.rs +++ b/substrate/frame/revive/fixtures/contracts/unstable_interface.rs @@ -16,8 +16,7 @@ // limitations under the License. #![no_std] #![no_main] - -extern crate common; +include!("../panic_handler.rs"); #[polkavm_derive::polkavm_import] extern "C" { diff --git a/substrate/frame/revive/fixtures/contracts/xcm_execute.rs b/substrate/frame/revive/fixtures/contracts/xcm_execute.rs index 1d570ffead718..0817682735a33 100644 --- a/substrate/frame/revive/fixtures/contracts/xcm_execute.rs +++ b/substrate/frame/revive/fixtures/contracts/xcm_execute.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/contracts/xcm_send.rs b/substrate/frame/revive/fixtures/contracts/xcm_send.rs index 6d4629e748a76..f94cb765edfc3 100644 --- a/substrate/frame/revive/fixtures/contracts/xcm_send.rs +++ b/substrate/frame/revive/fixtures/contracts/xcm_send.rs @@ -17,9 +17,9 @@ #![no_std] #![no_main] +include!("../panic_handler.rs"); -use common::input; -use uapi::{HostFn, HostFnImpl as api}; +use uapi::{input, HostFn, HostFnImpl as api}; #[no_mangle] #[polkavm_derive::polkavm_export] diff --git a/substrate/frame/revive/fixtures/panic_handler.rs b/substrate/frame/revive/fixtures/panic_handler.rs new file mode 100644 index 0000000000000..176045f2fb05c --- /dev/null +++ b/substrate/frame/revive/fixtures/panic_handler.rs @@ -0,0 +1,25 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + // Safety: The unimp instruction is guaranteed to trap + unsafe { + core::arch::asm!("unimp"); + core::hint::unreachable_unchecked(); + } +} diff --git a/substrate/frame/revive/rpc/Cargo.toml b/substrate/frame/revive/rpc/Cargo.toml index 0353cf2370952..1eb48b977b0b1 100644 --- a/substrate/frame/revive/rpc/Cargo.toml +++ b/substrate/frame/revive/rpc/Cargo.toml @@ -13,10 +13,6 @@ default-run = "eth-rpc" name = "eth-rpc" path = "src/main.rs" -[[bin]] -name = "eth-rpc-tester" -path = "src/eth-rpc-tester.rs" - [dependencies] anyhow = { workspace = true } clap = { workspace = true, features = ["derive", "env"] } @@ -26,7 +22,6 @@ hex = { workspace = true } jsonrpsee = { workspace = true, features = ["full"] } log = { workspace = true } pallet-revive = { workspace = true, default-features = true } -pallet-revive-fixtures = { workspace = true, default-features = true } prometheus-endpoint = { workspace = true, default-features = true } rlp = { workspace = true } sc-cli = { workspace = true, default-features = true } @@ -50,6 +45,7 @@ tokio = { workspace = true, features = ["full"] } [dev-dependencies] env_logger = { workspace = true } +pallet-revive-fixtures = { workspace = true, default-features = true } pretty_assertions = { workspace = true } static_init = { workspace = true } substrate-cli-test-utils = { workspace = true } diff --git a/substrate/frame/revive/rpc/examples/README.md b/substrate/frame/revive/rpc/examples/README.md index 5bbd6255713cf..ceed155ab1492 100644 --- a/substrate/frame/revive/rpc/examples/README.md +++ b/substrate/frame/revive/rpc/examples/README.md @@ -1,11 +1,3 @@ -## Pre-requisites - - Build `pallet-revive-fixture`, as we need some compiled contracts to exercise the RPC server. - -```bash -cargo build -p pallet-revive-fixtures -``` - ## Start the node Start the kitchensink node: diff --git a/substrate/frame/revive/rpc/src/eth-rpc-tester.rs b/substrate/frame/revive/rpc/examples/eth-rpc-tester.rs similarity index 100% rename from substrate/frame/revive/rpc/src/eth-rpc-tester.rs rename to substrate/frame/revive/rpc/examples/eth-rpc-tester.rs diff --git a/substrate/frame/revive/uapi/src/lib.rs b/substrate/frame/revive/uapi/src/lib.rs index 744a2f0bca5d1..f52e72ebc9399 100644 --- a/substrate/frame/revive/uapi/src/lib.rs +++ b/substrate/frame/revive/uapi/src/lib.rs @@ -22,9 +22,26 @@ mod flags; pub use flags::*; mod host; +mod macros; pub use host::{HostFn, HostFnImpl}; +/// Convert a u64 into a [u8; 32]. +pub const fn u256_bytes(value: u64) -> [u8; 32] { + let mut buffer = [0u8; 32]; + let bytes = value.to_le_bytes(); + + buffer[0] = bytes[0]; + buffer[1] = bytes[1]; + buffer[2] = bytes[2]; + buffer[3] = bytes[3]; + buffer[4] = bytes[4]; + buffer[5] = bytes[5]; + buffer[6] = bytes[6]; + buffer[7] = bytes[7]; + buffer +} + macro_rules! define_error_codes { ( $( diff --git a/substrate/frame/revive/fixtures/contracts/common/src/lib.rs b/substrate/frame/revive/uapi/src/macros.rs similarity index 87% rename from substrate/frame/revive/fixtures/contracts/common/src/lib.rs rename to substrate/frame/revive/uapi/src/macros.rs index 302608ccf87c1..7f90dfc397113 100644 --- a/substrate/frame/revive/fixtures/contracts/common/src/lib.rs +++ b/substrate/frame/revive/uapi/src/macros.rs @@ -14,32 +14,19 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#![no_std] - -pub use uapi::{HostFn, HostFnImpl as api}; - -#[panic_handler] -fn panic(_info: &core::panic::PanicInfo) -> ! { - // Safety: The unimp instruction is guaranteed to trap - unsafe { - core::arch::asm!("unimp"); - core::hint::unreachable_unchecked(); - } -} /// Utility macro to read input passed to a contract. /// /// Example: -/// -/// ``` -/// input$!( +/// ```ignore +/// input!( /// var1: u32, // [0, 4) var1 decoded as u32 /// var2: [u8; 32], // [4, 36) var2 decoded as a [u8] slice /// var3: u8, // [36, 37) var3 decoded as a u8 /// ); /// /// // Input and size can be specified as well: -/// input$!( +/// input!( /// input, // input buffer (optional) /// 512, // input size (optional) /// var4: u32, // [0, 4) var4 decoded as u32 @@ -121,9 +108,9 @@ macro_rules! input { // e.g input!(buffer, 512, var1: u32, var2: [u8], ); ($buffer:ident, $size:expr, $($rest:tt)*) => { let mut $buffer = [0u8; $size]; - let input_size = $crate::api::call_data_size(); + let input_size = $crate::HostFnImpl::call_data_size(); let $buffer = &mut &mut $buffer[..$size.min(input_size as usize)]; - $crate::api::call_data_copy($buffer, 0); + $crate::HostFnImpl::call_data_copy($buffer, 0); input!(@inner $buffer, 0, $($rest)*); }; @@ -143,7 +130,9 @@ macro_rules! input { /// Utility macro to invoke a host function that expect a `output: &mut &mut [u8]` as last argument. /// /// Example: -/// ``` +/// ```ignore +/// use pallet_revive_uapi::{output, HostFn, HostFnImpl as api}; +/// /// // call `api::caller` and store the output in `caller` /// output!(caller, [0u8; 32], api::caller,); /// @@ -179,19 +168,3 @@ macro_rules! u64_output { u64::from_le_bytes(buffer[..8].try_into().unwrap()) }}; } - -/// Convert a u64 into a [u8; 32]. -pub const fn u256_bytes(value: u64) -> [u8; 32] { - let mut buffer = [0u8; 32]; - let bytes = value.to_le_bytes(); - - buffer[0] = bytes[0]; - buffer[1] = bytes[1]; - buffer[2] = bytes[2]; - buffer[3] = bytes[3]; - buffer[4] = bytes[4]; - buffer[5] = bytes[5]; - buffer[6] = bytes[6]; - buffer[7] = bytes[7]; - buffer -}