From 91bef33b3948dfce988a495ecd05066d4816ce61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Wed, 18 Dec 2024 22:39:47 +0100 Subject: [PATCH] pallet-revive: Fix docs.rs (#6896) - Fixed failing docs.rs build for `pallet-revive-uapi` by fixing a wring attribute in the manifest (we were using `default-target` instead of `targets`) - Removed the macros defining host functions because the cfg attributes introduced in #6866 won't work on them - Added an docs.rs specific attribute so that the `unstable-hostfn` feature tag will show up on the functions that are guarded behind it. --------- Co-authored-by: command-bot <> --- Cargo.lock | 1 + prdoc/pr_6896.prdoc | 16 ++ substrate/frame/contracts/uapi/Cargo.toml | 2 +- .../frame/revive/fixtures/build/_Cargo.toml | 2 +- substrate/frame/revive/proc-macro/src/lib.rs | 11 ++ substrate/frame/revive/uapi/Cargo.toml | 6 +- substrate/frame/revive/uapi/src/host.rs | 123 ++++++++++------ .../frame/revive/uapi/src/host/riscv64.rs | 138 +++++++++--------- substrate/frame/revive/uapi/src/lib.rs | 1 + 9 files changed, 183 insertions(+), 117 deletions(-) create mode 100644 prdoc/pr_6896.prdoc diff --git a/Cargo.lock b/Cargo.lock index 9ae662452539..726c8f5a1885 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15047,6 +15047,7 @@ name = "pallet-revive-uapi" version = "0.1.0" dependencies = [ "bitflags 1.3.2", + "pallet-revive-proc-macro 0.1.0", "parity-scale-codec", "paste", "polkavm-derive 0.18.0", diff --git a/prdoc/pr_6896.prdoc b/prdoc/pr_6896.prdoc new file mode 100644 index 000000000000..a56e4303d9af --- /dev/null +++ b/prdoc/pr_6896.prdoc @@ -0,0 +1,16 @@ +title: 'pallet-revive: Fix docs.rs' +doc: +- audience: Runtime Dev + description: |- + - Fixed failing docs.rs build for `pallet-revive-uapi` by fixing a writing attribute in the manifest (we were using `default-target` instead of `targets`) + - Removed the macros defining host functions because the cfg attributes introduced in #6866 won't work on them + - Added an docs.rs specific attribute so that the `unstable-hostfn` feature tag will show up on the functions that are guarded behind it. +crates: +- name: pallet-contracts-uapi + bump: major +- name: pallet-revive-uapi + bump: major +- name: pallet-revive-fixtures + bump: major +- name: pallet-revive-proc-macro + bump: major diff --git a/substrate/frame/contracts/uapi/Cargo.toml b/substrate/frame/contracts/uapi/Cargo.toml index 09c70c287899..45f8c2cb84af 100644 --- a/substrate/frame/contracts/uapi/Cargo.toml +++ b/substrate/frame/contracts/uapi/Cargo.toml @@ -21,7 +21,7 @@ codec = { features = [ ], optional = true, workspace = true } [package.metadata.docs.rs] -default-target = ["wasm32-unknown-unknown"] +targets = ["wasm32-unknown-unknown"] [features] default = ["scale"] diff --git a/substrate/frame/revive/fixtures/build/_Cargo.toml b/substrate/frame/revive/fixtures/build/_Cargo.toml index 5d1c922f9002..bfb9aaedd6f5 100644 --- a/substrate/frame/revive/fixtures/build/_Cargo.toml +++ b/substrate/frame/revive/fixtures/build/_Cargo.toml @@ -12,7 +12,7 @@ edition = "2021" # All paths are injected dynamically by the build script. [dependencies] -uapi = { package = 'pallet-revive-uapi', path = "", features = ["unstable-api"], default-features = false } +uapi = { package = 'pallet-revive-uapi', path = "", features = ["unstable-hostfn"], default-features = false } common = { package = 'pallet-revive-fixtures-common', path = "" } polkavm-derive = { version = "0.18.0" } diff --git a/substrate/frame/revive/proc-macro/src/lib.rs b/substrate/frame/revive/proc-macro/src/lib.rs index ed1798e5b689..b6ea1a06d94e 100644 --- a/substrate/frame/revive/proc-macro/src/lib.rs +++ b/substrate/frame/revive/proc-macro/src/lib.rs @@ -25,6 +25,17 @@ use proc_macro2::{Literal, Span, TokenStream as TokenStream2}; use quote::{quote, ToTokens}; use syn::{parse_quote, punctuated::Punctuated, spanned::Spanned, token::Comma, FnArg, Ident}; +#[proc_macro_attribute] +pub fn unstable_hostfn(_attr: TokenStream, item: TokenStream) -> TokenStream { + let input = syn::parse_macro_input!(item as syn::Item); + let expanded = quote! { + #[cfg(feature = "unstable-hostfn")] + #[cfg_attr(docsrs, doc(cfg(feature = "unstable-hostfn")))] + #input + }; + expanded.into() +} + /// Defines a host functions set that can be imported by contract wasm code. /// /// **NB**: Be advised that all functions defined by this macro diff --git a/substrate/frame/revive/uapi/Cargo.toml b/substrate/frame/revive/uapi/Cargo.toml index 8274bf36204b..948c2c6e4f83 100644 --- a/substrate/frame/revive/uapi/Cargo.toml +++ b/substrate/frame/revive/uapi/Cargo.toml @@ -19,14 +19,16 @@ codec = { features = [ "derive", "max-encoded-len", ], optional = true, workspace = true } +pallet-revive-proc-macro = { workspace = true } [target.'cfg(target_arch = "riscv64")'.dependencies] polkavm-derive = { version = "0.18.0" } [package.metadata.docs.rs] -default-target = ["riscv64imac-unknown-none-elf"] +features = ["unstable-hostfn"] +targets = ["riscv64imac-unknown-none-elf"] [features] default = ["scale"] scale = ["dep:codec", "scale-info"] -unstable-api = [] +unstable-hostfn = [] diff --git a/substrate/frame/revive/uapi/src/host.rs b/substrate/frame/revive/uapi/src/host.rs index 16d6f0945427..476e3a26817a 100644 --- a/substrate/frame/revive/uapi/src/host.rs +++ b/substrate/frame/revive/uapi/src/host.rs @@ -12,27 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. use crate::{CallFlags, Result, ReturnFlags, StorageFlags}; -use paste::paste; +use pallet_revive_proc_macro::unstable_hostfn; #[cfg(target_arch = "riscv64")] mod riscv64; -macro_rules! hash_fn { - ( $name:ident, $bytes:literal ) => { - paste! { - #[doc = "Computes the " $name " " $bytes "-bit hash on the given input buffer."] - #[doc = "\n# Notes\n"] - #[doc = "- The `input` and `output` buffer may overlap."] - #[doc = "- The output buffer is expected to hold at least " $bytes " bits."] - #[doc = "- It is the callers responsibility to provide an output buffer that is large enough to hold the expected amount of bytes returned by the hash function."] - #[doc = "\n# Parameters\n"] - #[doc = "- `input`: The input data buffer."] - #[doc = "- `output`: The output buffer to write the hash result to."] - fn [](input: &[u8], output: &mut [u8; $bytes]); - } - }; -} - /// Implements [`HostFn`] when compiled on supported architectures (RISC-V). pub enum HostFnImpl {} @@ -238,7 +222,18 @@ pub trait HostFn: private::Sealed { /// [KeyNotFound][`crate::ReturnErrorCode::KeyNotFound] fn get_storage(flags: StorageFlags, key: &[u8], output: &mut &mut [u8]) -> Result; - hash_fn!(keccak_256, 32); + /// Computes the keccak_256 32-bit hash on the given input buffer. + /// + /// - The `input` and `output` buffer may overlap. + /// - The output buffer is expected to hold at least 32 bits. + /// - It is the callers responsibility to provide an output buffer that is large enough to hold + /// the expected amount of bytes returned by the hash function. + /// + /// # Parameters + /// + /// - `input`: The input data buffer. + /// - `output`: The output buffer to write the hash result to. + fn hash_keccak_256(input: &[u8], output: &mut [u8; 32]); /// Stores the input data passed by the caller into the supplied `output` buffer, /// starting from the given input data `offset`. @@ -400,7 +395,7 @@ pub trait HostFn: private::Sealed { /// # Parameters /// /// - `output`: A reference to the output data buffer to write the block number. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn block_number(output: &mut [u8; 32]); /// Stores the block hash of the given block number into the supplied buffer. @@ -409,7 +404,7 @@ pub trait HostFn: private::Sealed { /// /// - `block_number`: A reference to the block number buffer. /// - `output`: A reference to the output data buffer to write the block number. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn block_hash(block_number: &[u8; 32], output: &mut [u8; 32]); /// Call into the chain extension provided by the chain if any. @@ -434,7 +429,7 @@ pub trait HostFn: private::Sealed { /// # Return /// /// The chain extension returned value, if executed successfully. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn call_chain_extension(func_id: u32, input: &[u8], output: Option<&mut &mut [u8]>) -> u32; /// Call some dispatchable of the runtime. @@ -461,7 +456,7 @@ pub trait HostFn: private::Sealed { /// - Provide functionality **exclusively** to contracts. /// - Provide custom weights. /// - Avoid the need to keep the `Call` data structure stable. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn call_runtime(call: &[u8]) -> Result; /// Checks whether the caller of the current contract is the origin of the whole call stack. @@ -474,7 +469,7 @@ pub trait HostFn: private::Sealed { /// /// A return value of `true` indicates that this contract is being called by a plain account /// and `false` indicates that the caller is another contract. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn caller_is_origin() -> bool; /// Checks whether the caller of the current contract is root. @@ -484,7 +479,7 @@ pub trait HostFn: private::Sealed { /// /// A return value of `true` indicates that this contract is being called by a root origin, /// and `false` indicates that the caller is a signed origin. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn caller_is_root() -> u32; /// Clear the value at the given key in the contract storage. @@ -496,7 +491,7 @@ pub trait HostFn: private::Sealed { /// # Return /// /// Returns the size of the pre-existing value at the specified key if any. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn clear_storage(flags: StorageFlags, key: &[u8]) -> Option; /// Checks whether there is a value stored under the given key. @@ -509,7 +504,7 @@ pub trait HostFn: private::Sealed { /// # Return /// /// Returns the size of the pre-existing value at the specified key if any. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn contains_storage(flags: StorageFlags, key: &[u8]) -> Option; /// Emit a custom debug message. @@ -529,7 +524,7 @@ pub trait HostFn: private::Sealed { /// not being executed as an RPC. For example, they could allow users to disable logging /// through compile time flags (cargo features) for on-chain deployment. Additionally, the /// return value of this function can be cached in order to prevent further calls at runtime. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn debug_message(str: &[u8]) -> Result; /// Recovers the ECDSA public key from the given message hash and signature. @@ -546,7 +541,7 @@ pub trait HostFn: private::Sealed { /// # Errors /// /// - [EcdsaRecoveryFailed][`crate::ReturnErrorCode::EcdsaRecoveryFailed] - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn ecdsa_recover( signature: &[u8; 65], message_hash: &[u8; 32], @@ -564,15 +559,49 @@ pub trait HostFn: private::Sealed { /// # Errors /// /// - [EcdsaRecoveryFailed][`crate::ReturnErrorCode::EcdsaRecoveryFailed] - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn ecdsa_to_eth_address(pubkey: &[u8; 33], output: &mut [u8; 20]) -> Result; - #[cfg(feature = "unstable-api")] - hash_fn!(sha2_256, 32); - #[cfg(feature = "unstable-api")] - hash_fn!(blake2_256, 32); - #[cfg(feature = "unstable-api")] - hash_fn!(blake2_128, 16); + /// Computes the sha2_256 32-bit hash on the given input buffer. + /// + /// - The `input` and `output` buffer may overlap. + /// - The output buffer is expected to hold at least 32 bits. + /// - It is the callers responsibility to provide an output buffer that is large enough to hold + /// the expected amount of bytes returned by the hash function. + /// + /// # Parameters + /// + /// - `input`: The input data buffer. + /// - `output`: The output buffer to write the hash result to. + #[unstable_hostfn] + fn hash_sha2_256(input: &[u8], output: &mut [u8; 32]); + + /// Computes the blake2_256 32-bit hash on the given input buffer. + /// + /// - The `input` and `output` buffer may overlap. + /// - The output buffer is expected to hold at least 32 bits. + /// - It is the callers responsibility to provide an output buffer that is large enough to hold + /// the expected amount of bytes returned by the hash function. + /// + /// # Parameters + /// */ + /// - `input`: The input data buffer. + /// - `output`: The output buffer to write the hash result to. + #[unstable_hostfn] + fn hash_blake2_256(input: &[u8], output: &mut [u8; 32]); + + /// Computes the blake2_128 16-bit hash on the given input buffer. + /// + /// - The `input` and `output` buffer may overlap. + /// - The output buffer is expected to hold at least 16 bits. + /// - It is the callers responsibility to provide an output buffer that is large enough to hold + /// the expected amount of bytes returned by the hash function. + /// # Parameters + /// + /// - `input`: The input data buffer. + /// - `output`: The output buffer to write the hash result to. + #[unstable_hostfn] + fn hash_blake2_128(input: &[u8], output: &mut [u8; 16]); /// Checks whether a specified address belongs to a contract. /// @@ -583,7 +612,7 @@ pub trait HostFn: private::Sealed { /// # Return /// /// Returns `true` if the address belongs to a contract. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn is_contract(address: &[u8; 20]) -> bool; /// Lock a new delegate dependency to the contract. @@ -595,7 +624,7 @@ pub trait HostFn: private::Sealed { /// /// - `code_hash`: The code hash of the dependency. Should be decodable as an `T::Hash`. Traps /// otherwise. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn lock_delegate_dependency(code_hash: &[u8; 32]); /// Stores the minimum balance (a.k.a. existential deposit) into the supplied buffer. @@ -603,7 +632,7 @@ pub trait HostFn: private::Sealed { /// # Parameters /// /// - `output`: A reference to the output data buffer to write the minimum balance. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn minimum_balance(output: &mut [u8; 32]); /// Retrieve the code hash of the currently executing contract. @@ -611,7 +640,7 @@ pub trait HostFn: private::Sealed { /// # Parameters /// /// - `output`: A reference to the output data buffer to write the code hash. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn own_code_hash(output: &mut [u8; 32]); /// Replace the contract code at the specified address with new code. @@ -642,7 +671,7 @@ pub trait HostFn: private::Sealed { /// # Panics /// /// Panics if there is no code on-chain with the specified hash. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn set_code_hash(code_hash: &[u8; 32]); /// Verify a sr25519 signature @@ -655,7 +684,7 @@ pub trait HostFn: private::Sealed { /// # Errors /// /// - [Sr25519VerifyFailed][`crate::ReturnErrorCode::Sr25519VerifyFailed] - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn sr25519_verify(signature: &[u8; 64], message: &[u8], pub_key: &[u8; 32]) -> Result; /// Retrieve and remove the value under the given key from storage. @@ -667,7 +696,7 @@ pub trait HostFn: private::Sealed { /// # Errors /// /// [KeyNotFound][`crate::ReturnErrorCode::KeyNotFound] - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn take_storage(flags: StorageFlags, key: &[u8], output: &mut &mut [u8]) -> Result; /// Remove the calling account and transfer remaining **free** balance. @@ -685,7 +714,7 @@ pub trait HostFn: private::Sealed { /// - The contract is live i.e is already on the call stack. /// - Failed to send the balance to the beneficiary. /// - The deletion queue is full. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn terminate(beneficiary: &[u8; 20]) -> !; /// Removes the delegate dependency from the contract. @@ -696,7 +725,7 @@ pub trait HostFn: private::Sealed { /// /// - `code_hash`: The code hash of the dependency. Should be decodable as an `T::Hash`. Traps /// otherwise. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn unlock_delegate_dependency(code_hash: &[u8; 32]); /// Stores the amount of weight left into the supplied buffer. @@ -707,7 +736,7 @@ pub trait HostFn: private::Sealed { /// # Parameters /// /// - `output`: A reference to the output data buffer to write the weight left. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn weight_left(output: &mut &mut [u8]); /// Execute an XCM program locally, using the contract's address as the origin. @@ -724,7 +753,7 @@ pub trait HostFn: private::Sealed { /// /// Returns `Error::Success` when the XCM execution attempt is successful. When the XCM /// execution fails, `ReturnCode::XcmExecutionFailed` is returned - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn xcm_execute(msg: &[u8]) -> Result; /// Send an XCM program from the contract to the specified destination. @@ -742,7 +771,7 @@ pub trait HostFn: private::Sealed { /// /// Returns `ReturnCode::Success` when the message was successfully sent. When the XCM /// execution fails, `ReturnErrorCode::XcmSendFailed` is returned. - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn xcm_send(dest: &[u8], msg: &[u8], output: &mut [u8; 32]) -> Result; } diff --git a/substrate/frame/revive/uapi/src/host/riscv64.rs b/substrate/frame/revive/uapi/src/host/riscv64.rs index 9f080ddbfbf5..8376263b2348 100644 --- a/substrate/frame/revive/uapi/src/host/riscv64.rs +++ b/substrate/frame/revive/uapi/src/host/riscv64.rs @@ -18,6 +18,7 @@ use crate::{ host::{CallFlags, HostFn, HostFnImpl, Result, StorageFlags}, ReturnFlags, }; +use pallet_revive_proc_macro::unstable_hostfn; mod sys { use crate::ReturnCode; @@ -137,38 +138,6 @@ mod sys { } } -/// A macro to implement all Host functions with a signature of `fn(&mut [u8; n])`. -macro_rules! impl_wrapper_for { - (@impl_fn $name:ident, $n: literal) => { - fn $name(output: &mut [u8; $n]) { - unsafe { sys::$name(output.as_mut_ptr()) } - } - }; - - () => {}; - - ([u8; $n: literal] => $($name:ident),*; $($tail:tt)*) => { - $(impl_wrapper_for!(@impl_fn $name, $n);)* - impl_wrapper_for!($($tail)*); - }; -} - -macro_rules! impl_hash_fn { - ( $name:ident, $bytes_result:literal ) => { - paste::item! { - fn [](input: &[u8], output: &mut [u8; $bytes_result]) { - unsafe { - sys::[]( - input.as_ptr(), - input.len() as u32, - output.as_mut_ptr(), - ) - } - } - } - }; -} - #[inline(always)] fn extract_from_slice(output: &mut &mut [u8], new_len: usize) { debug_assert!(new_len <= output.len()); @@ -400,21 +369,45 @@ impl HostFn for HostFnImpl { panic!("seal_return does not return"); } - impl_wrapper_for! { - [u8; 32] => balance, value_transferred, now, chain_id; - [u8; 20] => address, caller, origin; + fn balance(output: &mut [u8; 32]) { + unsafe { sys::balance(output.as_mut_ptr()) } + } + + fn value_transferred(output: &mut [u8; 32]) { + unsafe { sys::value_transferred(output.as_mut_ptr()) } + } + + fn now(output: &mut [u8; 32]) { + unsafe { sys::now(output.as_mut_ptr()) } + } + + fn chain_id(output: &mut [u8; 32]) { + unsafe { sys::chain_id(output.as_mut_ptr()) } } - #[cfg(feature = "unstable-api")] - impl_wrapper_for! { - [u8; 32] => block_number, minimum_balance; + fn address(output: &mut [u8; 20]) { + unsafe { sys::address(output.as_mut_ptr()) } + } + + fn caller(output: &mut [u8; 20]) { + unsafe { sys::caller(output.as_mut_ptr()) } + } + + fn origin(output: &mut [u8; 20]) { + unsafe { sys::origin(output.as_mut_ptr()) } + } + + fn block_number(output: &mut [u8; 32]) { + unsafe { sys::block_number(output.as_mut_ptr()) } } fn weight_to_fee(ref_time_limit: u64, proof_size_limit: u64, output: &mut [u8; 32]) { unsafe { sys::weight_to_fee(ref_time_limit, proof_size_limit, output.as_mut_ptr()) }; } - impl_hash_fn!(keccak_256, 32); + fn hash_keccak_256(input: &[u8], output: &mut [u8; 32]) { + unsafe { sys::hash_keccak_256(input.as_ptr(), input.len() as u32, output.as_mut_ptr()) } + } fn get_immutable_data(output: &mut &mut [u8]) { let mut output_len = output.len() as u32; @@ -454,12 +447,12 @@ impl HostFn for HostFnImpl { unsafe { sys::ref_time_left() } } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn block_hash(block_number_ptr: &[u8; 32], output: &mut [u8; 32]) { unsafe { sys::block_hash(block_number_ptr.as_ptr(), output.as_mut_ptr()) }; } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn call_chain_extension(func_id: u32, input: &[u8], mut output: Option<&mut &mut [u8]>) -> u32 { let (output_ptr, mut output_len) = ptr_len_or_sentinel(&mut output); let ret_code = { @@ -485,43 +478,43 @@ impl HostFn for HostFnImpl { unsafe { sys::call_data_copy(output.as_mut_ptr(), len, offset) }; } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn call_runtime(call: &[u8]) -> Result { let ret_code = unsafe { sys::call_runtime(call.as_ptr(), call.len() as u32) }; ret_code.into() } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn caller_is_origin() -> bool { let ret_val = unsafe { sys::caller_is_origin() }; ret_val.into_bool() } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn caller_is_root() -> u32 { unsafe { sys::caller_is_root() }.into_u32() } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn clear_storage(flags: StorageFlags, key: &[u8]) -> Option { let ret_code = unsafe { sys::clear_storage(flags.bits(), key.as_ptr(), key.len() as u32) }; ret_code.into() } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn contains_storage(flags: StorageFlags, key: &[u8]) -> Option { let ret_code = unsafe { sys::contains_storage(flags.bits(), key.as_ptr(), key.len() as u32) }; ret_code.into() } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn debug_message(str: &[u8]) -> Result { let ret_code = unsafe { sys::debug_message(str.as_ptr(), str.len() as u32) }; ret_code.into() } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn ecdsa_recover( signature: &[u8; 65], message_hash: &[u8; 32], @@ -533,41 +526,54 @@ impl HostFn for HostFnImpl { ret_code.into() } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn ecdsa_to_eth_address(pubkey: &[u8; 33], output: &mut [u8; 20]) -> Result { let ret_code = unsafe { sys::ecdsa_to_eth_address(pubkey.as_ptr(), output.as_mut_ptr()) }; ret_code.into() } - #[cfg(feature = "unstable-api")] - impl_hash_fn!(sha2_256, 32); - #[cfg(feature = "unstable-api")] - impl_hash_fn!(blake2_256, 32); - #[cfg(feature = "unstable-api")] - impl_hash_fn!(blake2_128, 16); + #[unstable_hostfn] + fn hash_sha2_256(input: &[u8], output: &mut [u8; 32]) { + unsafe { sys::hash_sha2_256(input.as_ptr(), input.len() as u32, output.as_mut_ptr()) } + } + + #[unstable_hostfn] + fn hash_blake2_256(input: &[u8], output: &mut [u8; 32]) { + unsafe { sys::hash_blake2_256(input.as_ptr(), input.len() as u32, output.as_mut_ptr()) } + } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] + fn hash_blake2_128(input: &[u8], output: &mut [u8; 16]) { + unsafe { sys::hash_blake2_128(input.as_ptr(), input.len() as u32, output.as_mut_ptr()) } + } + + #[unstable_hostfn] fn is_contract(address: &[u8; 20]) -> bool { let ret_val = unsafe { sys::is_contract(address.as_ptr()) }; ret_val.into_bool() } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn lock_delegate_dependency(code_hash: &[u8; 32]) { unsafe { sys::lock_delegate_dependency(code_hash.as_ptr()) } } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] + fn minimum_balance(output: &mut [u8; 32]) { + unsafe { sys::minimum_balance(output.as_mut_ptr()) } + } + + #[unstable_hostfn] fn own_code_hash(output: &mut [u8; 32]) { unsafe { sys::own_code_hash(output.as_mut_ptr()) } } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn set_code_hash(code_hash: &[u8; 32]) { unsafe { sys::set_code_hash(code_hash.as_ptr()) } } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn sr25519_verify(signature: &[u8; 64], message: &[u8], pub_key: &[u8; 32]) -> Result { let ret_code = unsafe { sys::sr25519_verify( @@ -580,7 +586,7 @@ impl HostFn for HostFnImpl { ret_code.into() } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn take_storage(flags: StorageFlags, key: &[u8], output: &mut &mut [u8]) -> Result { let mut output_len = output.len() as u32; let ret_code = { @@ -598,31 +604,31 @@ impl HostFn for HostFnImpl { ret_code.into() } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn terminate(beneficiary: &[u8; 20]) -> ! { unsafe { sys::terminate(beneficiary.as_ptr()) } panic!("terminate does not return"); } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn unlock_delegate_dependency(code_hash: &[u8; 32]) { unsafe { sys::unlock_delegate_dependency(code_hash.as_ptr()) } } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn weight_left(output: &mut &mut [u8]) { let mut output_len = output.len() as u32; unsafe { sys::weight_left(output.as_mut_ptr(), &mut output_len) } extract_from_slice(output, output_len as usize) } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn xcm_execute(msg: &[u8]) -> Result { let ret_code = unsafe { sys::xcm_execute(msg.as_ptr(), msg.len() as _) }; ret_code.into() } - #[cfg(feature = "unstable-api")] + #[unstable_hostfn] fn xcm_send(dest: &[u8], msg: &[u8], output: &mut [u8; 32]) -> Result { let ret_code = unsafe { sys::xcm_send( diff --git a/substrate/frame/revive/uapi/src/lib.rs b/substrate/frame/revive/uapi/src/lib.rs index 14a5e3f28889..ef1798b4bf61 100644 --- a/substrate/frame/revive/uapi/src/lib.rs +++ b/substrate/frame/revive/uapi/src/lib.rs @@ -17,6 +17,7 @@ //! Refer to substrate FRAME contract module for more documentation. #![no_std] +#![cfg_attr(docsrs, feature(doc_cfg))] mod flags; pub use flags::*;