From b243a4b4aa190cdc023a515b3f0a6ee52a1ec46a Mon Sep 17 00:00:00 2001 From: Peter White Date: Mon, 26 Feb 2024 23:36:07 -0700 Subject: [PATCH 01/19] feat: PoC of chain-extension reimplementing call_runtime --- Cargo.toml | 4 + demo-contracts/.gitignore | 9 + demo-contracts/Cargo.toml | 32 ++ demo-contracts/lib.rs | 353 ++++++++++++++++++++ runtime/src/contracts_config.rs | 4 +- runtime/src/extensions/mod.rs | 1 + runtime/src/extensions/pop_api_extension.rs | 119 +++++++ runtime/src/lib.rs | 1 + 8 files changed, 521 insertions(+), 2 deletions(-) create mode 100755 demo-contracts/.gitignore create mode 100755 demo-contracts/Cargo.toml create mode 100755 demo-contracts/lib.rs create mode 100644 runtime/src/extensions/mod.rs create mode 100644 runtime/src/extensions/pop_api_extension.rs diff --git a/Cargo.toml b/Cargo.toml index 47be413b..9aadd630 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,10 @@ members = [ "node", "runtime", ] +exclude = [ + "demo-contracts" +] + resolver = "2" [workspace.dependencies] diff --git a/demo-contracts/.gitignore b/demo-contracts/.gitignore new file mode 100755 index 00000000..8de8f877 --- /dev/null +++ b/demo-contracts/.gitignore @@ -0,0 +1,9 @@ +# Ignore build artifacts from the local tests sub-crate. +/target/ + +# Ignore backup files creates by cargo fmt. +**/*.rs.bk + +# Remove Cargo.lock when creating an executable, leave it for libraries +# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock +Cargo.lock diff --git a/demo-contracts/Cargo.toml b/demo-contracts/Cargo.toml new file mode 100755 index 00000000..88ab4506 --- /dev/null +++ b/demo-contracts/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "pop_api_extension_demo" +version = "0.1.0" +authors = ["[your_name] <[your_email]>"] +edition = "2021" + +[dependencies] +ink = { version = "4.3.0", default-features = false } + +scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } +scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } + +sp-io = { version = "23.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } +sp-runtime = { version = "24.0.0", default-features = false } + +[dev-dependencies] +ink_e2e = "4.3.0" + +[lib] +path = "lib.rs" + +[features] +default = ["std"] +std = [ + "ink/std", + "scale/std", + "scale-info/std", + "sp-runtime/std", + "sp-io/std", +] +ink-as-dependency = [] +e2e-tests = [] diff --git a/demo-contracts/lib.rs b/demo-contracts/lib.rs new file mode 100755 index 00000000..fe09bfe4 --- /dev/null +++ b/demo-contracts/lib.rs @@ -0,0 +1,353 @@ +#![cfg_attr(not(feature = "std"), no_std, no_main)] + + +use ink::{ + env::Environment, + prelude::vec::Vec, +}; + +use ink::primitives::AccountId; +use sp_runtime::MultiAddress; + +/// A part of the runtime dispatchable API. +/// +/// For now, `ink!` doesn't provide any support for exposing the real `RuntimeCall` enum, +/// which fully describes the composed API of all the pallets present in runtime. Hence, +/// in order to use `call-runtime` functionality, we have to provide at least a partial +/// object, which correctly encodes the target extrinsic. +/// +/// You can investigate the full `RuntimeCall` definition by either expanding +/// `construct_runtime!` macro application or by using secondary tools for reading chain +/// metadata, like `subxt`. +#[derive(scale::Encode)] +enum RuntimeCall { + /// This index can be found by investigating runtime configuration. You can check the + /// pallet order inside `construct_runtime!` block and read the position of your + /// pallet (0-based). + /// + /// + /// [See here for more.](https://substrate.stackexchange.com/questions/778/how-to-get-pallet-index-u8-of-a-pallet-in-runtime) + #[codec(index = 10)] + Balances(BalancesCall), +} + +#[derive(scale::Encode)] +enum BalancesCall { + /// This index can be found by investigating the pallet dispatchable API. In your + /// pallet code, look for `#[pallet::call]` section and check + /// `#[pallet::call_index(x)]` attribute of the call. If these attributes are + /// missing, use source-code order (0-based). + #[codec(index = 8)] + ForceSetBalance { + who: MultiAddress, + #[codec(compact)] + new_free: u128, + }, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] +#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] +pub enum PopApiError { + TotalSupplyFailed, +} + +pub type Result = core::result::Result; + +use scale; +impl From for PopApiError { + fn from(_: scale::Error) -> Self { + panic!("encountered unexpected invalid SCALE encoding") + } +} + +/// This is an example of how an ink! contract may call the Substrate +/// runtime function `RandomnessCollectiveFlip::random_seed`. See the +/// file `runtime/chain-extension-example.rs` for that implementation. +/// +/// Here we define the operations to interact with the Substrate runtime. +#[ink::chain_extension] +pub trait PopApi { + type ErrorCode = PopApiError; + + /// Note: this gives the operation a corresponding `func_id` (1101 in this case), + /// and the chain-side chain extension will get the `func_id` to do further + /// operations. + #[ink(extension = 0xfecb)] + fn call_runtime(call: RuntimeCall) -> Result>; +} + +impl ink::env::chain_extension::FromStatusCode for PopApiError { + fn from_status_code(status_code: u32) -> core::result::Result<(), Self> { + match status_code { + 0 => Ok(()), + 1 => Err(Self::TotalSupplyFailed), + _ => panic!("encountered unknown status code"), + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] +pub enum CustomEnvironment {} + +impl Environment for CustomEnvironment { + const MAX_EVENT_TOPICS: usize = + ::MAX_EVENT_TOPICS; + + type AccountId = ::AccountId; + type Balance = ::Balance; + type Hash = ::Hash; + type BlockNumber = ::BlockNumber; + type Timestamp = ::Timestamp; + + type ChainExtension = PopApi; +} + +#[ink::contract(env = crate::CustomEnvironment)] +mod pop_api_extension_demo { + use crate::{ + BalancesCall, + RuntimeCall, + }; + + use super::PopApiError; + + use ink::env::Error as EnvError; + + /// A trivial contract with a single message, that uses `call-runtime` API for + /// performing native token transfer. + #[ink(storage)] + #[derive(Default)] + pub struct PopApiExtensionDemo; + + impl From for PopApiError { + fn from(e: EnvError) -> Self { + match e { + EnvError::CallRuntimeFailed => PopApiError::TotalSupplyFailed, + _ => panic!("Unexpected error from `pallet-contracts`."), + } + } + } + + // impl From for RuntimeError { + // fn from(e: EnvError) -> Self { + // use ink::env::ReturnErrorCode; + // match e { + // EnvError::ReturnError(ReturnErrorCode::CallRuntimeFailed) => { + // RuntimeError::CallRuntimeFailed + // } + // _ => panic!("Unexpected error from `pallet-contracts`."), + // } + // } + // } + + impl PopApiExtensionDemo { + /// The constructor is `payable`, so that during instantiation it can be given + /// some tokens that will be further transferred with + /// `transfer_through_runtime` message. + #[ink(constructor, payable)] + pub fn new() -> Self { + Default::default() + } + + /// Tries to transfer `value` from the contract's balance to `receiver`. + /// + /// Fails if: + /// - called in the off-chain environment + /// - the chain forbids contracts to call `Balances::transfer` (`CallFilter` is + /// too restrictive) + /// - after the transfer, `receiver` doesn't have at least existential deposit + /// - the contract doesn't have enough balance + #[ink(message)] + pub fn transfer_through_runtime( + &mut self, + receiver: AccountId, + value: Balance, + ) { + let call = RuntimeCall::Balances(BalancesCall::ForceSetBalance { + who: receiver.into(), + new_free: value, + }); + self.env().extension().call_runtime(call); + + } + + // /// Tries to trigger `call_runtime` API with rubbish data. + // /// + // /// # Note + // /// + // /// This message is for testing purposes only. + // #[ink(message)] + // pub fn call_nonexistent_extrinsic(&mut self) -> Result<(), PopApiError> { + // self.env().call_runtime(&()).map_err(Into::into) + // } + } + + #[cfg(all(test, feature = "e2e-tests"))] + mod e2e_tests { + use super::*; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; + + use ink::{ + env::{ + test::default_accounts, + DefaultEnvironment, + }, + primitives::AccountId, + }; + + type E2EResult = Result>; + + /// The base number of indivisible units for balances on the + /// `substrate-contracts-node`. + const UNIT: Balance = 1_000_000_000_000; + + /// The contract will be given 1000 tokens during instantiation. + const CONTRACT_BALANCE: Balance = 1_000 * UNIT; + + /// The receiver will get enough funds to have the required existential deposit. + /// + /// If your chain has this threshold higher, increase the transfer value. + const TRANSFER_VALUE: Balance = 1 / 10 * UNIT; + + /// An amount that is below the existential deposit, so that a transfer to an + /// empty account fails. + /// + /// Must not be zero, because such an operation would be a successful no-op. + const INSUFFICIENT_TRANSFER_VALUE: Balance = 1; + + /// Positive case scenario: + /// - the call is valid + /// - the call execution succeeds + #[ink_e2e::test] + async fn transfer_with_call_runtime_works( + mut client: Client, + ) -> E2EResult<()> { + // given + let mut constructor = RuntimeCallerRef::new(); + let contract = client + .instantiate("call-runtime", &ink_e2e::alice(), &mut constructor) + .value(CONTRACT_BALANCE) + .submit() + .await + .expect("instantiate failed"); + let mut call_builder = contract.call_builder::(); + + let receiver: AccountId = default_accounts::().bob; + + let contract_balance_before = client + .free_balance(contract.account_id) + .await + .expect("Failed to get account balance"); + let receiver_balance_before = client + .free_balance(receiver) + .await + .expect("Failed to get account balance"); + + // when + let transfer_message = + call_builder.transfer_through_runtime(receiver, TRANSFER_VALUE); + + let call_res = client + .call(&ink_e2e::alice(), &transfer_message) + .submit() + .await + .expect("call failed"); + + assert!(call_res.return_value().is_ok()); + + // then + let contract_balance_after = client + .free_balance(contract.account_id) + .await + .expect("Failed to get account balance"); + let receiver_balance_after = client + .free_balance(receiver) + .await + .expect("Failed to get account balance"); + + assert_eq!( + contract_balance_before, + contract_balance_after + TRANSFER_VALUE + ); + assert_eq!( + receiver_balance_before, + receiver_balance_after - TRANSFER_VALUE + ); + + Ok(()) + } + + /// Negative case scenario: + /// - the call is valid + /// - the call execution fails + #[ink_e2e::test] + async fn transfer_with_call_runtime_fails_when_execution_fails< + Client: E2EBackend, + >( + mut client: Client, + ) -> E2EResult<()> { + // given + let mut constructor = RuntimeCallerRef::new(); + let contract = client + .instantiate("call-runtime", &ink_e2e::alice(), &mut constructor) + .value(CONTRACT_BALANCE) + .submit() + .await + .expect("instantiate failed"); + let mut call_builder = contract.call_builder::(); + + let receiver: AccountId = default_accounts::().bob; + + // when + let transfer_message = call_builder + .transfer_through_runtime(receiver, INSUFFICIENT_TRANSFER_VALUE); + + let call_res = client + .call(&ink_e2e::alice(), &transfer_message) + .dry_run() + .await? + .return_value(); + + // then + assert!(matches!(call_res, Err(RuntimeError::CallRuntimeFailed))); + + Ok(()) + } + + /// Negative case scenario: + /// - the call is invalid + #[ink_e2e::test] + async fn transfer_with_call_runtime_fails_when_call_is_invalid< + Client: E2EBackend, + >( + mut client: Client, + ) -> E2EResult<()> { + // given + let mut constructor = RuntimeCallerRef::new(); + let contract = client + .instantiate("call-runtime", &ink_e2e::alice(), &mut constructor) + .value(CONTRACT_BALANCE) + .submit() + .await + .expect("instantiate failed"); + let mut call_builder = contract.call_builder::(); + + // when + let transfer_message = call_builder.call_nonexistent_extrinsic(); + + let call_res = client + .call(&ink_e2e::alice(), &transfer_message) + .dry_run() + .await; + + // then + assert!(call_res.is_err()); + + Ok(()) + } + } +} \ No newline at end of file diff --git a/runtime/src/contracts_config.rs b/runtime/src/contracts_config.rs index 3bae4a2b..534a2d05 100644 --- a/runtime/src/contracts_config.rs +++ b/runtime/src/contracts_config.rs @@ -1,5 +1,5 @@ use crate::{ - deposit, Balance, Balances, BalancesCall, Perbill, Runtime, RuntimeCall, RuntimeEvent, + deposit, extensions, Balance, Balances, BalancesCall, Perbill, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason, Timestamp, }; use frame_support::{ @@ -63,7 +63,7 @@ impl pallet_contracts::Config for Runtime { type CallStack = [pallet_contracts::Frame; 23]; type WeightPrice = pallet_transaction_payment::Pallet; type WeightInfo = pallet_contracts::weights::SubstrateWeight; - type ChainExtension = (); + type ChainExtension = extensions::pop_api_extension::PopApiExtension; type Schedule = Schedule; type AddressGenerator = pallet_contracts::DefaultAddressGenerator; // This node is geared towards development and testing of contracts. diff --git a/runtime/src/extensions/mod.rs b/runtime/src/extensions/mod.rs new file mode 100644 index 00000000..3d1a6f9d --- /dev/null +++ b/runtime/src/extensions/mod.rs @@ -0,0 +1 @@ +pub mod pop_api_extension; \ No newline at end of file diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs new file mode 100644 index 00000000..594f01b4 --- /dev/null +++ b/runtime/src/extensions/pop_api_extension.rs @@ -0,0 +1,119 @@ +use codec::{ + Decode, + Encode, + MaxEncodedLen, +}; +use frame_support::{ + dispatch::RawOrigin, + pallet_prelude::*, +}; + +use log::{error, log, trace}; + +use pallet_contracts::chain_extension::{ + ChainExtension, + Environment, + Ext, + InitState, + RetVal, + SysConfig, +}; +use sp_core::crypto::UncheckedFrom; +use sp_runtime::{ + traits::{ + Dispatchable, Saturating, StaticLookup, Zero + }, + DispatchError, +}; + +use crate::{RuntimeCall, RuntimeOrigin}; + + +#[derive(Default)] +pub struct PopApiExtension; + +fn convert_err(err_msg: &'static str) -> impl FnOnce(DispatchError) -> DispatchError { + move |err| { + trace!( + target: "runtime", + "Pop API failed:{:?}", + err + ); + DispatchError::Other(err_msg) + } +} + +/// We're using enums for function IDs because contrary to raw u16 it enables +/// exhaustive matching, which results in cleaner code. +#[derive(Debug)] +enum FuncId { + CallRuntime +} + +impl TryFrom for FuncId { + type Error = DispatchError; + + fn try_from(func_id: u16) -> Result { + let id = match func_id { + 0xfecb => Self::CallRuntime, + _ => { + error!("Called an unregistered `func_id`: {:}", func_id); + return Err(DispatchError::Other("Unimplemented func_id")) + } + }; + + Ok(id) + } +} +const LOG_TARGET: &str = "runtime::contracts"; +fn call_runtime(env: Environment) -> Result<(), DispatchError> +where + T: pallet_contracts::Config, + ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, + E: Ext, +{ + log::debug!(target:LOG_TARGET, "popapi call_runtime"); + let mut env = env.buf_in_buf_out(); + + // TODO: calculate weight and charge fees + + // let base_weight = ::WeightInfo::transfer(); + // debug_message weight is a good approximation of the additional overhead of going + // from contract layer to substrate layer. + let len = env.in_len(); + let mut call: RuntimeCall = env.read_as_unbounded(len)?; + log::debug!(target:LOG_TARGET, "popapi dispatch {:?}", call); + + //TODO: properly set the origin to the sender + let sender = env.ext().caller(); + let origin: RuntimeOrigin = RawOrigin::Root.into(); + let result = call.dispatch(origin); + log::debug!(target:LOG_TARGET, "pop api trace {:?}", result); + Ok(()) +} + + +impl ChainExtension for PopApiExtension +where + T: pallet_contracts::Config, + ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, +{ + fn call( + &mut self, + env: Environment, + ) -> Result + where + E: Ext, + ::AccountId: + UncheckedFrom<::Hash> + AsRef<[u8]>, + { + + let func_id = FuncId::try_from(env.func_id())?; + log::debug!(target:LOG_TARGET, "popapi call_hit id: {:?}", func_id); + match func_id { + FuncId::CallRuntime => call_runtime::(env)?, + } + + Ok(RetVal::Converging(0)) + } +} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index fc6550b2..6219a15b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -9,6 +9,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod assets_config; mod contracts_config; mod weights; +mod extensions; pub mod xcm_config; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; From da2abe4bb7c3e4b677787207bc64aa746c13a765 Mon Sep 17 00:00:00 2001 From: Peter White Date: Tue, 27 Feb 2024 14:28:07 -0700 Subject: [PATCH 02/19] feat: use proper origin for pop api chain extension, start weight calculations --- demo-contracts/lib.rs | 106 ++++---------------- runtime/src/extensions/pop_api_extension.rs | 80 +++++++++------ 2 files changed, 67 insertions(+), 119 deletions(-) diff --git a/demo-contracts/lib.rs b/demo-contracts/lib.rs index fe09bfe4..8e114470 100755 --- a/demo-contracts/lib.rs +++ b/demo-contracts/lib.rs @@ -37,6 +37,12 @@ enum BalancesCall { /// pallet code, look for `#[pallet::call]` section and check /// `#[pallet::call_index(x)]` attribute of the call. If these attributes are /// missing, use source-code order (0-based). + #[codec(index = 3)] + TransferKeepAlive { + dest: MultiAddress, + #[codec(compact)] + value: u128, + }, #[codec(index = 8)] ForceSetBalance { who: MultiAddress, @@ -163,24 +169,14 @@ mod pop_api_extension_demo { &mut self, receiver: AccountId, value: Balance, - ) { - let call = RuntimeCall::Balances(BalancesCall::ForceSetBalance { - who: receiver.into(), - new_free: value, + ) { + let call = RuntimeCall::Balances(BalancesCall::TransferKeepAlive { + dest: receiver.into(), + value: value, }); self.env().extension().call_runtime(call); } - - // /// Tries to trigger `call_runtime` API with rubbish data. - // /// - // /// # Note - // /// - // /// This message is for testing purposes only. - // #[ink(message)] - // pub fn call_nonexistent_extrinsic(&mut self) -> Result<(), PopApiError> { - // self.env().call_runtime(&()).map_err(Into::into) - // } } #[cfg(all(test, feature = "e2e-tests"))] @@ -236,10 +232,12 @@ mod pop_api_extension_demo { .expect("instantiate failed"); let mut call_builder = contract.call_builder::(); - let receiver: AccountId = default_accounts::().bob; + let accounts = default_accounts::(); + + let receiver: AccountId = accounts.bob; - let contract_balance_before = client - .free_balance(contract.account_id) + let sender_balance_before = client + .free_balance(accounts.alice) .await .expect("Failed to get account balance"); let receiver_balance_before = client @@ -260,8 +258,8 @@ mod pop_api_extension_demo { assert!(call_res.return_value().is_ok()); // then - let contract_balance_after = client - .free_balance(contract.account_id) + let sender_balance_after = client + .free_balance(accounts.alice) .await .expect("Failed to get account balance"); let receiver_balance_after = client @@ -281,73 +279,5 @@ mod pop_api_extension_demo { Ok(()) } - /// Negative case scenario: - /// - the call is valid - /// - the call execution fails - #[ink_e2e::test] - async fn transfer_with_call_runtime_fails_when_execution_fails< - Client: E2EBackend, - >( - mut client: Client, - ) -> E2EResult<()> { - // given - let mut constructor = RuntimeCallerRef::new(); - let contract = client - .instantiate("call-runtime", &ink_e2e::alice(), &mut constructor) - .value(CONTRACT_BALANCE) - .submit() - .await - .expect("instantiate failed"); - let mut call_builder = contract.call_builder::(); - - let receiver: AccountId = default_accounts::().bob; - - // when - let transfer_message = call_builder - .transfer_through_runtime(receiver, INSUFFICIENT_TRANSFER_VALUE); - - let call_res = client - .call(&ink_e2e::alice(), &transfer_message) - .dry_run() - .await? - .return_value(); - - // then - assert!(matches!(call_res, Err(RuntimeError::CallRuntimeFailed))); - - Ok(()) - } - - /// Negative case scenario: - /// - the call is invalid - #[ink_e2e::test] - async fn transfer_with_call_runtime_fails_when_call_is_invalid< - Client: E2EBackend, - >( - mut client: Client, - ) -> E2EResult<()> { - // given - let mut constructor = RuntimeCallerRef::new(); - let contract = client - .instantiate("call-runtime", &ink_e2e::alice(), &mut constructor) - .value(CONTRACT_BALANCE) - .submit() - .await - .expect("instantiate failed"); - let mut call_builder = contract.call_builder::(); - - // when - let transfer_message = call_builder.call_nonexistent_extrinsic(); - - let call_res = client - .call(&ink_e2e::alice(), &transfer_message) - .dry_run() - .await; - - // then - assert!(call_res.is_err()); - - Ok(()) - } - } + } } \ No newline at end of file diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs index 594f01b4..4aed9808 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions/pop_api_extension.rs @@ -1,14 +1,9 @@ -use codec::{ - Decode, - Encode, - MaxEncodedLen, -}; use frame_support::{ - dispatch::RawOrigin, + dispatch::{GetDispatchInfo, PostDispatchInfo, RawOrigin}, pallet_prelude::*, }; -use log::{error, log, trace}; +use log; use pallet_contracts::chain_extension::{ ChainExtension, @@ -18,24 +13,23 @@ use pallet_contracts::chain_extension::{ RetVal, SysConfig, }; + use sp_core::crypto::UncheckedFrom; use sp_runtime::{ traits::{ - Dispatchable, Saturating, StaticLookup, Zero + Dispatchable }, DispatchError, }; -use crate::{RuntimeCall, RuntimeOrigin}; - - +const LOG_TARGET: &str = "popapi::extension"; #[derive(Default)] pub struct PopApiExtension; fn convert_err(err_msg: &'static str) -> impl FnOnce(DispatchError) -> DispatchError { move |err| { - trace!( - target: "runtime", + log::trace!( + target: LOG_TARGET, "Pop API failed:{:?}", err ); @@ -43,8 +37,6 @@ fn convert_err(err_msg: &'static str) -> impl FnOnce(DispatchError) -> DispatchE } } -/// We're using enums for function IDs because contrary to raw u16 it enables -/// exhaustive matching, which results in cleaner code. #[derive(Debug)] enum FuncId { CallRuntime @@ -57,7 +49,7 @@ impl TryFrom for FuncId { let id = match func_id { 0xfecb => Self::CallRuntime, _ => { - error!("Called an unregistered `func_id`: {:}", func_id); + log::error!("Called an unregistered `func_id`: {:}", func_id); return Err(DispatchError::Other("Unimplemented func_id")) } }; @@ -65,30 +57,52 @@ impl TryFrom for FuncId { Ok(id) } } -const LOG_TARGET: &str = "runtime::contracts"; -fn call_runtime(env: Environment) -> Result<(), DispatchError> + +fn dispatch(env: Environment) -> Result<(), DispatchError> where - T: pallet_contracts::Config, + T: pallet_contracts::Config + frame_system::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, + ::RuntimeCall: Parameter + + Dispatchable< + RuntimeOrigin = ::RuntimeOrigin, + PostInfo = PostDispatchInfo, + > + GetDispatchInfo + + From>, E: Ext, { - log::debug!(target:LOG_TARGET, "popapi call_runtime"); let mut env = env.buf_in_buf_out(); - // TODO: calculate weight and charge fees + // charge max weight before reading contract memory + // TODO: causing "1010: block limits exhausted" error + // let weight_limit = env.ext().gas_meter().gas_left(); + // let charged_weight = env.charge_weight(weight_limit)?; - // let base_weight = ::WeightInfo::transfer(); - // debug_message weight is a good approximation of the additional overhead of going + // TODO: debug_message weight is a good approximation of the additional overhead of going // from contract layer to substrate layer. + + // input length let len = env.in_len(); - let mut call: RuntimeCall = env.read_as_unbounded(len)?; - log::debug!(target:LOG_TARGET, "popapi dispatch {:?}", call); + let call: ::RuntimeCall = env.read_as_unbounded(len)?; + + log::trace!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); - //TODO: properly set the origin to the sender let sender = env.ext().caller(); - let origin: RuntimeOrigin = RawOrigin::Root.into(); + let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); + + // TODO: uncomment once charged_weight is fixed + // let actual_weight = call.get_dispatch_info().weight; + // env.adjust_weight(charged_weight, actual_weight); + let result = call.dispatch(origin); - log::debug!(target:LOG_TARGET, "pop api trace {:?}", result); + match result { + Ok(info) => { + log::trace!(target:LOG_TARGET, "dispatch success, actual weight: {:?}", info.actual_weight); + } + Err(err) => { + log::trace!(target:LOG_TARGET, "dispatch failed: error: {:?}", err.error); + return Err(err.error); + } + } Ok(()) } @@ -97,6 +111,12 @@ impl ChainExtension for PopApiExtension where T: pallet_contracts::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, + ::RuntimeCall: Parameter + + Dispatchable< + RuntimeOrigin = ::RuntimeOrigin, + PostInfo = PostDispatchInfo, + > + GetDispatchInfo + + From>, { fn call( &mut self, @@ -107,11 +127,9 @@ where ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, { - let func_id = FuncId::try_from(env.func_id())?; - log::debug!(target:LOG_TARGET, "popapi call_hit id: {:?}", func_id); match func_id { - FuncId::CallRuntime => call_runtime::(env)?, + FuncId::CallRuntime => dispatch::(env)?, } Ok(RetVal::Converging(0)) From 024ef71f244438dcb781b7d18fafaee582627e2e Mon Sep 17 00:00:00 2001 From: Peter White Date: Tue, 27 Feb 2024 22:50:21 -0700 Subject: [PATCH 03/19] feat: start adding unit test for pop api chain extension --- runtime/Cargo.toml | 2 + runtime/src/extensions/pop_api_extension.rs | 93 ++++++++++++++++++++- 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 01ec36bf..fda969a9 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -47,6 +47,7 @@ pallet-timestamp = { workspace = true } pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } sp-api = { workspace = true } +sp-io = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } sp-core = { workspace = true } @@ -122,6 +123,7 @@ std = [ "polkadot-runtime-common/std", "scale-info/std", "sp-api/std", + "sp-io/std", "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs index 4aed9808..76337e04 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions/pop_api_extension.rs @@ -92,7 +92,6 @@ where // TODO: uncomment once charged_weight is fixed // let actual_weight = call.get_dispatch_info().weight; // env.adjust_weight(charged_weight, actual_weight); - let result = call.dispatch(origin); match result { Ok(info) => { @@ -135,3 +134,95 @@ where Ok(RetVal::Converging(0)) } } + +#[cfg(test)] +mod tests { + pub use super::*; + pub use crate::*; + pub use sp_runtime::{AccountId32, MultiAddress, traits::Hash}; + pub use frame_support::traits::{Currency, GenesisBuild}; + pub use pallet_contracts::Code; + + pub const ALICE: AccountId32 = AccountId32::new([1_u8; 32]); + pub const BOB: AccountId32 = AccountId32::new([2_u8; 32]); + pub const INITIAL_AMOUNT: u128 = 100_000 * UNIT; + pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000, 3 * 1024 * 1024); + + pub fn new_test_ext() -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .expect("Frame system builds valid default genesis config"); + + pallet_balances::GenesisConfig:: { + balances: vec![(ALICE, INITIAL_AMOUNT), (BOB, INITIAL_AMOUNT)], + } + .assimilate_storage(&mut t) + .expect("Pallet balances storage can be assimilated"); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext + } + + pub fn load_wasm_module() -> std::io::Result<(Vec, ::Output)> + where + T: frame_system::Config, + { + let fixture_path = "../demo-contracts/target/ink/pop_api_extension_demo.wasm"; + let wasm_binary = std::fs::read(fixture_path)?; + let code_hash = T::Hashing::hash(&wasm_binary); + Ok((wasm_binary, code_hash)) + } + + // pub fn call_contract_method( + // origin: AccountId32, + // contract_id: AccountId32, + // data: Vec, + // ) -> V { + // let result = Contracts::bare_call( + // origin, + // contract_id, + // 0, + // Weight::from_parts(10_000_000_000, 1024 * 1024), + // None, + // data, + // false, + // pallet_contracts::DebugInfo::Skip, + // pallet_contracts::CollectEvents::Skip, + // ); + // } + + #[test] + fn test_dispatch() { + new_test_ext().execute_with(|| { + let (wasm_binary, code_hash) = load_wasm_module::().unwrap(); + + let value = 100; + let to_send = 50; + + let addr = Contracts::bare_instantiate( + ALICE, + value, + GAS_LIMIT, + None, + Code::Upload(wasm_binary), + vec![], + vec![], + pallet_contracts::DebugInfo::Skip, + pallet_contracts::CollectEvents::Skip, + ); + + // call_wasm_contract_method::>( + // ALICE, + // contract_id.clone(), + // [ + // b"transfer_through_runtime", + // BOB, + // to_send, + // ] + // .concat() + // ); + + }); + } +} \ No newline at end of file From 9bd7fdf059c13543d66b48cad6d3a380e1b69477 Mon Sep 17 00:00:00 2001 From: Frank Bell Date: Wed, 28 Feb 2024 10:59:43 +0000 Subject: [PATCH 04/19] chore: update cargo.lock --- Cargo.lock | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 48e0da15..90c66145 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8844,6 +8844,7 @@ dependencies = [ "sp-core", "sp-genesis-builder", "sp-inherents", + "sp-io", "sp-offchain", "sp-runtime", "sp-session", @@ -11887,7 +11888,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#12ce4f7d049b70918cadb658de4bbe8eb6ffc670" +source = "git+https://github.com/paritytech/polkadot-sdk#f1b2189e8312821a9f8a79dc4f0183d314273faa" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -11950,7 +11951,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#12ce4f7d049b70918cadb658de4bbe8eb6ffc670" +source = "git+https://github.com/paritytech/polkadot-sdk#f1b2189e8312821a9f8a79dc4f0183d314273faa" dependencies = [ "proc-macro2", "quote", @@ -11971,7 +11972,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#12ce4f7d049b70918cadb658de4bbe8eb6ffc670" +source = "git+https://github.com/paritytech/polkadot-sdk#f1b2189e8312821a9f8a79dc4f0183d314273faa" dependencies = [ "environmental", "parity-scale-codec", @@ -12190,7 +12191,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#12ce4f7d049b70918cadb658de4bbe8eb6ffc670" +source = "git+https://github.com/paritytech/polkadot-sdk#f1b2189e8312821a9f8a79dc4f0183d314273faa" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -12222,7 +12223,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#12ce4f7d049b70918cadb658de4bbe8eb6ffc670" +source = "git+https://github.com/paritytech/polkadot-sdk#f1b2189e8312821a9f8a79dc4f0183d314273faa" dependencies = [ "Inflector", "expander 2.0.0", @@ -12315,7 +12316,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#12ce4f7d049b70918cadb658de4bbe8eb6ffc670" +source = "git+https://github.com/paritytech/polkadot-sdk#f1b2189e8312821a9f8a79dc4f0183d314273faa" [[package]] name = "sp-storage" @@ -12333,7 +12334,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#12ce4f7d049b70918cadb658de4bbe8eb6ffc670" +source = "git+https://github.com/paritytech/polkadot-sdk#f1b2189e8312821a9f8a79dc4f0183d314273faa" dependencies = [ "impl-serde", "parity-scale-codec", @@ -12371,7 +12372,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#12ce4f7d049b70918cadb658de4bbe8eb6ffc670" +source = "git+https://github.com/paritytech/polkadot-sdk#f1b2189e8312821a9f8a79dc4f0183d314273faa" dependencies = [ "parity-scale-codec", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", @@ -12472,7 +12473,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#12ce4f7d049b70918cadb658de4bbe8eb6ffc670" +source = "git+https://github.com/paritytech/polkadot-sdk#f1b2189e8312821a9f8a79dc4f0183d314273faa" dependencies = [ "anyhow", "impl-trait-for-tuples", From 23f41b70109904155108d1710a4aafa22e524aae Mon Sep 17 00:00:00 2001 From: Peter White Date: Wed, 28 Feb 2024 12:56:35 -0700 Subject: [PATCH 05/19] feat: unit test works for pop api chain extension --- demo-contracts/lib.rs | 20 ++--- runtime/Cargo.toml | 4 + runtime/src/extensions/pop_api_extension.rs | 88 ++++++++++++--------- 3 files changed, 62 insertions(+), 50 deletions(-) diff --git a/demo-contracts/lib.rs b/demo-contracts/lib.rs index 8e114470..53dc73a2 100755 --- a/demo-contracts/lib.rs +++ b/demo-contracts/lib.rs @@ -79,7 +79,7 @@ pub trait PopApi { /// and the chain-side chain extension will get the `func_id` to do further /// operations. #[ink(extension = 0xfecb)] - fn call_runtime(call: RuntimeCall) -> Result>; + fn dispatch(call: RuntimeCall) -> Result>; } impl ink::env::chain_extension::FromStatusCode for PopApiError { @@ -148,33 +148,27 @@ mod pop_api_extension_demo { // } impl PopApiExtensionDemo { - /// The constructor is `payable`, so that during instantiation it can be given - /// some tokens that will be further transferred with - /// `transfer_through_runtime` message. #[ink(constructor, payable)] pub fn new() -> Self { + ink::env::debug_println!("PopApiExtensionDemo::new"); Default::default() } - /// Tries to transfer `value` from the contract's balance to `receiver`. - /// - /// Fails if: - /// - called in the off-chain environment - /// - the chain forbids contracts to call `Balances::transfer` (`CallFilter` is - /// too restrictive) - /// - after the transfer, `receiver` doesn't have at least existential deposit - /// - the contract doesn't have enough balance #[ink(message)] pub fn transfer_through_runtime( &mut self, receiver: AccountId, value: Balance, ) { + ink::env::debug_println!("PopApiExtensionDemo::transfer_through_runtime: \nreceiver: {:?}, \nvalue: {:?}", receiver, value); + let call = RuntimeCall::Balances(BalancesCall::TransferKeepAlive { dest: receiver.into(), value: value, }); - self.env().extension().call_runtime(call); + self.env().extension().dispatch(call); + + ink::env::debug_println!("PopApiExtensionDemo::transfer_through_runtime end"); } } diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index fda969a9..55e33628 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -80,6 +80,10 @@ pallet-collator-selection = { workspace = true } parachains-common = { workspace = true } parachain-info = { workspace = true } +[dev-dependencies] +env_logger = "0.11.2" +hex = "0.4.3" + [features] default = ["std"] std = [ diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs index 76337e04..bcfcc689 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions/pop_api_extension.rs @@ -139,10 +139,11 @@ where mod tests { pub use super::*; pub use crate::*; - pub use sp_runtime::{AccountId32, MultiAddress, traits::Hash}; - pub use frame_support::traits::{Currency, GenesisBuild}; + pub use sp_runtime::{AccountId32, traits::Hash}; pub use pallet_contracts::Code; + pub const DEBUG_OUTPUT: pallet_contracts::DebugInfo = pallet_contracts::DebugInfo::Skip; + pub const ALICE: AccountId32 = AccountId32::new([1_u8; 32]); pub const BOB: AccountId32 = AccountId32::new([2_u8; 32]); pub const INITIAL_AMOUNT: u128 = 100_000 * UNIT; @@ -174,55 +175,68 @@ mod tests { Ok((wasm_binary, code_hash)) } - // pub fn call_contract_method( - // origin: AccountId32, - // contract_id: AccountId32, - // data: Vec, - // ) -> V { - // let result = Contracts::bare_call( - // origin, - // contract_id, - // 0, - // Weight::from_parts(10_000_000_000, 1024 * 1024), - // None, - // data, - // false, - // pallet_contracts::DebugInfo::Skip, - // pallet_contracts::CollectEvents::Skip, - // ); - // } + pub fn function_selector(name: &str) -> Vec { + let hash = sp_io::hashing::blake2_256(name.as_bytes()); + [hash[0..4].to_vec()].concat() + } #[test] fn test_dispatch() { new_test_ext().execute_with(|| { - let (wasm_binary, code_hash) = load_wasm_module::().unwrap(); + let _ = env_logger::try_init(); - let value = 100; - let to_send = 50; + let (wasm_binary, _) = load_wasm_module::().unwrap(); - let addr = Contracts::bare_instantiate( + let init_value = 100; + + let result = Contracts::bare_instantiate( ALICE, - value, + init_value, GAS_LIMIT, None, Code::Upload(wasm_binary), + function_selector("new"), vec![], - vec![], - pallet_contracts::DebugInfo::Skip, + DEBUG_OUTPUT, pallet_contracts::CollectEvents::Skip, + ).result.unwrap(); + + assert!(!result.result.did_revert(), "deploying contract reverted {:?}", result); + + let addr = result.account_id; + + let function = function_selector("transfer_through_runtime"); + let value_to_send: u128 = 1_000_000_000_000_000; + let params = [function, BOB.encode(), value_to_send.encode()].concat(); + + let bob_balance_before= Balances::free_balance(&BOB); + assert_eq!(bob_balance_before, INITIAL_AMOUNT); + + let result = Contracts::bare_call( + ALICE, + addr.clone(), + 0, + Weight::from_parts(100_000_000_000, 3 * 1024 * 1024), + None, + params, + DEBUG_OUTPUT, + pallet_contracts::CollectEvents::Skip, + pallet_contracts::Determinism::Enforced, ); - // call_wasm_contract_method::>( - // ALICE, - // contract_id.clone(), - // [ - // b"transfer_through_runtime", - // BOB, - // to_send, - // ] - // .concat() - // ); - + if DEBUG_OUTPUT == pallet_contracts::DebugInfo::UnsafeDebug { + log::debug!( + "Contract debug buffer - {:?}", + String::from_utf8(result.debug_message.clone()) + ); + log::debug!("result: {:?}", result); + } + + // check for revert + assert!(! result.result.unwrap().did_revert(), "Contract reverted!"); + + let bob_balance_after= Balances::free_balance(&BOB); + assert_eq!(bob_balance_before + value_to_send, bob_balance_after); }); } } \ No newline at end of file From 10cc94b135fb5f69d52c26b4e9af01b303e07d38 Mon Sep 17 00:00:00 2001 From: Peter White Date: Wed, 28 Feb 2024 13:12:41 -0700 Subject: [PATCH 06/19] chore: cargo fmt --- runtime/src/extensions/mod.rs | 2 +- runtime/src/extensions/pop_api_extension.rs | 73 +++++++++------------ runtime/src/lib.rs | 2 +- 3 files changed, 32 insertions(+), 45 deletions(-) diff --git a/runtime/src/extensions/mod.rs b/runtime/src/extensions/mod.rs index 3d1a6f9d..ad18a5a0 100644 --- a/runtime/src/extensions/mod.rs +++ b/runtime/src/extensions/mod.rs @@ -1 +1 @@ -pub mod pop_api_extension; \ No newline at end of file +pub mod pop_api_extension; diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs index bcfcc689..ad704d30 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions/pop_api_extension.rs @@ -6,21 +6,11 @@ use frame_support::{ use log; use pallet_contracts::chain_extension::{ - ChainExtension, - Environment, - Ext, - InitState, - RetVal, - SysConfig, + ChainExtension, Environment, Ext, InitState, RetVal, SysConfig, }; use sp_core::crypto::UncheckedFrom; -use sp_runtime::{ - traits::{ - Dispatchable - }, - DispatchError, -}; +use sp_runtime::{traits::Dispatchable, DispatchError}; const LOG_TARGET: &str = "popapi::extension"; #[derive(Default)] @@ -39,7 +29,7 @@ fn convert_err(err_msg: &'static str) -> impl FnOnce(DispatchError) -> DispatchE #[derive(Debug)] enum FuncId { - CallRuntime + CallRuntime, } impl TryFrom for FuncId { @@ -50,7 +40,7 @@ impl TryFrom for FuncId { 0xfecb => Self::CallRuntime, _ => { log::error!("Called an unregistered `func_id`: {:}", func_id); - return Err(DispatchError::Other("Unimplemented func_id")) + return Err(DispatchError::Other("Unimplemented func_id")); } }; @@ -63,11 +53,9 @@ where T: pallet_contracts::Config + frame_system::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, ::RuntimeCall: Parameter - + Dispatchable< - RuntimeOrigin = ::RuntimeOrigin, - PostInfo = PostDispatchInfo, - > + GetDispatchInfo - + From>, + + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> + + GetDispatchInfo + + From>, E: Ext, { let mut env = env.buf_in_buf_out(); @@ -79,17 +67,17 @@ where // TODO: debug_message weight is a good approximation of the additional overhead of going // from contract layer to substrate layer. - + // input length let len = env.in_len(); let call: ::RuntimeCall = env.read_as_unbounded(len)?; - + log::trace!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); let sender = env.ext().caller(); let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); - - // TODO: uncomment once charged_weight is fixed + + // TODO: uncomment once charged_weight is fixed // let actual_weight = call.get_dispatch_info().weight; // env.adjust_weight(charged_weight, actual_weight); let result = call.dispatch(origin); @@ -105,26 +93,19 @@ where Ok(()) } - impl ChainExtension for PopApiExtension where T: pallet_contracts::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, ::RuntimeCall: Parameter - + Dispatchable< - RuntimeOrigin = ::RuntimeOrigin, - PostInfo = PostDispatchInfo, - > + GetDispatchInfo - + From>, + + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> + + GetDispatchInfo + + From>, { - fn call( - &mut self, - env: Environment, - ) -> Result + fn call(&mut self, env: Environment) -> Result where E: Ext, - ::AccountId: - UncheckedFrom<::Hash> + AsRef<[u8]>, + ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, { let func_id = FuncId::try_from(env.func_id())?; match func_id { @@ -139,8 +120,8 @@ where mod tests { pub use super::*; pub use crate::*; - pub use sp_runtime::{AccountId32, traits::Hash}; pub use pallet_contracts::Code; + pub use sp_runtime::{traits::Hash, AccountId32}; pub const DEBUG_OUTPUT: pallet_contracts::DebugInfo = pallet_contracts::DebugInfo::Skip; @@ -199,9 +180,15 @@ mod tests { vec![], DEBUG_OUTPUT, pallet_contracts::CollectEvents::Skip, - ).result.unwrap(); - - assert!(!result.result.did_revert(), "deploying contract reverted {:?}", result); + ) + .result + .unwrap(); + + assert!( + !result.result.did_revert(), + "deploying contract reverted {:?}", + result + ); let addr = result.account_id; @@ -209,7 +196,7 @@ mod tests { let value_to_send: u128 = 1_000_000_000_000_000; let params = [function, BOB.encode(), value_to_send.encode()].concat(); - let bob_balance_before= Balances::free_balance(&BOB); + let bob_balance_before = Balances::free_balance(&BOB); assert_eq!(bob_balance_before, INITIAL_AMOUNT); let result = Contracts::bare_call( @@ -233,10 +220,10 @@ mod tests { } // check for revert - assert!(! result.result.unwrap().did_revert(), "Contract reverted!"); + assert!(!result.result.unwrap().did_revert(), "Contract reverted!"); - let bob_balance_after= Balances::free_balance(&BOB); + let bob_balance_after = Balances::free_balance(&BOB); assert_eq!(bob_balance_before + value_to_send, bob_balance_after); }); } -} \ No newline at end of file +} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 6219a15b..7f69e8d5 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -8,8 +8,8 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod assets_config; mod contracts_config; -mod weights; mod extensions; +mod weights; pub mod xcm_config; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; From f310bdabd9cb51cc01c2be81677765316ad1b6f8 Mon Sep 17 00:00:00 2001 From: Peter White <23270067+peterwht@users.noreply.github.com> Date: Fri, 1 Mar 2024 19:13:26 -0700 Subject: [PATCH 07/19] feat: pop api crate (#16) * ci: add build workflow * chore: improve zombienet config * ci: grant write permission to actions * feat: initialize pop-api directory * feat: add codec indexes, and wrap NFT interface * feat: add example contract utilizing pop-api crate -- not working * feat: minting NFT from contract through runtime works * feat pop api crate refactoring and test (#15) * refactor: simplify api usage from contract * test: add NFT mint unit test to pop api extension --------- Co-authored-by: Frank Bell --------- Co-authored-by: Frank Bell --- Cargo.lock | 2432 +++++++++++------ Cargo.toml | 3 +- .../balance-transfer}/.gitignore | 0 .../balance-transfer}/Cargo.toml | 0 .../pop-api-examples/balance-transfer}/lib.rs | 0 contracts/pop-api-examples/nfts/.gitignore | 9 + contracts/pop-api-examples/nfts/Cargo.toml | 32 + contracts/pop-api-examples/nfts/lib.rs | 58 + pop-api/.gitignore | 15 + pop-api/Cargo.toml | 29 + pop-api/README.md | 1 + pop-api/src/lib.rs | 77 + pop-api/src/v0/balances.rs | 1 + pop-api/src/v0/mod.rs | 8 + pop-api/src/v0/nfts.rs | 213 ++ runtime/Cargo.toml | 1 + runtime/src/extensions/pop_api_extension.rs | 124 +- 17 files changed, 2190 insertions(+), 813 deletions(-) rename {demo-contracts => contracts/pop-api-examples/balance-transfer}/.gitignore (100%) rename {demo-contracts => contracts/pop-api-examples/balance-transfer}/Cargo.toml (100%) rename {demo-contracts => contracts/pop-api-examples/balance-transfer}/lib.rs (100%) create mode 100755 contracts/pop-api-examples/nfts/.gitignore create mode 100755 contracts/pop-api-examples/nfts/Cargo.toml create mode 100755 contracts/pop-api-examples/nfts/lib.rs create mode 100644 pop-api/.gitignore create mode 100644 pop-api/Cargo.toml create mode 100644 pop-api/README.md create mode 100644 pop-api/src/lib.rs create mode 100644 pop-api/src/v0/balances.rs create mode 100644 pop-api/src/v0/mod.rs create mode 100644 pop-api/src/v0/nfts.rs diff --git a/Cargo.lock b/Cargo.lock index 90c66145..26c55acf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,9 +84,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42cd52102d3df161c77a887b608d7a4897d7cc112886a9537b738a887a03aaff" +checksum = "8b79b82693f705137f8fb9b37871d99e4f9a7df12b917eed79c3d3954830a60b" dependencies = [ "cfg-if", "getrandom 0.2.12", @@ -142,9 +142,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.12" +version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96b09b5178381e0874812a9b157f7fe84982617e48f71f4e3235482775e5b540" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" dependencies = [ "anstyle", "anstyle-parse", @@ -214,7 +214,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -487,7 +487,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" dependencies = [ "num-traits", - "rand", + "rand 0.8.5", "rayon", ] @@ -516,6 +516,12 @@ version = "6.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f840fb7195bcfc5e17ea40c26e5ce6d5b9ce5d584466e17703209657e459ae0" +[[package]] +name = "array-init" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d62b7694a562cdf5a74227903507c56ab2cc8bdd1f781ed5cb4cf9c9f810bfc" + [[package]] name = "arrayref" version = "0.3.7" @@ -568,7 +574,7 @@ dependencies = [ "proc-macro2", "quote", "syn 1.0.109", - "synstructure", + "synstructure 0.12.6", ] [[package]] @@ -606,7 +612,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f28243a43d821d11341ab73c80bed182dc015c514b951616cf79bd4af39af0c3" dependencies = [ "concurrent-queue", - "event-listener 5.1.0", + "event-listener 5.2.0", "event-listener-strategy 0.5.0", "futures-core", "pin-project-lite 0.2.13", @@ -757,7 +763,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -904,7 +910,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -914,7 +920,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" dependencies = [ "bitcoin_hashes", - "rand", + "rand 0.8.5", "rand_core 0.6.4", "serde", "unicode-normalization", @@ -1072,6 +1078,18 @@ dependencies = [ "tracing", ] +[[package]] +name = "bounded-collections" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca548b6163b872067dc5eb82fd130c56881435e30367d2073594a3d9744120dd" +dependencies = [ + "log", + "parity-scale-codec", + "scale-info", + "serde", +] + [[package]] name = "bounded-collections" version = "0.2.0" @@ -1100,8 +1118,8 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "parity-scale-codec", "scale-info", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", ] [[package]] @@ -1130,9 +1148,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.15.0" +version = "3.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32a994c2b3ca201d9b263612a374263f05e7adde37c4707f693dcd375076d1f" +checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b" [[package]] name = "byte-slice-cast" @@ -1219,11 +1237,10 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.83" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "02f341c093d19155a6e41631ce5971aac4e9a868262212153124c15fa22d1cdc" dependencies = [ - "jobserver", "libc", ] @@ -1302,7 +1319,7 @@ dependencies = [ "js-sys", "num-traits", "wasm-bindgen", - "windows-targets 0.52.0", + "windows-targets 0.52.4", ] [[package]] @@ -1377,7 +1394,7 @@ dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim", + "strsim 0.11.0", "terminal_size", ] @@ -1390,7 +1407,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -1826,8 +1843,8 @@ dependencies = [ "sc-client-api", "sc-service", "sp-blockchain", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "url", ] @@ -1849,8 +1866,8 @@ dependencies = [ "sc-client-api", "sp-api", "sp-consensus", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "tracing", ] @@ -1881,16 +1898,16 @@ dependencies = [ "sc-telemetry", "schnellru", "sp-api", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-block-builder", "sp-blockchain", "sp-consensus", "sp-consensus-aura", - "sp-core", + "sp-core 28.0.0", "sp-inherents", - "sp-keystore", - "sp-runtime", - "sp-state-machine", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "sp-timestamp", "substrate-prometheus-endpoint", "tracing", @@ -1917,10 +1934,10 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-slots", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "sp-timestamp", - "sp-trie", + "sp-trie 29.0.0", "substrate-prometheus-endpoint", "tracing", ] @@ -1935,8 +1952,8 @@ dependencies = [ "cumulus-primitives-parachain-inherent", "sp-consensus", "sp-inherents", - "sp-runtime", - "sp-state-machine", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "thiserror", ] @@ -1957,9 +1974,9 @@ dependencies = [ "sc-client-api", "sp-blockchain", "sp-consensus", - "sp-core", - "sp-runtime", - "sp-state-machine", + "sp-core 28.0.0", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "tracing", ] @@ -1979,11 +1996,11 @@ dependencies = [ "sp-api", "sp-crypto-hashing", "sp-inherents", - "sp-runtime", - "sp-state-machine", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", "tracing", ] @@ -2002,12 +2019,12 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-overseer", "polkadot-primitives", - "rand", + "rand 0.8.5", "sc-client-api", "sc-consensus", "sp-consensus", "sp-maybe-compressed-blob", - "sp-runtime", + "sp-runtime 31.0.1", "tracing", ] @@ -2042,8 +2059,8 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-consensus", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "sp-transaction-pool", ] @@ -2059,9 +2076,9 @@ dependencies = [ "pallet-timestamp", "parity-scale-codec", "scale-info", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-consensus-aura", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -2086,17 +2103,17 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-runtime-parachains", "scale-info", - "sp-core", + "sp-core 28.0.0", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-inherents", - "sp-io", - "sp-runtime", - "sp-state-machine", + "sp-io 30.0.0", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", "sp-version", "staging-xcm", - "trie-db", + "trie-db 0.28.0", ] [[package]] @@ -2107,7 +2124,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -2120,7 +2137,7 @@ dependencies = [ "frame-system", "pallet-session", "parity-scale-codec", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -2134,8 +2151,8 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-io", - "sp-runtime", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "staging-xcm", ] @@ -2145,7 +2162,7 @@ name = "cumulus-pallet-xcmp-queue" version = "0.7.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ - "bounded-collections", + "bounded-collections 0.2.0", "bp-xcm-bridge-hub-router", "cumulus-primitives-core", "frame-benchmarking", @@ -2157,9 +2174,9 @@ dependencies = [ "polkadot-runtime-common", "polkadot-runtime-parachains", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "staging-xcm", "staging-xcm-executor", @@ -2175,7 +2192,7 @@ dependencies = [ "polkadot-primitives", "sp-api", "sp-consensus-aura", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -2190,9 +2207,9 @@ dependencies = [ "polkadot-primitives", "scale-info", "sp-api", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", "staging-xcm", ] @@ -2205,10 +2222,10 @@ dependencies = [ "cumulus-primitives-core", "parity-scale-codec", "scale-info", - "sp-core", + "sp-core 28.0.0", "sp-inherents", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", ] [[package]] @@ -2218,7 +2235,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", ] [[package]] @@ -2234,8 +2251,8 @@ dependencies = [ "parity-scale-codec", "polkadot-runtime-common", "polkadot-runtime-parachains", - "sp-io", - "sp-runtime", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "staging-xcm", "staging-xcm-builder", @@ -2261,9 +2278,9 @@ dependencies = [ "sc-tracing", "sp-api", "sp-consensus", - "sp-core", - "sp-runtime", - "sp-state-machine", + "sp-core 28.0.0", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", ] [[package]] @@ -2280,7 +2297,7 @@ dependencies = [ "sc-client-api", "sp-api", "sp-blockchain", - "sp-state-machine", + "sp-state-machine 0.35.0", "thiserror", ] @@ -2319,7 +2336,7 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-babe", - "sp-runtime", + "sp-runtime 31.0.1", "substrate-prometheus-endpoint", "tokio", "tracing", @@ -2340,7 +2357,7 @@ dependencies = [ "parity-scale-codec", "pin-project", "polkadot-overseer", - "rand", + "rand 0.8.5", "sc-client-api", "sc-rpc-api", "sc-service", @@ -2352,9 +2369,9 @@ dependencies = [ "sp-api", "sp-authority-discovery", "sp-consensus-babe", - "sp-core", - "sp-runtime", - "sp-state-machine", + "sp-core 28.0.0", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-version", "thiserror", @@ -2372,10 +2389,10 @@ dependencies = [ "cumulus-primitives-core", "parity-scale-codec", "polkadot-primitives", - "sp-runtime", - "sp-state-machine", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", ] [[package]] @@ -2429,7 +2446,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -2447,9 +2464,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.116" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aff472b83efd22bfc0176aa8ba34617dd5c17364670eb201a5f06d339b8abf7" +checksum = "2673ca5ae28334544ec2a6b18ebe666c42a2650abfb48abbd532ed409a44be2b" dependencies = [ "cc", "cxxbridge-flags", @@ -2459,9 +2476,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.116" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf6e7a52c19013a9a0ec421c7d9c2d1125faf333551227e0a017288d71b47c3" +checksum = "9df46fe0eb43066a332586114174c449a62c25689f85a08f28fdcc8e12c380b9" dependencies = [ "cc", "codespan-reporting", @@ -2469,24 +2486,59 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] name = "cxxbridge-flags" -version = "1.0.116" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589e83d02fc1d4fb78f5ad56ca08835341e23499d086d2821315869426d618dc" +checksum = "886acf875df67811c11cd015506b3392b9e1820b1627af1a6f4e93ccdfc74d11" [[package]] name = "cxxbridge-macro" -version = "1.0.116" +version = "1.0.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d151cc139c3080e07f448f93a1284577ab2283d2a44acd902c6fba9ec20b6de" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "darling" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2cb1fd8ffae4230c7cfbbaf3698dbeaf750fa8c5dadf7ed897df581b9b572a5" +checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" dependencies = [ + "fnv", + "ident_case", "proc-macro2", "quote", - "syn 2.0.50", + "strsim 0.10.0", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" +dependencies = [ + "darling_core", + "quote", + "syn 1.0.109", ] [[package]] @@ -2669,7 +2721,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -2709,7 +2761,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.50", + "syn 2.0.52", "termcolor", "toml 0.8.10", "walkdir", @@ -2756,9 +2808,9 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "ecdsa" @@ -2770,10 +2822,19 @@ dependencies = [ "digest 0.10.7", "elliptic-curve", "rfc6979", - "signature", + "signature 2.2.0", "spki", ] +[[package]] +name = "ed25519" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +dependencies = [ + "signature 1.6.4", +] + [[package]] name = "ed25519" version = "2.2.3" @@ -2781,7 +2842,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ "pkcs8", - "signature", + "signature 2.2.0", +] + +[[package]] +name = "ed25519-dalek" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +dependencies = [ + "curve25519-dalek 3.2.0", + "ed25519 1.5.3", + "sha2 0.9.9", + "zeroize", ] [[package]] @@ -2791,7 +2864,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ "curve25519-dalek 4.1.2", - "ed25519", + "ed25519 2.2.3", "rand_core 0.6.4", "serde", "sha2 0.10.8", @@ -2820,7 +2893,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d9ce6874da5d4415896cd45ffbc4d1cfc0c4f9c079427bd870742c30f2f65a9" dependencies = [ "curve25519-dalek 4.1.2", - "ed25519", + "ed25519 2.2.3", "hashbrown 0.14.3", "hex", "rand_core 0.6.4", @@ -2888,7 +2961,7 @@ checksum = "5c785274071b1b420972453b306eeca06acf4633829db4223b58a2a8c5953bc4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -2899,7 +2972,17 @@ checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", +] + +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", ] [[package]] @@ -2915,6 +2998,19 @@ dependencies = [ "termcolor", ] +[[package]] +name = "env_logger" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c012a26a7f605efc424dd53697843a72be7dc86ad2d01f7814337794a12231d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "environmental" version = "1.1.4" @@ -2967,9 +3063,9 @@ dependencies = [ [[package]] name = "event-listener" -version = "5.1.0" +version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7ad6fd685ce13acd6d9541a30f6db6567a7a24c9ffd4ba2955d29e3f22c8b27" +checksum = "2b5fb89194fa3cad959b833185b3063ba881dbfc7030680b314250779fb4cc91" dependencies = [ "concurrent-queue", "parking", @@ -2992,7 +3088,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "feedafcaa9b749175d5ac357452a9d41ea2911da598fde46ce1fe02c37751291" dependencies = [ - "event-listener 5.1.0", + "event-listener 5.2.0", "pin-project-lite 0.2.13", ] @@ -3027,7 +3123,7 @@ dependencies = [ "fs-err", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -3127,7 +3223,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84f2e425d9790201ba4af4630191feac6dcc98765b118d4d18e91d23c2353866" dependencies = [ - "env_logger", + "env_logger 0.10.2", "log", ] @@ -3166,7 +3262,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" dependencies = [ "byteorder", - "rand", + "rand 0.8.5", "rustc-hex", "static_assertions", ] @@ -3241,10 +3337,10 @@ dependencies = [ "scale-info", "serde", "sp-api", - "sp-application-crypto", - "sp-core", - "sp-io", - "sp-runtime", + "sp-application-crypto 30.0.0", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", @@ -3271,7 +3367,7 @@ dependencies = [ "linked-hash-map", "log", "parity-scale-codec", - "rand", + "rand 0.8.5", "rand_pcg", "sc-block-builder", "sc-cli", @@ -3284,16 +3380,16 @@ dependencies = [ "serde_json", "sp-api", "sp-blockchain", - "sp-core", + "sp-core 28.0.0", "sp-database", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-inherents", - "sp-io", - "sp-keystore", - "sp-runtime", - "sp-state-machine", + "sp-io 30.0.0", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", "sp-wasm-interface 20.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "thiserror", "thousands", @@ -3307,7 +3403,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -3320,10 +3416,10 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-arithmetic", - "sp-core", + "sp-arithmetic 23.0.0", + "sp-core 28.0.0", "sp-npos-elections", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -3338,9 +3434,9 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -3368,11 +3464,11 @@ dependencies = [ "log", "parity-scale-codec", "serde", - "sp-core", + "sp-core 28.0.0", "sp-crypto-hashing", - "sp-io", - "sp-runtime", - "sp-state-machine", + "sp-io 30.0.0", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "spinners", "substrate-rpc-client", "tokio", @@ -3402,20 +3498,20 @@ dependencies = [ "serde_json", "smallvec", "sp-api", - "sp-arithmetic", - "sp-core", + "sp-arithmetic 23.0.0", + "sp-core 28.0.0", "sp-crypto-hashing-proc-macro", "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-genesis-builder", "sp-inherents", - "sp-io", + "sp-io 30.0.0", "sp-metadata-ir", - "sp-runtime", + "sp-runtime 31.0.1", "sp-staking", - "sp-state-machine", + "sp-state-machine 0.35.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-weights", + "sp-weights 27.0.0", "static_assertions", "tt-call", ] @@ -3436,7 +3532,7 @@ dependencies = [ "proc-macro2", "quote", "sp-crypto-hashing", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -3448,7 +3544,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -3458,7 +3554,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -3473,12 +3569,12 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-version", - "sp-weights", + "sp-weights 27.0.0", ] [[package]] @@ -3491,8 +3587,8 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -3513,7 +3609,7 @@ dependencies = [ "frame-support", "parity-scale-codec", "sp-api", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -3637,7 +3733,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -3665,9 +3761,9 @@ checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-timer" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" @@ -3754,7 +3850,7 @@ version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ea1015b5a70616b688dc230cfe50c8af89d972cb132d5a622814d29773b10b9" dependencies = [ - "rand", + "rand 0.8.5", "rand_core 0.6.4", ] @@ -3814,7 +3910,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 2.2.3", + "indexmap 2.2.5", "slab", "tokio", "tokio-util", @@ -3865,7 +3961,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.8", + "ahash 0.8.10", ] [[package]] @@ -3874,7 +3970,7 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ - "ahash 0.8.8", + "ahash 0.8.10", "allocator-api2", "serde", ] @@ -3896,9 +3992,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.6" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hex" @@ -4044,7 +4140,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite 0.2.13", - "socket2 0.5.5", + "socket2 0.5.6", "tokio", "tower-service", "tracing", @@ -4090,6 +4186,12 @@ dependencies = [ "cc", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.2.3" @@ -4201,9 +4303,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.3" +version = "2.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" +checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" dependencies = [ "equivalent", "hashbrown 0.14.3", @@ -4228,6 +4330,197 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "ink" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9fd4f77d66c94aa7f27a7cf41cd2edbc2229afe34ec475c3f32b6e8fdf561a0" +dependencies = [ + "derive_more", + "ink_env", + "ink_macro", + "ink_metadata", + "ink_prelude", + "ink_primitives", + "ink_storage", + "parity-scale-codec", +] + +[[package]] +name = "ink_allocator" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "870914970470fd77a3f42d3c5d1918b562817af127fd063ee8b1d9fbf59aa1fe" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "ink_codegen" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22d79057b2565df31a10af6510a44b161093f110c5f9c22ad02c20af9cea4c29" +dependencies = [ + "blake2 0.10.6", + "derive_more", + "either", + "env_logger 0.10.2", + "heck", + "impl-serde", + "ink_ir", + "ink_primitives", + "itertools 0.10.5", + "log", + "parity-scale-codec", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 2.0.52", +] + +[[package]] +name = "ink_engine" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "722ec3a5eb557124b001c60ff8f961079f6d566af643edea579f152b15822fe5" +dependencies = [ + "blake2 0.10.6", + "derive_more", + "ink_primitives", + "parity-scale-codec", + "secp256k1 0.27.0", + "sha2 0.10.8", + "sha3", +] + +[[package]] +name = "ink_env" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "584e73bc0982f6f1a067bb63ebc75262f6dc54ed2a17060efa73eaba84dc9308" +dependencies = [ + "arrayref", + "blake2 0.10.6", + "cfg-if", + "derive_more", + "ink_allocator", + "ink_engine", + "ink_prelude", + "ink_primitives", + "ink_storage_traits", + "num-traits", + "parity-scale-codec", + "paste", + "rlibc", + "scale-decode", + "scale-encode", + "scale-info", + "secp256k1 0.27.0", + "sha2 0.10.8", + "sha3", + "static_assertions", +] + +[[package]] +name = "ink_ir" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b529c941518e8f450395fab9fe8ebba0a7acbb18778fc7e0a87f6248286ec72" +dependencies = [ + "blake2 0.10.6", + "either", + "itertools 0.10.5", + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "ink_macro" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8579576c995ca9baa032584beca19155cbd63b6739570aa9da4d35a0415f4be8" +dependencies = [ + "ink_codegen", + "ink_ir", + "ink_primitives", + "parity-scale-codec", + "proc-macro2", + "quote", + "syn 2.0.52", + "synstructure 0.13.1", +] + +[[package]] +name = "ink_metadata" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fddff95ce3e01f42002fdaf96edda691dbccb08c9ae76d7101daa1fa634e601" +dependencies = [ + "derive_more", + "impl-serde", + "ink_prelude", + "ink_primitives", + "scale-info", + "serde", +] + +[[package]] +name = "ink_prelude" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8cfdf91d2b442f08efb34dd3780fd6fbd3d033f63b42f62684fe47534948ef6" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "ink_primitives" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6414bcad12ebf0c3abbbb192a09e4d06e22f662cf3e19545204e1b0684be12a1" +dependencies = [ + "derive_more", + "ink_prelude", + "parity-scale-codec", + "scale-decode", + "scale-encode", + "scale-info", + "xxhash-rust", +] + +[[package]] +name = "ink_storage" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd728409de235de0489f71ee2d1beb320613fdb50dda9fa1c564825f4ad06daa" +dependencies = [ + "array-init", + "cfg-if", + "derive_more", + "ink_env", + "ink_metadata", + "ink_prelude", + "ink_primitives", + "ink_storage_traits", + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "ink_storage_traits" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8dcb50f70377ac35c28d63b06383a0a3cbb79542ea4cdc5b00e3e2b3de4a549" +dependencies = [ + "ink_metadata", + "ink_prelude", + "ink_primitives", + "parity-scale-codec", + "scale-info", +] + [[package]] name = "inout" version = "0.1.3" @@ -4284,7 +4577,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" dependencies = [ - "socket2 0.5.5", + "socket2 0.5.6", "widestring", "windows-sys 0.48.0", "winreg", @@ -4340,15 +4633,6 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" -[[package]] -name = "jobserver" -version = "0.1.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" -dependencies = [ - "libc", -] - [[package]] name = "js-sys" version = "0.3.68" @@ -4409,7 +4693,7 @@ dependencies = [ "hyper", "jsonrpsee-types", "parking_lot 0.12.1", - "rand", + "rand 0.8.5", "rustc-hash", "serde", "serde_json", @@ -4685,7 +4969,7 @@ dependencies = [ "parking_lot 0.12.1", "pin-project", "quick-protobuf", - "rand", + "rand 0.8.5", "rw-stream-sink", "smallvec", "thiserror", @@ -4736,12 +5020,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "276bb57e7af15d8f100d3c11cbdd32c6752b7eef4ba7a18ecf464972c07abcce" dependencies = [ "bs58 0.4.0", - "ed25519-dalek", + "ed25519-dalek 2.1.1", "log", "multiaddr", "multihash 0.17.0", "quick-protobuf", - "rand", + "rand 0.8.5", "sha2 0.10.8", "thiserror", "zeroize", @@ -4766,7 +5050,7 @@ dependencies = [ "libp2p-swarm", "log", "quick-protobuf", - "rand", + "rand 0.8.5", "sha2 0.10.8", "smallvec", "thiserror", @@ -4788,7 +5072,7 @@ dependencies = [ "libp2p-identity", "libp2p-swarm", "log", - "rand", + "rand 0.8.5", "smallvec", "socket2 0.4.10", "tokio", @@ -4824,7 +5108,7 @@ dependencies = [ "log", "once_cell", "quick-protobuf", - "rand", + "rand 0.8.5", "sha2 0.10.8", "snow", "static_assertions", @@ -4846,7 +5130,7 @@ dependencies = [ "libp2p-core", "libp2p-swarm", "log", - "rand", + "rand 0.8.5", "void", ] @@ -4866,7 +5150,7 @@ dependencies = [ "log", "parking_lot 0.12.1", "quinn-proto", - "rand", + "rand 0.8.5", "rustls 0.20.9", "thiserror", "tokio", @@ -4884,7 +5168,7 @@ dependencies = [ "libp2p-core", "libp2p-identity", "libp2p-swarm", - "rand", + "rand 0.8.5", "smallvec", ] @@ -4903,7 +5187,7 @@ dependencies = [ "libp2p-identity", "libp2p-swarm-derive", "log", - "rand", + "rand 0.8.5", "smallvec", "tokio", "void", @@ -5040,7 +5324,7 @@ dependencies = [ "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", - "rand", + "rand 0.8.5", "serde", "sha2 0.9.9", "typenum", @@ -5161,9 +5445,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "lru" @@ -5227,7 +5511,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -5241,7 +5525,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -5252,7 +5536,7 @@ checksum = "9ea73aa640dc01d62a590d48c0c3521ed739d53b27f919b25c3551e233481654" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -5263,7 +5547,7 @@ checksum = "ef9d79ae96aaba821963320eb2b6e34d17df1e5a83d8a1985c29cc5be59577b3" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -5385,7 +5669,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69672161530e8aeca1d1400fbf3f1a1747ff60ea604265a4e906c2442df20532" dependencies = [ "futures", - "rand", + "rand 0.8.5", "thrift", ] @@ -5432,7 +5716,7 @@ dependencies = [ "lioness", "log", "parking_lot 0.12.1", - "rand", + "rand 0.8.5", "rand_chacha 0.3.1", "rand_distr", "subtle 2.5.0", @@ -5454,9 +5738,9 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-beefy", - "sp-core", + "sp-core 28.0.0", "sp-mmr-primitives", - "sp-runtime", + "sp-runtime 31.0.1", ] [[package]] @@ -5469,9 +5753,9 @@ dependencies = [ "serde", "sp-api", "sp-blockchain", - "sp-core", + "sp-core 28.0.0", "sp-mmr-primitives", - "sp-runtime", + "sp-runtime 31.0.1", ] [[package]] @@ -5602,7 +5886,7 @@ dependencies = [ "proc-macro2", "quote", "syn 1.0.109", - "synstructure", + "synstructure 0.12.6", ] [[package]] @@ -5627,7 +5911,7 @@ dependencies = [ "proc-macro2", "quote", "syn 1.0.109", - "synstructure", + "synstructure 0.12.6", ] [[package]] @@ -5683,7 +5967,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bddcd3bf5144b6392de80e04c347cd7fab2508f6df16a85fc496ecd5cec39bc" dependencies = [ - "rand", + "rand 0.8.5", ] [[package]] @@ -5981,7 +6265,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eedb646674596266dc9bb2b5c7eea7c36b32ecc7777eba0d510196972d72c4fd" dependencies = [ "expander 2.0.0", - "indexmap 2.2.3", + "indexmap 2.2.5", "itertools 0.11.0", "petgraph", "proc-macro-crate 1.3.1", @@ -6010,10 +6294,10 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api", - "sp-arithmetic", - "sp-core", - "sp-io", - "sp-runtime", + "sp-arithmetic 23.0.0", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6027,8 +6311,8 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6044,9 +6328,9 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6061,8 +6345,8 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6077,9 +6361,9 @@ dependencies = [ "pallet-timestamp", "parity-scale-codec", "scale-info", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-consensus-aura", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6093,9 +6377,9 @@ dependencies = [ "pallet-session", "parity-scale-codec", "scale-info", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-authority-discovery", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6109,7 +6393,7 @@ dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", "scale-info", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6127,11 +6411,11 @@ dependencies = [ "pallet-timestamp", "parity-scale-codec", "scale-info", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-consensus-babe", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-session", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", @@ -6152,9 +6436,9 @@ dependencies = [ "pallet-balances", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6171,7 +6455,7 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6189,7 +6473,7 @@ dependencies = [ "scale-info", "serde", "sp-consensus-beefy", - "sp-runtime", + "sp-runtime 31.0.1", "sp-session", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", @@ -6213,10 +6497,10 @@ dependencies = [ "serde", "sp-api", "sp-consensus-beefy", - "sp-core", - "sp-io", - "sp-runtime", - "sp-state-machine", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6232,9 +6516,9 @@ dependencies = [ "pallet-treasury", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6249,9 +6533,9 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-arithmetic", - "sp-core", - "sp-runtime", + "sp-arithmetic 23.0.0", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6268,9 +6552,9 @@ dependencies = [ "pallet-treasury", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6286,9 +6570,9 @@ dependencies = [ "pallet-authorship", "pallet-session", "parity-scale-codec", - "rand", + "rand 0.8.5", "scale-info", - "sp-runtime", + "sp-runtime 31.0.1", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6304,9 +6588,9 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6326,15 +6610,15 @@ dependencies = [ "pallet-contracts-proc-macro", "pallet-contracts-uapi", "parity-scale-codec", - "rand", + "rand 0.8.5", "rand_pcg", "scale-info", "serde", "smallvec", "sp-api", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "staging-xcm", "staging-xcm-builder", @@ -6349,7 +6633,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -6376,8 +6660,8 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-io", - "sp-runtime", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6393,9 +6677,9 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6411,13 +6695,13 @@ dependencies = [ "log", "pallet-election-provider-support-benchmarking", "parity-scale-codec", - "rand", + "rand 0.8.5", "scale-info", - "sp-arithmetic", - "sp-core", - "sp-io", + "sp-arithmetic 23.0.0", + "sp-core 28.0.0", + "sp-io 30.0.0", "sp-npos-elections", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "strum 0.24.1", ] @@ -6432,7 +6716,7 @@ dependencies = [ "frame-system", "parity-scale-codec", "sp-npos-elections", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6447,10 +6731,10 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", + "sp-core 28.0.0", + "sp-io 30.0.0", "sp-npos-elections", - "sp-runtime", + "sp-runtime 31.0.1", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6468,8 +6752,8 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-io", - "sp-runtime", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6487,11 +6771,11 @@ dependencies = [ "pallet-session", "parity-scale-codec", "scale-info", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-consensus-grandpa", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-session", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", @@ -6509,8 +6793,8 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-io", - "sp-runtime", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6526,10 +6810,10 @@ dependencies = [ "pallet-authorship", "parity-scale-codec", "scale-info", - "sp-application-crypto", - "sp-core", - "sp-io", - "sp-runtime", + "sp-application-crypto 30.0.0", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6544,10 +6828,10 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", + "sp-core 28.0.0", + "sp-io 30.0.0", "sp-keyring", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6562,9 +6846,9 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6580,12 +6864,12 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-arithmetic", - "sp-core", - "sp-io", - "sp-runtime", + "sp-arithmetic 23.0.0", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-weights", + "sp-weights 27.0.0", ] [[package]] @@ -6599,10 +6883,10 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", + "sp-core 28.0.0", + "sp-io 30.0.0", "sp-mmr-primitives", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6617,8 +6901,8 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-io", - "sp-runtime", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6635,7 +6919,7 @@ dependencies = [ "pallet-nfts", "parity-scale-codec", "scale-info", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6651,9 +6935,9 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6678,9 +6962,9 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-arithmetic", - "sp-core", - "sp-runtime", + "sp-arithmetic 23.0.0", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6695,9 +6979,9 @@ dependencies = [ "pallet-balances", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", @@ -6717,7 +7001,7 @@ dependencies = [ "pallet-staking", "parity-scale-codec", "scale-info", - "sp-runtime", + "sp-runtime 31.0.1", "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", @@ -6746,7 +7030,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-runtime", + "sp-runtime 31.0.1", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6770,7 +7054,7 @@ dependencies = [ "pallet-staking", "parity-scale-codec", "scale-info", - "sp-runtime", + "sp-runtime 31.0.1", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6786,9 +7070,9 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6802,8 +7086,8 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-io", - "sp-runtime", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6819,10 +7103,10 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-arithmetic", - "sp-core", - "sp-io", - "sp-runtime", + "sp-arithmetic 23.0.0", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6836,8 +7120,8 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-io", - "sp-runtime", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6854,9 +7138,9 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-arithmetic", - "sp-io", - "sp-runtime", + "sp-arithmetic 23.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6869,9 +7153,9 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6887,10 +7171,10 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-io", - "sp-runtime", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-weights", + "sp-weights 27.0.0", ] [[package]] @@ -6905,14 +7189,14 @@ dependencies = [ "pallet-timestamp", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-session", "sp-staking", - "sp-state-machine", + "sp-state-machine 0.35.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", ] [[package]] @@ -6926,8 +7210,8 @@ dependencies = [ "pallet-session", "pallet-staking", "parity-scale-codec", - "rand", - "sp-runtime", + "rand 0.8.5", + "sp-runtime 31.0.1", "sp-session", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6944,9 +7228,9 @@ dependencies = [ "parity-scale-codec", "rand_chacha 0.2.2", "scale-info", - "sp-arithmetic", - "sp-io", - "sp-runtime", + "sp-arithmetic 23.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6966,9 +7250,9 @@ dependencies = [ "rand_chacha 0.2.2", "scale-info", "serde", - "sp-application-crypto", - "sp-io", - "sp-runtime", + "sp-application-crypto 30.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -6981,7 +7265,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -6990,7 +7274,7 @@ version = "19.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ "log", - "sp-arithmetic", + "sp-arithmetic 23.0.0", ] [[package]] @@ -7014,9 +7298,9 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -7031,8 +7315,8 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-io", - "sp-runtime", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -7049,8 +7333,8 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-inherents", - "sp-io", - "sp-runtime", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-timestamp", @@ -7069,9 +7353,9 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -7085,9 +7369,9 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -7101,10 +7385,10 @@ dependencies = [ "parity-scale-codec", "sp-api", "sp-blockchain", - "sp-core", + "sp-core 28.0.0", "sp-rpc", - "sp-runtime", - "sp-weights", + "sp-runtime 31.0.1", + "sp-weights 27.0.0", ] [[package]] @@ -7115,8 +7399,8 @@ dependencies = [ "pallet-transaction-payment", "parity-scale-codec", "sp-api", - "sp-runtime", - "sp-weights", + "sp-runtime 31.0.1", + "sp-weights 27.0.0", ] [[package]] @@ -7133,8 +7417,8 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -7148,9 +7432,9 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -7165,7 +7449,7 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -7180,7 +7464,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -7189,7 +7473,7 @@ name = "pallet-xcm" version = "7.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ - "bounded-collections", + "bounded-collections 0.2.0", "frame-benchmarking", "frame-support", "frame-system", @@ -7198,9 +7482,9 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "staging-xcm", "staging-xcm-builder", @@ -7218,8 +7502,8 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-io", - "sp-runtime", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "staging-xcm", "staging-xcm-builder", @@ -7247,9 +7531,9 @@ dependencies = [ "polkadot-primitives", "scale-info", "sp-consensus-aura", - "sp-core", - "sp-io", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "staging-parachain-info", "staging-xcm", @@ -7272,7 +7556,7 @@ dependencies = [ "lz4", "memmap2 0.5.10", "parking_lot 0.12.1", - "rand", + "rand 0.8.5", "siphasher", "snap", "winapi", @@ -7392,6 +7676,15 @@ dependencies = [ "crypto-mac 0.11.0", ] +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "pbkdf2" version = "0.12.2" @@ -7453,7 +7746,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -7474,7 +7767,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.2.3", + "indexmap 2.2.5", ] [[package]] @@ -7494,7 +7787,7 @@ checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -7564,7 +7857,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "rand", + "rand 0.8.5", "tracing-gum", ] @@ -7580,7 +7873,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "rand", + "rand 0.8.5", "tracing-gum", ] @@ -7599,10 +7892,10 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "rand", + "rand 0.8.5", "schnellru", - "sp-core", - "sp-keystore", + "sp-core 28.0.0", + "sp-keystore 0.34.0", "thiserror", "tracing-gum", ] @@ -7622,7 +7915,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "rand", + "rand 0.8.5", "sc-network", "schnellru", "thiserror", @@ -7649,8 +7942,8 @@ dependencies = [ "sc-storage-monitor", "sc-sysinfo", "sc-tracing", - "sp-core", - "sp-io", + "sp-core 28.0.0", + "sp-io 30.0.0", "sp-keyring", "sp-maybe-compressed-blob", "substrate-build-script-utils", @@ -7672,9 +7965,9 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "sp-core", - "sp-keystore", - "sp-runtime", + "sp-core 28.0.0", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "thiserror", "tokio-util", "tracing-gum", @@ -7687,8 +7980,8 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "parity-scale-codec", "scale-info", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -7701,7 +7994,7 @@ dependencies = [ "fatality", "futures", "futures-timer", - "indexmap 2.2.3", + "indexmap 2.2.5", "parity-scale-codec", "polkadot-erasure-coding", "polkadot-node-network-protocol", @@ -7711,8 +8004,8 @@ dependencies = [ "polkadot-primitives", "sc-network", "schnellru", - "sp-application-crypto", - "sp-keystore", + "sp-application-crypto 30.0.0", + "sp-keystore 0.34.0", "thiserror", "tracing-gum", ] @@ -7726,8 +8019,8 @@ dependencies = [ "polkadot-node-primitives", "polkadot-primitives", "reed-solomon-novelpoly", - "sp-core", - "sp-trie", + "sp-core 28.0.0", + "sp-trie 29.0.0", "thiserror", ] @@ -7742,14 +8035,14 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "rand", + "rand 0.8.5", "rand_chacha 0.3.1", "sc-network", "sc-network-common", - "sp-application-crypto", - "sp-core", + "sp-application-crypto 30.0.0", + "sp-core 28.0.0", "sp-crypto-hashing", - "sp-keystore", + "sp-keystore 0.34.0", "tracing-gum", ] @@ -7788,7 +8081,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "sp-core", + "sp-core 28.0.0", "sp-maybe-compressed-blob", "thiserror", "tracing-gum", @@ -7813,16 +8106,16 @@ dependencies = [ "polkadot-node-subsystem-util", "polkadot-overseer", "polkadot-primitives", - "rand", + "rand 0.8.5", "rand_chacha 0.3.1", "rand_core 0.6.4", "sc-keystore", "schnellru", "schnorrkel 0.11.4", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-consensus", "sp-consensus-slots", - "sp-runtime", + "sp-runtime 31.0.1", "thiserror", "tracing-gum", ] @@ -7864,7 +8157,7 @@ dependencies = [ "polkadot-primitives", "polkadot-statement-table", "schnellru", - "sp-keystore", + "sp-keystore 0.34.0", "thiserror", "tracing-gum", ] @@ -7878,7 +8171,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "sp-keystore", + "sp-keystore 0.34.0", "thiserror", "tracing-gum", "wasm-timer", @@ -8028,9 +8321,9 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-parachain-primitives", "polkadot-primitives", - "rand", + "rand 0.8.5", "slotmap", - "sp-core", + "sp-core 28.0.0", "sp-maybe-compressed-blob", "sp-wasm-interface 20.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "tempfile", @@ -8050,7 +8343,7 @@ dependencies = [ "polkadot-node-subsystem-util", "polkadot-overseer", "polkadot-primitives", - "sp-keystore", + "sp-keystore 0.34.0", "thiserror", "tracing-gum", ] @@ -8073,10 +8366,10 @@ dependencies = [ "sc-executor-common", "sc-executor-wasmtime", "seccompiler", - "sp-core", + "sp-core 28.0.0", "sp-crypto-hashing", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-io", + "sp-io 30.0.0", "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "thiserror", "tracing-gum", @@ -8110,7 +8403,7 @@ dependencies = [ "polkadot-node-primitives", "polkadot-primitives", "sc-network", - "sp-core", + "sp-core 28.0.0", "thiserror", "tokio", ] @@ -8150,7 +8443,7 @@ dependencies = [ "polkadot-node-jaeger", "polkadot-node-primitives", "polkadot-primitives", - "rand", + "rand 0.8.5", "sc-authority-discovery", "sc-network", "strum 0.24.1", @@ -8171,12 +8464,12 @@ dependencies = [ "polkadot-primitives", "schnorrkel 0.11.4", "serde", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-consensus-babe", - "sp-core", - "sp-keystore", + "sp-core 28.0.0", + "sp-keystore 0.34.0", "sp-maybe-compressed-blob", - "sp-runtime", + "sp-runtime 31.0.1", "thiserror", "zstd 0.12.4", ] @@ -8214,7 +8507,7 @@ dependencies = [ "sp-authority-discovery", "sp-blockchain", "sp-consensus-babe", - "sp-runtime", + "sp-runtime 31.0.1", "substrate-prometheus-endpoint", "thiserror", ] @@ -8244,12 +8537,12 @@ dependencies = [ "polkadot-overseer", "polkadot-primitives", "prioritized-metered-channel", - "rand", + "rand 0.8.5", "sc-client-api", "schnellru", - "sp-application-crypto", - "sp-core", - "sp-keystore", + "sp-application-crypto 30.0.0", + "sp-core 28.0.0", + "sp-keystore 0.34.0", "thiserror", "tracing-gum", ] @@ -8271,7 +8564,7 @@ dependencies = [ "polkadot-primitives", "sc-client-api", "sp-api", - "sp-core", + "sp-core 28.0.0", "tikv-jemalloc-ctl", "tracing-gum", ] @@ -8281,16 +8574,16 @@ name = "polkadot-parachain-primitives" version = "6.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ - "bounded-collections", + "bounded-collections 0.2.0", "derive_more", "parity-scale-codec", "polkadot-core-primitives", "scale-info", "serde", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-weights", + "sp-weights 27.0.0", ] [[package]] @@ -8307,15 +8600,15 @@ dependencies = [ "scale-info", "serde", "sp-api", - "sp-application-crypto", - "sp-arithmetic", + "sp-application-crypto 30.0.0", + "sp-arithmetic 23.0.0", "sp-authority-discovery", "sp-consensus-slots", - "sp-core", + "sp-core 28.0.0", "sp-inherents", - "sp-io", - "sp-keystore", - "sp-runtime", + "sp-io 30.0.0", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -8347,8 +8640,8 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-babe", - "sp-keystore", - "sp-runtime", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "substrate-frame-rpc-system", "substrate-state-trie-migration-rpc", ] @@ -8391,11 +8684,11 @@ dependencies = [ "serde_derive", "slot-range-helper", "sp-api", - "sp-core", + "sp-core 28.0.0", "sp-inherents", - "sp-io", + "sp-io 30.0.0", "sp-npos-elections", - "sp-runtime", + "sp-runtime 31.0.1", "sp-session", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", @@ -8446,19 +8739,19 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-primitives", "polkadot-runtime-metrics", - "rand", + "rand 0.8.5", "rand_chacha 0.3.1", "rustc-hex", "scale-info", "serde", "sp-api", - "sp-application-crypto", - "sp-arithmetic", - "sp-core", + "sp-application-crypto 30.0.0", + "sp-arithmetic 23.0.0", + "sp-core 28.0.0", "sp-inherents", - "sp-io", - "sp-keystore", - "sp-runtime", + "sp-io 30.0.0", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "sp-session", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", @@ -8563,21 +8856,21 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-consensus-grandpa", - "sp-core", + "sp-core 28.0.0", "sp-inherents", - "sp-io", + "sp-io 30.0.0", "sp-keyring", - "sp-keystore", + "sp-keystore 0.34.0", "sp-mmr-primitives", "sp-offchain", - "sp-runtime", + "sp-runtime 31.0.1", "sp-session", - "sp-state-machine", + "sp-state-machine 0.35.0", "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-timestamp", "sp-transaction-pool", "sp-version", - "sp-weights", + "sp-weights 27.0.0", "substrate-prometheus-endpoint", "thiserror", "tracing-gum", @@ -8594,14 +8887,14 @@ dependencies = [ "fatality", "futures", "futures-timer", - "indexmap 2.2.3", + "indexmap 2.2.5", "parity-scale-codec", "polkadot-node-network-protocol", "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "sp-keystore", + "sp-keystore 0.34.0", "sp-staking", "thiserror", "tracing-gum", @@ -8614,7 +8907,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "parity-scale-codec", "polkadot-primitives", - "sp-core", + "sp-core 28.0.0", "tracing-gum", ] @@ -8637,7 +8930,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6380dbe1fb03ecc74ad55d841cfc75480222d153ba69ddcb00977866cbdabdb8" dependencies = [ "polkavm-derive-impl 0.5.0", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -8658,7 +8951,7 @@ dependencies = [ "polkavm-common 0.5.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -8670,7 +8963,7 @@ dependencies = [ "polkavm-common 0.8.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -8680,7 +8973,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15e85319a0d5129dc9f021c62607e0804f5fb777a05cdda44d750ac0732def66" dependencies = [ "polkavm-derive-impl 0.8.0", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -8736,6 +9029,17 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "pop-api" +version = "0.0.0" +dependencies = [ + "ink", + "ink_env", + "parity-scale-codec", + "scale-info", + "sp-runtime 24.0.0", +] + [[package]] name = "pop-node" version = "0.1.0" @@ -8783,10 +9087,10 @@ dependencies = [ "sp-block-builder", "sp-blockchain", "sp-consensus-aura", - "sp-core", - "sp-io", - "sp-keystore", - "sp-runtime", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "sp-timestamp", "staging-xcm", "substrate-build-script-utils", @@ -8805,6 +9109,8 @@ dependencies = [ "cumulus-pallet-xcmp-queue", "cumulus-primitives-core", "cumulus-primitives-utility", + "enumflags2", + "env_logger 0.11.2", "frame-benchmarking", "frame-executive", "frame-support", @@ -8812,6 +9118,7 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", + "hex", "hex-literal", "log", "pallet-assets", @@ -8841,12 +9148,12 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-consensus-aura", - "sp-core", + "sp-core 28.0.0", "sp-genesis-builder", "sp-inherents", - "sp-io", + "sp-io 30.0.0", "sp-offchain", - "sp-runtime", + "sp-runtime 31.0.1", "sp-session", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-transaction-pool", @@ -8923,7 +9230,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -9015,7 +9322,7 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -9061,7 +9368,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -9129,7 +9436,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -9196,7 +9503,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94b0b33c13a79f669c85defaf4c275dc86a0c0372807d0ca3d78e0bb87274863" dependencies = [ "bytes", - "rand", + "rand 0.8.5", "ring 0.16.20", "rustc-hash", "rustls 0.20.9", @@ -9222,6 +9529,19 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + [[package]] name = "rand" version = "0.8.5" @@ -9278,7 +9598,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" dependencies = [ "num-traits", - "rand", + "rand 0.8.5", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", ] [[package]] @@ -9298,9 +9627,9 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" +checksum = "e4963ed1bc86e4f3ee217022bd855b297cef07fb9eac5dfa1f788b220b49b3bd" dependencies = [ "either", "rayon-core", @@ -9386,7 +9715,7 @@ checksum = "5fddb4f8d99b0a2ebafc65a87a69a7b9875e4b1ae1f00db265d300ef7f28bccc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -9520,6 +9849,12 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "rlibc" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe" + [[package]] name = "rocksdb" version = "0.21.0" @@ -9601,18 +9936,18 @@ dependencies = [ "serde_derive", "smallvec", "sp-api", - "sp-arithmetic", + "sp-arithmetic 23.0.0", "sp-authority-discovery", "sp-block-builder", "sp-consensus-babe", "sp-consensus-beefy", - "sp-core", + "sp-core 28.0.0", "sp-genesis-builder", "sp-inherents", - "sp-io", + "sp-io 30.0.0", "sp-mmr-primitives", "sp-offchain", - "sp-runtime", + "sp-runtime 31.0.1", "sp-session", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", @@ -9635,9 +9970,9 @@ dependencies = [ "polkadot-primitives", "polkadot-runtime-common", "smallvec", - "sp-core", - "sp-runtime", - "sp-weights", + "sp-core 28.0.0", + "sp-runtime 31.0.1", + "sp-weights 27.0.0", "staging-xcm", "staging-xcm-builder", ] @@ -9874,7 +10209,7 @@ version = "23.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ "log", - "sp-core", + "sp-core 28.0.0", "sp-wasm-interface 20.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "thiserror", ] @@ -9895,15 +10230,15 @@ dependencies = [ "parity-scale-codec", "prost 0.12.3", "prost-build", - "rand", + "rand 0.8.5", "sc-client-api", "sc-network", "sp-api", "sp-authority-discovery", "sp-blockchain", - "sp-core", - "sp-keystore", - "sp-runtime", + "sp-core 28.0.0", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "substrate-prometheus-endpoint", "thiserror", ] @@ -9924,9 +10259,9 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-consensus", - "sp-core", + "sp-core 28.0.0", "sp-inherents", - "sp-runtime", + "sp-runtime 31.0.1", "substrate-prometheus-endpoint", ] @@ -9939,10 +10274,10 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-blockchain", - "sp-core", + "sp-core 28.0.0", "sp-inherents", - "sp-runtime", - "sp-trie", + "sp-runtime 31.0.1", + "sp-trie 29.0.0", ] [[package]] @@ -9963,12 +10298,12 @@ dependencies = [ "serde", "serde_json", "sp-blockchain", - "sp-core", + "sp-core 28.0.0", "sp-crypto-hashing", "sp-genesis-builder", - "sp-io", - "sp-runtime", - "sp-state-machine", + "sp-io 30.0.0", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", ] [[package]] @@ -9979,7 +10314,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -9998,7 +10333,7 @@ dependencies = [ "log", "names", "parity-scale-codec", - "rand", + "rand 0.8.5", "regex", "rpassword", "sc-client-api", @@ -10013,11 +10348,11 @@ dependencies = [ "serde", "serde_json", "sp-blockchain", - "sp-core", + "sp-core 28.0.0", "sp-keyring", - "sp-keystore", - "sp-panic-handler", - "sp-runtime", + "sp-keystore 0.34.0", + "sp-panic-handler 13.0.0", + "sp-runtime 31.0.1", "sp-version", "thiserror", "tokio", @@ -10039,14 +10374,14 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-consensus", - "sp-core", + "sp-core 28.0.0", "sp-database", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-runtime", - "sp-state-machine", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "sp-statement-store", "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", "substrate-prometheus-endpoint", ] @@ -10067,13 +10402,13 @@ dependencies = [ "sc-client-api", "sc-state-db", "schnellru", - "sp-arithmetic", + "sp-arithmetic 23.0.0", "sp-blockchain", - "sp-core", + "sp-core 28.0.0", "sp-database", - "sp-runtime", - "sp-state-machine", - "sp-trie", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", + "sp-trie 29.0.0", ] [[package]] @@ -10094,9 +10429,9 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-consensus", - "sp-core", - "sp-runtime", - "sp-state-machine", + "sp-core 28.0.0", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "substrate-prometheus-endpoint", "thiserror", ] @@ -10116,16 +10451,16 @@ dependencies = [ "sc-consensus-slots", "sc-telemetry", "sp-api", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-block-builder", "sp-blockchain", "sp-consensus", "sp-consensus-aura", "sp-consensus-slots", - "sp-core", + "sp-core 28.0.0", "sp-inherents", - "sp-keystore", - "sp-runtime", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "substrate-prometheus-endpoint", "thiserror", ] @@ -10151,17 +10486,17 @@ dependencies = [ "sc-telemetry", "sc-transaction-pool-api", "sp-api", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-block-builder", "sp-blockchain", "sp-consensus", "sp-consensus-babe", "sp-consensus-slots", - "sp-core", + "sp-core 28.0.0", "sp-crypto-hashing", "sp-inherents", - "sp-keystore", - "sp-runtime", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "substrate-prometheus-endpoint", "thiserror", ] @@ -10178,13 +10513,13 @@ dependencies = [ "sc-rpc-api", "serde", "sp-api", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-blockchain", "sp-consensus", "sp-consensus-babe", - "sp-core", - "sp-keystore", - "sp-runtime", + "sp-core 28.0.0", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "thiserror", ] @@ -10208,16 +10543,16 @@ dependencies = [ "sc-network-sync", "sc-utils", "sp-api", - "sp-application-crypto", - "sp-arithmetic", + "sp-application-crypto 30.0.0", + "sp-arithmetic 23.0.0", "sp-blockchain", "sp-consensus", "sp-consensus-beefy", - "sp-core", + "sp-core 28.0.0", "sp-crypto-hashing", - "sp-keystore", + "sp-keystore 0.34.0", "sp-mmr-primitives", - "sp-runtime", + "sp-runtime 31.0.1", "substrate-prometheus-endpoint", "thiserror", "tokio", @@ -10238,8 +10573,8 @@ dependencies = [ "sc-rpc", "serde", "sp-consensus-beefy", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "thiserror", ] @@ -10253,7 +10588,7 @@ dependencies = [ "sc-client-api", "sc-consensus", "sp-blockchain", - "sp-runtime", + "sp-runtime 31.0.1", ] [[package]] @@ -10261,7 +10596,7 @@ name = "sc-consensus-grandpa" version = "0.19.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ - "ahash 0.8.8", + "ahash 0.8.10", "array-bytes 6.2.2", "async-trait", "dyn-clone", @@ -10272,7 +10607,7 @@ dependencies = [ "log", "parity-scale-codec", "parking_lot 0.12.1", - "rand", + "rand 0.8.5", "sc-block-builder", "sc-chain-spec", "sc-client-api", @@ -10286,15 +10621,15 @@ dependencies = [ "sc-utils", "serde_json", "sp-api", - "sp-application-crypto", - "sp-arithmetic", + "sp-application-crypto 30.0.0", + "sp-arithmetic 23.0.0", "sp-blockchain", "sp-consensus", "sp-consensus-grandpa", - "sp-core", + "sp-core 28.0.0", "sp-crypto-hashing", - "sp-keystore", - "sp-runtime", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "substrate-prometheus-endpoint", "thiserror", ] @@ -10314,8 +10649,8 @@ dependencies = [ "sc-rpc", "serde", "sp-blockchain", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "thiserror", ] @@ -10332,14 +10667,14 @@ dependencies = [ "sc-client-api", "sc-consensus", "sc-telemetry", - "sp-arithmetic", + "sp-arithmetic 23.0.0", "sp-blockchain", "sp-consensus", "sp-consensus-slots", - "sp-core", + "sp-core 28.0.0", "sp-inherents", - "sp-runtime", - "sp-state-machine", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", ] [[package]] @@ -10353,12 +10688,12 @@ dependencies = [ "sc-executor-wasmtime", "schnellru", "sp-api", - "sp-core", + "sp-core 28.0.0", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-io", - "sp-panic-handler", + "sp-io 30.0.0", + "sp-panic-handler 13.0.0", "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", "sp-version", "sp-wasm-interface 20.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "tracing", @@ -10408,7 +10743,7 @@ dependencies = [ "sc-network-common", "sc-network-sync", "sp-blockchain", - "sp-runtime", + "sp-runtime 31.0.1", ] [[package]] @@ -10419,9 +10754,9 @@ dependencies = [ "array-bytes 6.2.2", "parking_lot 0.12.1", "serde_json", - "sp-application-crypto", - "sp-core", - "sp-keystore", + "sp-application-crypto 30.0.0", + "sp-core 28.0.0", + "sp-keystore 0.34.0", "thiserror", ] @@ -10447,10 +10782,10 @@ dependencies = [ "sc-transaction-pool-api", "sp-api", "sp-consensus", - "sp-core", - "sp-keystore", + "sp-core 28.0.0", + "sp-keystore 0.34.0", "sp-mixnet", - "sp-runtime", + "sp-runtime 31.0.1", "thiserror", ] @@ -10477,17 +10812,17 @@ dependencies = [ "parking_lot 0.12.1", "partial_sort", "pin-project", - "rand", + "rand 0.8.5", "sc-client-api", "sc-network-common", "sc-utils", "serde", "serde_json", "smallvec", - "sp-arithmetic", + "sp-arithmetic 23.0.0", "sp-blockchain", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "substrate-prometheus-endpoint", "thiserror", "tokio", @@ -10512,7 +10847,7 @@ dependencies = [ "sc-client-api", "sc-network", "sp-blockchain", - "sp-runtime", + "sp-runtime 31.0.1", "thiserror", "unsigned-varint", ] @@ -10531,7 +10866,7 @@ dependencies = [ "sc-consensus", "sp-consensus", "sp-consensus-grandpa", - "sp-runtime", + "sp-runtime 31.0.1", ] [[package]] @@ -10539,7 +10874,7 @@ name = "sc-network-gossip" version = "0.34.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ - "ahash 0.8.8", + "ahash 0.8.10", "futures", "futures-timer", "libp2p", @@ -10548,7 +10883,7 @@ dependencies = [ "sc-network-common", "sc-network-sync", "schnellru", - "sp-runtime", + "sp-runtime 31.0.1", "substrate-prometheus-endpoint", "tracing", ] @@ -10569,8 +10904,8 @@ dependencies = [ "sc-client-api", "sc-network", "sp-blockchain", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "thiserror", ] @@ -10598,12 +10933,12 @@ dependencies = [ "sc-utils", "schnellru", "smallvec", - "sp-arithmetic", + "sp-arithmetic 23.0.0", "sp-blockchain", "sp-consensus", "sp-consensus-grandpa", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "substrate-prometheus-endpoint", "thiserror", "tokio", @@ -10625,7 +10960,7 @@ dependencies = [ "sc-network-sync", "sc-utils", "sp-consensus", - "sp-runtime", + "sp-runtime 31.0.1", "substrate-prometheus-endpoint", ] @@ -10647,18 +10982,18 @@ dependencies = [ "once_cell", "parity-scale-codec", "parking_lot 0.12.1", - "rand", + "rand 0.8.5", "sc-client-api", "sc-network", "sc-network-common", "sc-transaction-pool-api", "sc-utils", "sp-api", - "sp-core", + "sp-core 28.0.0", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-keystore", + "sp-keystore 0.34.0", "sp-offchain", - "sp-runtime", + "sp-runtime 31.0.1", "threadpool", "tracing", ] @@ -10693,11 +11028,11 @@ dependencies = [ "serde_json", "sp-api", "sp-blockchain", - "sp-core", - "sp-keystore", + "sp-core 28.0.0", + "sp-keystore 0.34.0", "sp-offchain", "sp-rpc", - "sp-runtime", + "sp-runtime 31.0.1", "sp-session", "sp-statement-store", "sp-version", @@ -10717,9 +11052,9 @@ dependencies = [ "scale-info", "serde", "serde_json", - "sp-core", + "sp-core 28.0.0", "sp-rpc", - "sp-runtime", + "sp-runtime 31.0.1", "sp-version", "thiserror", ] @@ -10760,9 +11095,9 @@ dependencies = [ "serde", "sp-api", "sp-blockchain", - "sp-core", + "sp-core 28.0.0", "sp-rpc", - "sp-runtime", + "sp-runtime 31.0.1", "sp-version", "thiserror", "tokio", @@ -10784,7 +11119,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", "pin-project", - "rand", + "rand 0.8.5", "sc-chain-spec", "sc-client-api", "sc-client-db", @@ -10812,16 +11147,16 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-consensus", - "sp-core", + "sp-core 28.0.0", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-keystore", - "sp-runtime", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "sp-session", - "sp-state-machine", + "sp-state-machine 0.35.0", "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-transaction-pool", "sp-transaction-storage-proof", - "sp-trie", + "sp-trie 29.0.0", "sp-version", "static_init", "substrate-prometheus-endpoint", @@ -10840,7 +11175,7 @@ dependencies = [ "log", "parity-scale-codec", "parking_lot 0.12.1", - "sp-core", + "sp-core 28.0.0", ] [[package]] @@ -10851,7 +11186,7 @@ dependencies = [ "clap", "fs4", "log", - "sp-core", + "sp-core 28.0.0", "thiserror", "tokio", ] @@ -10871,7 +11206,7 @@ dependencies = [ "serde", "serde_json", "sp-blockchain", - "sp-runtime", + "sp-runtime 31.0.1", "thiserror", ] @@ -10884,15 +11219,15 @@ dependencies = [ "futures", "libc", "log", - "rand", + "rand 0.8.5", "rand_pcg", "regex", "sc-telemetry", "serde", "serde_json", - "sp-core", + "sp-core 28.0.0", "sp-crypto-hashing", - "sp-io", + "sp-io 30.0.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -10907,7 +11242,7 @@ dependencies = [ "log", "parking_lot 0.12.1", "pin-project", - "rand", + "rand 0.8.5", "sc-utils", "serde", "serde_json", @@ -10935,9 +11270,9 @@ dependencies = [ "serde", "sp-api", "sp-blockchain", - "sp-core", + "sp-core 28.0.0", "sp-rpc", - "sp-runtime", + "sp-runtime 31.0.1", "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "thiserror", "tracing", @@ -10953,7 +11288,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -10974,9 +11309,9 @@ dependencies = [ "serde", "sp-api", "sp-blockchain", - "sp-core", + "sp-core 28.0.0", "sp-crypto-hashing", - "sp-runtime", + "sp-runtime 31.0.1", "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-transaction-pool", "substrate-prometheus-endpoint", @@ -10994,8 +11329,8 @@ dependencies = [ "parity-scale-codec", "serde", "sp-blockchain", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "thiserror", ] @@ -11011,31 +11346,94 @@ dependencies = [ "log", "parking_lot 0.12.1", "prometheus", - "sp-arithmetic", + "sp-arithmetic 23.0.0", ] [[package]] -name = "scale-info" -version = "2.10.0" +name = "scale-bits" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7d66a1128282b7ef025a8ead62a4a9fcf017382ec53b8ffbf4d7bf77bd3c60" +checksum = "036575c29af9b6e4866ffb7fa055dbf623fe7a9cc159b33786de6013a6969d89" dependencies = [ - "bitvec", - "cfg-if", - "derive_more", "parity-scale-codec", - "scale-info-derive", - "serde", + "scale-info", ] [[package]] -name = "scale-info-derive" -version = "2.10.0" +name = "scale-decode" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf2c68b89cafb3b8d918dd07b42be0da66ff202cf1155c5739a4e0c1ea0dc19" +checksum = "7789f5728e4e954aaa20cadcc370b99096fb8645fca3c9333ace44bb18f30095" dependencies = [ - "proc-macro-crate 1.3.1", - "proc-macro2", + "derive_more", + "parity-scale-codec", + "scale-bits", + "scale-decode-derive", + "scale-info", + "smallvec", +] + +[[package]] +name = "scale-decode-derive" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27873eb6005868f8cc72dcfe109fae664cf51223d35387bc2f28be4c28d94c47" +dependencies = [ + "darling", + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "scale-encode" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d70cb4b29360105483fac1ed567ff95d65224a14dd275b6303ed0a654c78de5" +dependencies = [ + "derive_more", + "parity-scale-codec", + "scale-encode-derive", + "scale-info", + "smallvec", +] + +[[package]] +name = "scale-encode-derive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "995491f110efdc6bea96d6a746140e32bfceb4ea47510750a5467295a4707a25" +dependencies = [ + "darling", + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "scale-info" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7d66a1128282b7ef025a8ead62a4a9fcf017382ec53b8ffbf4d7bf77bd3c60" +dependencies = [ + "bitvec", + "cfg-if", + "derive_more", + "parity-scale-codec", + "scale-info-derive", + "serde", +] + +[[package]] +name = "scale-info-derive" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf2c68b89cafb3b8d918dd07b42be0da66ff202cf1155c5739a4e0c1ea0dc19" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro2", "quote", "syn 1.0.109", ] @@ -11055,7 +11453,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "772575a524feeb803e5b0fcbc6dd9f367e579488197c94c6e4023aad2305774d" dependencies = [ - "ahash 0.8.8", + "ahash 0.8.10", "cfg-if", "hashbrown 0.13.2", ] @@ -11069,7 +11467,9 @@ dependencies = [ "arrayref", "arrayvec 0.5.2", "curve25519-dalek 2.1.3", + "getrandom 0.1.16", "merlin 2.0.1", + "rand 0.7.3", "rand_core 0.5.1", "sha2 0.8.2", "subtle 2.5.0", @@ -11156,13 +11556,49 @@ dependencies = [ "libc", ] +[[package]] +name = "secp256k1" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1629c9c557ef9b293568b338dddfc8208c98a18c59d722a9d53f859d9c9b62" +dependencies = [ + "secp256k1-sys 0.6.1", +] + +[[package]] +name = "secp256k1" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" +dependencies = [ + "secp256k1-sys 0.8.1", +] + [[package]] name = "secp256k1" version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" dependencies = [ - "secp256k1-sys", + "secp256k1-sys 0.9.2", +] + +[[package]] +name = "secp256k1-sys" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83080e2c2fc1006e625be82e5d1eb6a43b7fd9578b617fcc55814daf286bba4b" +dependencies = [ + "cc", +] + +[[package]] +name = "secp256k1-sys" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" +dependencies = [ + "cc", ] [[package]] @@ -11256,14 +11692,14 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] name = "serde_json" -version = "1.0.113" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ "itoa", "ryu", @@ -11373,6 +11809,12 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" + [[package]] name = "signature" version = "2.2.0" @@ -11430,7 +11872,7 @@ dependencies = [ "enumn", "parity-scale-codec", "paste", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -11502,7 +11944,7 @@ dependencies = [ "pbkdf2 0.12.2", "pin-project", "poly1305", - "rand", + "rand 0.8.5", "rand_chacha 0.3.1", "ruzstd", "schnorrkel 0.10.2", @@ -11545,7 +11987,7 @@ dependencies = [ "no-std-net", "parking_lot 0.12.1", "pin-project", - "rand", + "rand 0.8.5", "rand_chacha 0.3.1", "serde", "serde_json", @@ -11591,12 +12033,12 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.5" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -11612,7 +12054,7 @@ dependencies = [ "http", "httparse", "log", - "rand", + "rand 0.8.5", "sha-1", ] @@ -11626,13 +12068,13 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api-proc-macro", - "sp-core", + "sp-core 28.0.0", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-metadata-ir", - "sp-runtime", - "sp-state-machine", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", "sp-version", "thiserror", ] @@ -11648,7 +12090,21 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", +] + +[[package]] +name = "sp-application-crypto" +version = "23.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899492ea547816d5dfe9a5a2ecc32f65a7110805af6da3380aa4902371b31dc2" +dependencies = [ + "parity-scale-codec", + "scale-info", + "serde", + "sp-core 21.0.0", + "sp-io 23.0.0", + "sp-std 8.0.0", ] [[package]] @@ -11659,11 +12115,26 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core", - "sp-io", + "sp-core 28.0.0", + "sp-io 30.0.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] +[[package]] +name = "sp-arithmetic" +version = "16.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6020576e544c6824a51d651bc8df8e6ab67cd59f1c9ac09868bb81a5199ded" +dependencies = [ + "integer-sqrt", + "num-traits", + "parity-scale-codec", + "scale-info", + "serde", + "sp-std 8.0.0", + "static_assertions", +] + [[package]] name = "sp-arithmetic" version = "23.0.0" @@ -11704,8 +12175,8 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api", - "sp-application-crypto", - "sp-runtime", + "sp-application-crypto 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -11716,7 +12187,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "sp-api", "sp-inherents", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -11733,8 +12204,8 @@ dependencies = [ "sp-api", "sp-consensus", "sp-database", - "sp-runtime", - "sp-state-machine", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "thiserror", ] @@ -11746,10 +12217,10 @@ dependencies = [ "async-trait", "futures", "log", - "sp-core", + "sp-core 28.0.0", "sp-inherents", - "sp-runtime", - "sp-state-machine", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "thiserror", ] @@ -11762,10 +12233,10 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-consensus-slots", "sp-inherents", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-timestamp", ] @@ -11780,11 +12251,11 @@ dependencies = [ "scale-info", "serde", "sp-api", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-consensus-slots", - "sp-core", + "sp-core 28.0.0", "sp-inherents", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-timestamp", ] @@ -11799,12 +12270,12 @@ dependencies = [ "scale-info", "serde", "sp-api", - "sp-application-crypto", - "sp-core", + "sp-application-crypto 30.0.0", + "sp-core 28.0.0", "sp-crypto-hashing", - "sp-io", + "sp-io 30.0.0", "sp-mmr-primitives", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "strum 0.24.1", ] @@ -11820,10 +12291,10 @@ dependencies = [ "scale-info", "serde", "sp-api", - "sp-application-crypto", - "sp-core", - "sp-keystore", - "sp-runtime", + "sp-application-crypto 30.0.0", + "sp-core 28.0.0", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -11839,6 +12310,51 @@ dependencies = [ "sp-timestamp", ] +[[package]] +name = "sp-core" +version = "21.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f18d9e2f67d8661f9729f35347069ac29d92758b59135176799db966947a7336" +dependencies = [ + "array-bytes 4.2.0", + "bitflags 1.3.2", + "blake2 0.10.6", + "bounded-collections 0.1.9", + "bs58 0.4.0", + "dyn-clonable", + "ed25519-zebra 3.1.0", + "futures", + "hash-db", + "hash256-std-hasher", + "impl-serde", + "lazy_static", + "libsecp256k1", + "log", + "merlin 2.0.1", + "parity-scale-codec", + "parking_lot 0.12.1", + "paste", + "primitive-types", + "rand 0.8.5", + "regex", + "scale-info", + "schnorrkel 0.9.1", + "secp256k1 0.24.3", + "secrecy", + "serde", + "sp-core-hashing", + "sp-debug-derive 8.0.0", + "sp-externalities 0.19.0", + "sp-runtime-interface 17.0.0", + "sp-std 8.0.0", + "sp-storage 13.0.0", + "ss58-registry", + "substrate-bip39", + "thiserror", + "tiny-bip39", + "zeroize", +] + [[package]] name = "sp-core" version = "28.0.0" @@ -11849,7 +12365,7 @@ dependencies = [ "bip39", "bitflags 1.3.2", "blake2 0.10.6", - "bounded-collections", + "bounded-collections 0.2.0", "bs58 0.5.0", "dyn-clonable", "ed25519-zebra 3.1.0", @@ -11865,10 +12381,10 @@ dependencies = [ "parking_lot 0.12.1", "paste", "primitive-types", - "rand", + "rand 0.8.5", "scale-info", "schnorrkel 0.11.4", - "secp256k1", + "secp256k1 0.28.2", "secrecy", "serde", "sp-crypto-hashing", @@ -11885,6 +12401,21 @@ dependencies = [ "zeroize", ] +[[package]] +name = "sp-core-hashing" +version = "9.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ee599a8399448e65197f9a6cee338ad192e9023e35e31f22382964c3c174c68" +dependencies = [ + "blake2b_simd", + "byteorder", + "digest 0.10.7", + "sha2 0.10.8", + "sha3", + "sp-std 8.0.0", + "twox-hash", +] + [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" @@ -11926,7 +12457,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "quote", "sp-crypto-hashing", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -11938,6 +12469,17 @@ dependencies = [ "parking_lot 0.12.1", ] +[[package]] +name = "sp-debug-derive" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f531814d2f16995144c74428830ccf7d94ff4a7749632b83ad8199b181140c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + [[package]] name = "sp-debug-derive" version = "14.0.0" @@ -11945,7 +12487,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -11955,7 +12497,19 @@ source = "git+https://github.com/paritytech/polkadot-sdk#f1b2189e8312821a9f8a79d dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", +] + +[[package]] +name = "sp-externalities" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0f71c671e01a8ca60da925d43a1b351b69626e268b8837f8371e320cf1dd100" +dependencies = [ + "environmental", + "parity-scale-codec", + "sp-std 8.0.0", + "sp-storage 13.0.0", ] [[package]] @@ -11987,7 +12541,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "serde_json", "sp-api", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -12000,32 +12554,59 @@ dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", "scale-info", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "thiserror", ] +[[package]] +name = "sp-io" +version = "23.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d597e35a9628fe7454b08965b2442e3ec0f264b0a90d41328e87422cec02e99" +dependencies = [ + "bytes", + "ed25519 1.5.3", + "ed25519-dalek 1.0.1", + "futures", + "libsecp256k1", + "log", + "parity-scale-codec", + "rustversion", + "secp256k1 0.24.3", + "sp-core 21.0.0", + "sp-externalities 0.19.0", + "sp-keystore 0.27.0", + "sp-runtime-interface 17.0.0", + "sp-state-machine 0.28.0", + "sp-std 8.0.0", + "sp-tracing 10.0.0", + "sp-trie 22.0.0", + "tracing", + "tracing-core", +] + [[package]] name = "sp-io" version = "30.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ "bytes", - "ed25519-dalek", + "ed25519-dalek 2.1.1", "libsecp256k1", "log", "parity-scale-codec", "rustversion", - "secp256k1", - "sp-core", + "secp256k1 0.28.2", + "sp-core 28.0.0", "sp-crypto-hashing", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-keystore", + "sp-keystore 0.34.0", "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-state-machine", + "sp-state-machine 0.35.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", "tracing", "tracing-core", ] @@ -12035,11 +12616,25 @@ name = "sp-keyring" version = "31.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "strum 0.24.1", ] +[[package]] +name = "sp-keystore" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9be3cdd67cc1d9c1db17c5cbc4ec4924054a8437009d167f21f6590797e4aa45" +dependencies = [ + "futures", + "parity-scale-codec", + "parking_lot 0.12.1", + "sp-core 21.0.0", + "sp-externalities 0.19.0", + "thiserror", +] + [[package]] name = "sp-keystore" version = "0.34.0" @@ -12047,7 +12642,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", - "sp-core", + "sp-core 28.0.0", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "thiserror", ] @@ -12080,7 +12675,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api", - "sp-application-crypto", + "sp-application-crypto 30.0.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -12095,9 +12690,9 @@ dependencies = [ "scale-info", "serde", "sp-api", - "sp-core", + "sp-core 28.0.0", "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "thiserror", ] @@ -12110,9 +12705,9 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-arithmetic", - "sp-core", - "sp-runtime", + "sp-arithmetic 23.0.0", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -12122,8 +12717,19 @@ version = "26.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ "sp-api", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", +] + +[[package]] +name = "sp-panic-handler" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd2de46003fa8212426838ca71cd42ee36a26480ba9ffea983506ce03131033" +dependencies = [ + "backtrace", + "lazy_static", + "regex", ] [[package]] @@ -12143,7 +12749,30 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "rustc-hash", "serde", - "sp-core", + "sp-core 28.0.0", +] + +[[package]] +name = "sp-runtime" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21c5bfc764a1a8259d7e8f7cfd22c84006275a512c958d3ff966c92151e134d5" +dependencies = [ + "either", + "hash256-std-hasher", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "paste", + "rand 0.8.5", + "scale-info", + "serde", + "sp-application-crypto 23.0.0", + "sp-arithmetic 16.0.0", + "sp-core 21.0.0", + "sp-io 23.0.0", + "sp-std 8.0.0", + "sp-weights 20.0.0", ] [[package]] @@ -12158,16 +12787,35 @@ dependencies = [ "log", "parity-scale-codec", "paste", - "rand", + "rand 0.8.5", "scale-info", "serde", "simple-mermaid", - "sp-application-crypto", - "sp-arithmetic", - "sp-core", - "sp-io", + "sp-application-crypto 30.0.0", + "sp-arithmetic 23.0.0", + "sp-core 28.0.0", + "sp-io 30.0.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-weights", + "sp-weights 27.0.0", +] + +[[package]] +name = "sp-runtime-interface" +version = "17.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e676128182f90015e916f806cba635c8141e341e7abbc45d25525472e1bbce8" +dependencies = [ + "bytes", + "impl-trait-for-tuples", + "parity-scale-codec", + "primitive-types", + "sp-externalities 0.19.0", + "sp-runtime-interface-proc-macro 11.0.0", + "sp-std 8.0.0", + "sp-storage 13.0.0", + "sp-tracing 10.0.0", + "sp-wasm-interface 14.0.0", + "static_assertions", ] [[package]] @@ -12207,6 +12855,19 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "sp-runtime-interface-proc-macro" +version = "11.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d5bd5566fe5633ec48dfa35ab152fd29f8a577c21971e1c6db9f28afb9bbb9" +dependencies = [ + "Inflector", + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 2.0.52", +] + [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" @@ -12217,7 +12878,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -12230,7 +12891,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -12241,9 +12902,9 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api", - "sp-core", - "sp-keystore", - "sp-runtime", + "sp-core 28.0.0", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -12257,11 +12918,32 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] +[[package]] +name = "sp-state-machine" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ef45d31f9e7ac648f8899a0cd038a3608f8499028bff55b6c799702592325b6" +dependencies = [ + "hash-db", + "log", + "parity-scale-codec", + "parking_lot 0.12.1", + "rand 0.8.5", + "smallvec", + "sp-core 21.0.0", + "sp-externalities 0.19.0", + "sp-panic-handler 8.0.0", + "sp-std 8.0.0", + "sp-trie 22.0.0", + "thiserror", + "tracing", +] + [[package]] name = "sp-state-machine" version = "0.35.0" @@ -12271,16 +12953,16 @@ dependencies = [ "log", "parity-scale-codec", "parking_lot 0.12.1", - "rand", + "rand 0.8.5", "smallvec", - "sp-core", + "sp-core 28.0.0", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-panic-handler", + "sp-panic-handler 13.0.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", "thiserror", "tracing", - "trie-db", + "trie-db 0.28.0", ] [[package]] @@ -12290,24 +12972,30 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "aes-gcm", "curve25519-dalek 4.1.2", - "ed25519-dalek", + "ed25519-dalek 2.1.1", "hkdf", "parity-scale-codec", - "rand", + "rand 0.8.5", "scale-info", "sha2 0.10.8", "sp-api", - "sp-application-crypto", - "sp-core", + "sp-application-crypto 30.0.0", + "sp-core 28.0.0", "sp-crypto-hashing", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-runtime", + "sp-runtime 31.0.1", "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "thiserror", "x25519-dalek 2.0.1", ] +[[package]] +name = "sp-std" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53458e3c57df53698b3401ec0934bea8e8cfce034816873c0b0abbd83d7bac0d" + [[package]] name = "sp-std" version = "14.0.0" @@ -12318,6 +13006,20 @@ name = "sp-std" version = "14.0.0" source = "git+https://github.com/paritytech/polkadot-sdk#f1b2189e8312821a9f8a79dc4f0183d314273faa" +[[package]] +name = "sp-storage" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94294be83f11d4958cfea89ed5798f0b6605f5defc3a996948848458abbcc18e" +dependencies = [ + "impl-serde", + "parity-scale-codec", + "ref-cast", + "serde", + "sp-debug-derive 8.0.0", + "sp-std 8.0.0", +] + [[package]] name = "sp-storage" version = "19.0.0" @@ -12352,11 +13054,24 @@ dependencies = [ "async-trait", "parity-scale-codec", "sp-inherents", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "thiserror", ] +[[package]] +name = "sp-tracing" +version = "10.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357f7591980dd58305956d32f8f6646d0a8ea9ea0e7e868e46f53b68ddf00cec" +dependencies = [ + "parity-scale-codec", + "sp-std 8.0.0", + "tracing", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "sp-tracing" version = "16.0.0" @@ -12387,7 +13102,7 @@ version = "26.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ "sp-api", - "sp-runtime", + "sp-runtime 31.0.1", ] [[package]] @@ -12398,11 +13113,35 @@ dependencies = [ "async-trait", "parity-scale-codec", "scale-info", - "sp-core", + "sp-core 28.0.0", "sp-inherents", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-trie", + "sp-trie 29.0.0", +] + +[[package]] +name = "sp-trie" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4eeb7ef23f79eba8609db79ef9cef242f994f1f87a3c0387b4b5f177fda74" +dependencies = [ + "ahash 0.8.10", + "hash-db", + "hashbrown 0.13.2", + "lazy_static", + "memory-db", + "nohash-hasher", + "parity-scale-codec", + "parking_lot 0.12.1", + "scale-info", + "schnellru", + "sp-core 21.0.0", + "sp-std 8.0.0", + "thiserror", + "tracing", + "trie-db 0.27.1", + "trie-root", ] [[package]] @@ -12410,22 +13149,22 @@ name = "sp-trie" version = "29.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ - "ahash 0.8.8", + "ahash 0.8.10", "hash-db", "lazy_static", "memory-db", "nohash-hasher", "parity-scale-codec", "parking_lot 0.12.1", - "rand", + "rand 0.8.5", "scale-info", "schnellru", - "sp-core", + "sp-core 28.0.0", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "thiserror", "tracing", - "trie-db", + "trie-db 0.28.0", "trie-root", ] @@ -12440,7 +13179,7 @@ dependencies = [ "scale-info", "serde", "sp-crypto-hashing-proc-macro", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-version-proc-macro", "thiserror", @@ -12454,7 +13193,21 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", +] + +[[package]] +name = "sp-wasm-interface" +version = "14.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19c122609ca5d8246be6386888596320d03c7bc880959eaa2c36bcd5acd6846" +dependencies = [ + "anyhow", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "sp-std 8.0.0", + "wasmtime", ] [[package]] @@ -12483,17 +13236,33 @@ dependencies = [ "wasmtime", ] +[[package]] +name = "sp-weights" +version = "20.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45d084c735544f70625b821c3acdbc7a2fc1893ca98b85f1942631284692c75b" +dependencies = [ + "parity-scale-codec", + "scale-info", + "serde", + "smallvec", + "sp-arithmetic 16.0.0", + "sp-core 21.0.0", + "sp-debug-derive 8.0.0", + "sp-std 8.0.0", +] + [[package]] name = "sp-weights" version = "27.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ - "bounded-collections", + "bounded-collections 0.2.0", "parity-scale-codec", "scale-info", "serde", "smallvec", - "sp-arithmetic", + "sp-arithmetic 23.0.0", "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -12562,7 +13331,7 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-runtime", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", ] @@ -12572,7 +13341,7 @@ version = "7.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1#2a91d5abdc56ed27dab36030db5fa3c9c92e60a9" dependencies = [ "array-bytes 6.2.2", - "bounded-collections", + "bounded-collections 0.2.0", "derivative", "environmental", "impl-trait-for-tuples", @@ -12580,7 +13349,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-weights", + "sp-weights 27.0.0", "xcm-procedural", ] @@ -12597,11 +13366,11 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain-primitives", "scale-info", - "sp-arithmetic", - "sp-io", - "sp-runtime", + "sp-arithmetic 23.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-weights", + "sp-weights 27.0.0", "staging-xcm", "staging-xcm-executor", ] @@ -12618,12 +13387,12 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-arithmetic", - "sp-core", - "sp-io", - "sp-runtime", + "sp-arithmetic 23.0.0", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", - "sp-weights", + "sp-weights 27.0.0", "staging-xcm", ] @@ -12674,6 +13443,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "strsim" version = "0.11.0" @@ -12718,7 +13493,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -12754,8 +13529,8 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-blockchain", - "sp-core", - "sp-runtime", + "sp-core 28.0.0", + "sp-runtime 31.0.1", ] [[package]] @@ -12780,7 +13555,7 @@ dependencies = [ "log", "sc-rpc-api", "serde", - "sp-runtime", + "sp-runtime 31.0.1", ] [[package]] @@ -12793,11 +13568,11 @@ dependencies = [ "sc-client-api", "sc-rpc-api", "serde", - "sp-core", - "sp-runtime", - "sp-state-machine", - "sp-trie", - "trie-db", + "sp-core 28.0.0", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", + "sp-trie 29.0.0", + "trie-db 0.28.0", ] [[package]] @@ -12849,9 +13624,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.50" +version = "2.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" dependencies = [ "proc-macro2", "quote", @@ -12870,6 +13645,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -12899,15 +13685,15 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "target-lexicon" -version = "0.12.13" +version = "0.12.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae" +checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" [[package]] name = "tempfile" -version = "3.10.0" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", "fastrand 2.0.1", @@ -12966,7 +13752,7 @@ checksum = "e4c60d69f36615a077cc7663b9cb8e42275722d23e58a7fa3d2c7f2915d09d04" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -12977,7 +13763,7 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -12988,9 +13774,9 @@ checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" [[package]] name = "thread_local" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" dependencies = [ "cfg-if", "once_cell", @@ -13070,6 +13856,25 @@ dependencies = [ "time-core", ] +[[package]] +name = "tiny-bip39" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62cc94d358b5a1e84a5cb9109f559aa3c4d634d2b1b4de3d0fa4adc7c78e2861" +dependencies = [ + "anyhow", + "hmac 0.12.1", + "once_cell", + "pbkdf2 0.11.0", + "rand 0.8.5", + "rustc-hash", + "sha2 0.10.8", + "thiserror", + "unicode-normalization", + "wasm-bindgen", + "zeroize", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -13108,7 +13913,7 @@ dependencies = [ "parking_lot 0.12.1", "pin-project-lite 0.2.13", "signal-hook-registry", - "socket2 0.5.5", + "socket2 0.5.6", "tokio-macros", "windows-sys 0.48.0", ] @@ -13121,7 +13926,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -13131,7 +13936,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f57eb36ecbe0fc510036adff84824dd3c24bb781e21bfa67b69d556aa85214f" dependencies = [ "pin-project", - "rand", + "rand 0.8.5", "tokio", ] @@ -13208,7 +14013,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.2.3", + "indexmap 2.2.5", "toml_datetime", "winnow 0.5.40", ] @@ -13219,7 +14024,7 @@ version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" dependencies = [ - "indexmap 2.2.3", + "indexmap 2.2.5", "toml_datetime", "winnow 0.5.40", ] @@ -13230,7 +14035,7 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ - "indexmap 2.2.3", + "indexmap 2.2.5", "toml_datetime", "winnow 0.5.40", ] @@ -13241,11 +14046,11 @@ version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c1b5fd4128cc8d3e0cb74d4ed9a9cc7c7284becd4df68f5f940e1ad123606f6" dependencies = [ - "indexmap 2.2.3", + "indexmap 2.2.5", "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.2", + "winnow 0.6.5", ] [[package]] @@ -13313,7 +14118,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -13356,7 +14161,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -13403,6 +14208,19 @@ dependencies = [ "tracing-serde", ] +[[package]] +name = "trie-db" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "767abe6ffed88a1889671a102c2861ae742726f52e0a5a425b92c9fbfa7e9c85" +dependencies = [ + "hash-db", + "hashbrown 0.13.2", + "log", + "rustc-hex", + "smallvec", +] + [[package]] name = "trie-db" version = "0.28.0" @@ -13441,7 +14259,7 @@ dependencies = [ "idna 0.2.3", "ipnet", "lazy_static", - "rand", + "rand 0.8.5", "smallvec", "socket2 0.4.10", "thiserror", @@ -13496,19 +14314,19 @@ dependencies = [ "sp-api", "sp-consensus-aura", "sp-consensus-babe", - "sp-core", + "sp-core 28.0.0", "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", "sp-inherents", - "sp-io", - "sp-keystore", + "sp-io 30.0.0", + "sp-keystore 0.34.0", "sp-rpc", - "sp-runtime", - "sp-state-machine", + "sp-runtime 31.0.1", + "sp-state-machine 0.35.0", "sp-timestamp", "sp-transaction-storage-proof", "sp-version", - "sp-weights", + "sp-weights 27.0.0", "substrate-rpc-client", "zstd 0.12.4", ] @@ -13527,7 +14345,7 @@ checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if", "digest 0.10.7", - "rand", + "rand 0.8.5", "static_assertions", ] @@ -13678,7 +14496,7 @@ dependencies = [ "arrayref", "constcat", "digest 0.10.7", - "rand", + "rand 0.8.5", "rand_chacha 0.3.1", "rand_core 0.6.4", "sha2 0.10.8", @@ -13754,7 +14572,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", "wasm-bindgen-shared", ] @@ -13788,7 +14606,7 @@ checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -14088,7 +14906,7 @@ dependencies = [ "memfd", "memoffset", "paste", - "rand", + "rand 0.8.5", "rustix 0.36.17", "wasmtime-asm-macros", "wasmtime-environ", @@ -14216,20 +15034,20 @@ dependencies = [ "serde_derive", "smallvec", "sp-api", - "sp-application-crypto", - "sp-arithmetic", + "sp-application-crypto 30.0.0", + "sp-arithmetic 23.0.0", "sp-authority-discovery", "sp-block-builder", "sp-consensus-babe", "sp-consensus-beefy", - "sp-core", + "sp-core 28.0.0", "sp-genesis-builder", "sp-inherents", - "sp-io", + "sp-io 30.0.0", "sp-mmr-primitives", "sp-npos-elections", "sp-offchain", - "sp-runtime", + "sp-runtime 31.0.1", "sp-session", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.1)", @@ -14252,9 +15070,9 @@ dependencies = [ "polkadot-primitives", "polkadot-runtime-common", "smallvec", - "sp-core", - "sp-runtime", - "sp-weights", + "sp-core 28.0.0", + "sp-runtime 31.0.1", + "sp-weights 27.0.0", "staging-xcm", "staging-xcm-builder", ] @@ -14343,7 +15161,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.4", ] [[package]] @@ -14370,7 +15188,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.4", ] [[package]] @@ -14405,17 +15223,17 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", ] [[package]] @@ -14432,9 +15250,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" [[package]] name = "windows_aarch64_msvc" @@ -14450,9 +15268,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[package]] name = "windows_i686_gnu" @@ -14468,9 +15286,9 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[package]] name = "windows_i686_msvc" @@ -14486,9 +15304,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[package]] name = "windows_x86_64_gnu" @@ -14504,9 +15322,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[package]] name = "windows_x86_64_gnullvm" @@ -14522,9 +15340,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[package]] name = "windows_x86_64_msvc" @@ -14540,9 +15358,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "winnow" @@ -14555,9 +15373,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.2" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a4191c47f15cc3ec71fcb4913cb83d58def65dd3787610213c649283b5ce178" +checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" dependencies = [ "memchr", ] @@ -14630,9 +15448,15 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] +[[package]] +name = "xxhash-rust" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927da81e25be1e1a2901d59b81b37dd2efd1fc9c9345a55007f09bf5a2d3ee03" + [[package]] name = "yamux" version = "0.10.2" @@ -14643,7 +15467,7 @@ dependencies = [ "log", "nohash-hasher", "parking_lot 0.12.1", - "rand", + "rand 0.8.5", "static_assertions", ] @@ -14673,7 +15497,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] @@ -14693,7 +15517,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.50", + "syn 2.0.52", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 9aadd630..22df83b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,9 +12,10 @@ repository = "https://github.com/r0gue-io/pop-node/" members = [ "node", "runtime", + "pop-api", ] exclude = [ - "demo-contracts" + "contracts" ] resolver = "2" diff --git a/demo-contracts/.gitignore b/contracts/pop-api-examples/balance-transfer/.gitignore similarity index 100% rename from demo-contracts/.gitignore rename to contracts/pop-api-examples/balance-transfer/.gitignore diff --git a/demo-contracts/Cargo.toml b/contracts/pop-api-examples/balance-transfer/Cargo.toml similarity index 100% rename from demo-contracts/Cargo.toml rename to contracts/pop-api-examples/balance-transfer/Cargo.toml diff --git a/demo-contracts/lib.rs b/contracts/pop-api-examples/balance-transfer/lib.rs similarity index 100% rename from demo-contracts/lib.rs rename to contracts/pop-api-examples/balance-transfer/lib.rs diff --git a/contracts/pop-api-examples/nfts/.gitignore b/contracts/pop-api-examples/nfts/.gitignore new file mode 100755 index 00000000..8de8f877 --- /dev/null +++ b/contracts/pop-api-examples/nfts/.gitignore @@ -0,0 +1,9 @@ +# Ignore build artifacts from the local tests sub-crate. +/target/ + +# Ignore backup files creates by cargo fmt. +**/*.rs.bk + +# Remove Cargo.lock when creating an executable, leave it for libraries +# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock +Cargo.lock diff --git a/contracts/pop-api-examples/nfts/Cargo.toml b/contracts/pop-api-examples/nfts/Cargo.toml new file mode 100755 index 00000000..282d9a82 --- /dev/null +++ b/contracts/pop-api-examples/nfts/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "pop_api_nft_example" +version = "0.1.0" +authors = ["[your_name] <[your_email]>"] +edition = "2021" + +[dependencies] +ink = { version = "4.3.0", default-features = false } +pop-api = { path = "../../../pop-api", default-features = false } +scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } +scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } +sp-io = { version = "23.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } +sp-runtime = { version = "24.0.0", default-features = false } + +[dev-dependencies] +ink_e2e = "4.3.0" + +[lib] +path = "lib.rs" + +[features] +default = ["std"] +std = [ + "ink/std", + "scale/std", + "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "pop-api/std", +] +ink-as-dependency = [] +e2e-tests = [] diff --git a/contracts/pop-api-examples/nfts/lib.rs b/contracts/pop-api-examples/nfts/lib.rs new file mode 100755 index 00000000..df8bb9d1 --- /dev/null +++ b/contracts/pop-api-examples/nfts/lib.rs @@ -0,0 +1,58 @@ +#![cfg_attr(not(feature = "std"), no_std, no_main)] + +use pop_api::PopApiError; + +#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] +#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] +pub enum ContractError { + SomeError, +} + +impl From for ContractError { + fn from(_value: PopApiError) -> Self { + ContractError::SomeError + } +} + +#[ink::contract(env = pop_api::PopEnv)] +mod pop_api_extension_demo { + use super::ContractError; + + #[ink(storage)] + #[derive(Default)] + pub struct PopApiExtensionDemo; + + impl PopApiExtensionDemo { + #[ink(constructor, payable)] + pub fn new() -> Self { + ink::env::debug_println!("PopApiExtensionDemo::new"); + Default::default() + } + + #[ink(message)] + pub fn mint_through_runtime( + &mut self, + collection_id: u32, + item_id: u32, + receiver: AccountId, + ) -> Result<(), ContractError> { + ink::env::debug_println!("PopApiExtensionDemo::mint_through_runtime: collection_id: {:?} \nitem_id {:?} \nreceiver: {:?}, ", collection_id, item_id, receiver); + + // simplified API call + pop_api::nfts::mint(collection_id, item_id, receiver)?; + + ink::env::debug_println!("PopApiExtensionDemo::mint_through_runtime end"); + Ok(()) + } + } + + #[cfg(test)] + mod tests { + use super::*; + + #[ink::test] + fn default_works() { + PopApiExtensionDemo::new(); + } + } +} diff --git a/pop-api/.gitignore b/pop-api/.gitignore new file mode 100644 index 00000000..9170f591 --- /dev/null +++ b/pop-api/.gitignore @@ -0,0 +1,15 @@ +.idea/ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb diff --git a/pop-api/Cargo.toml b/pop-api/Cargo.toml new file mode 100644 index 00000000..ee581ba6 --- /dev/null +++ b/pop-api/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "pop-api" +description = "Reserved crate for pop-api." +license = "GPL-3.0-only" +version = "0.0.0" +edition = "2021" + +[dependencies] +ink = { version = "4.3.0", default-features = false } +ink_env = { version = "4.3.0", default-features = false } +sp-runtime = { version = "24.0.0", default-features = false } +scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } +scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } + +[lib] +name = "pop_api" +path = "src/lib.rs" +crate-type = [ + "rlib", +] + +[features] +default = ["std"] +std = [ + "ink/std", + "sp-runtime/std", + "scale/std", + "scale-info/std", +] diff --git a/pop-api/README.md b/pop-api/README.md new file mode 100644 index 00000000..f37ae208 --- /dev/null +++ b/pop-api/README.md @@ -0,0 +1 @@ +Reserved crate for pop-api. \ No newline at end of file diff --git a/pop-api/src/lib.rs b/pop-api/src/lib.rs new file mode 100644 index 00000000..0f9f7f70 --- /dev/null +++ b/pop-api/src/lib.rs @@ -0,0 +1,77 @@ +#![cfg_attr(not(feature = "std"), no_std, no_main)] + +pub mod v0; + +use ink::{env::Environment, prelude::vec::Vec, ChainExtensionInstance}; +use scale; +use sp_runtime::MultiSignature; +pub use v0::nfts; +use v0::RuntimeCall; + +// Id used for identifying non-fungible collections. +pub type CollectionId = u32; + +// Id used for identifying non-fungible items. +pub type ItemId = u32; + +type AccountId = ::AccountId; +type Balance = ::Balance; +type BlockNumber = ::BlockNumber; +type Signature = MultiSignature; +type StringLimit = u32; +type KeyLimit = u32; +type MaxTips = u32; + +pub type Result = core::result::Result; + +#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] +#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] +pub enum PopApiError { + PlaceholderError, +} + +impl ink::env::chain_extension::FromStatusCode for PopApiError { + fn from_status_code(status_code: u32) -> core::result::Result<(), Self> { + match status_code { + 0 => Ok(()), + 1 => Err(Self::PlaceholderError), + _ => panic!("encountered unknown status code"), + } + } +} + +impl From for PopApiError { + fn from(_: scale::Error) -> Self { + panic!("encountered unexpected invalid SCALE encoding") + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] +pub enum PopEnv {} + +impl Environment for PopEnv { + const MAX_EVENT_TOPICS: usize = ::MAX_EVENT_TOPICS; + + type AccountId = ::AccountId; + type Balance = ::Balance; + type Hash = ::Hash; + type BlockNumber = ::BlockNumber; + type Timestamp = ::Timestamp; + + type ChainExtension = PopApi; +} + +#[ink::chain_extension] +pub trait PopApi { + type ErrorCode = PopApiError; + + #[ink(extension = 0xfecb)] + #[allow(private_interfaces)] + fn dispatch(call: RuntimeCall) -> crate::Result>; +} + +fn call_runtime(call: RuntimeCall) -> Result> { + <::ChainExtension as ChainExtensionInstance>::instantiate() + .dispatch(call) +} diff --git a/pop-api/src/v0/balances.rs b/pop-api/src/v0/balances.rs new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/pop-api/src/v0/balances.rs @@ -0,0 +1 @@ + diff --git a/pop-api/src/v0/mod.rs b/pop-api/src/v0/mod.rs new file mode 100644 index 00000000..9692c233 --- /dev/null +++ b/pop-api/src/v0/mod.rs @@ -0,0 +1,8 @@ +pub mod balances; +pub mod nfts; + +#[derive(scale::Encode)] +pub(crate) enum RuntimeCall { + #[codec(index = 50)] + Nfts(nfts::NftCalls), +} diff --git a/pop-api/src/v0/nfts.rs b/pop-api/src/v0/nfts.rs new file mode 100644 index 00000000..127f393b --- /dev/null +++ b/pop-api/src/v0/nfts.rs @@ -0,0 +1,213 @@ +use super::RuntimeCall; +use crate::*; +use ink::prelude::vec::Vec; +use sp_runtime::{BoundedVec, MultiAddress}; + +pub fn mint( + collection: CollectionId, + item: ItemId, + mint_to: impl Into>, +) -> Result<()> { + crate::call_runtime(RuntimeCall::Nfts(NftCalls::Mint { + collection, + item, + mint_to: mint_to.into(), + witness_data: None, + }))?; + Ok(()) +} + +#[derive(scale::Encode)] +pub(crate) enum NftCalls { + // #[codec(index = 0)] + // Create { + // admin: MultiAddress, + // config: CollectionConfig + // }, + #[codec(index = 2)] + Destroy { collection: CollectionId }, + #[codec(index = 3)] + Mint { + collection: CollectionId, + item: ItemId, + mint_to: MultiAddress, + witness_data: Option<()>, + }, + #[codec(index = 5)] + Burn { + collection: CollectionId, + item: ItemId, + }, + #[codec(index = 6)] + Transfer { + collection: CollectionId, + item: ItemId, + dest: MultiAddress, + }, + #[codec(index = 7)] + Redeposit { + collection: CollectionId, + items: Vec, + }, + #[codec(index = 8)] + LockItemTransfer { + collection: CollectionId, + item: ItemId, + }, + #[codec(index = 9)] + UnlockItemTransfer { + collection: CollectionId, + item: ItemId, + }, + // #[codec(index = 10)] + // LockCollection { + // collection: CollectionId, + // lock_settings: CollectionSettings, + // }, + #[codec(index = 11)] + TransferOwnership { + collection: CollectionId, + new_owner: MultiAddress, + }, + #[codec(index = 12)] + SetTeam { + collection: CollectionId, + issuer: Option>, + admin: Option>, + freezer: Option>, + }, + #[codec(index = 15)] + ApproveTransfer { + collection: CollectionId, + item: ItemId, + delegate: MultiAddress, + maybe_deadline: Option, + }, + #[codec(index = 16)] + CancelApproval { + collection: CollectionId, + item: ItemId, + delegate: MultiAddress, + }, + #[codec(index = 17)] + ClearAllTransferApprovals { + collection: CollectionId, + item: ItemId, + }, + #[codec(index = 18)] + LockItemProperties { + collection: CollectionId, + item: ItemId, + lock_metadata: bool, + lock_attributes: bool, + }, + // #[codec(index = 19)] + // SetAttribute { + // collection: CollectionId, + // maybe_item: Option, + // namespace: AttributeNamespace, + // key: BoundedVec, + // value: BoundedVec, + // }, + // #[codec(index = 21)] + // ClearAttribute { + // collection: CollectionId, + // maybe_item: Option, + // namespace: AttributeNamespace, + // key: BoundedVec, + // }, + #[codec(index = 22)] + ApproveItemAttribute { + collection: CollectionId, + item: ItemId, + delegate: MultiAddress, + }, + #[codec(index = 23)] + CancelItemAttributesApproval { + collection: CollectionId, + item: ItemId, + delegate: MultiAddress, + }, + #[codec(index = 24)] + SetMetadata { + collection: CollectionId, + item: ItemId, + data: BoundedVec, + }, + #[codec(index = 25)] + ClearMetadata { + collection: CollectionId, + item: ItemId, + }, + #[codec(index = 26)] + SetCollectionMetadata { + collection: CollectionId, + data: BoundedVec, + }, + #[codec(index = 27)] + ClearCollectionMetadata { collection: CollectionId }, + #[codec(index = 28)] + SetAcceptOwnership { + collection: CollectionId, + maybe_collection: Option, + }, + #[codec(index = 29)] + SetCollectionMaxSupply { + collection: CollectionId, + max_supply: u32, + }, + // #[codec(index = 30)] + // UpdateMintSettings { + // collection: CollectionId, + // mint_settings: MintSettings, + // }, + #[codec(index = 31)] + Price { + collection: CollectionId, + item: ItemId, + price: Option, + }, + #[codec(index = 32)] + BuyItem { + collection: CollectionId, + item: ItemId, + bid_price: Balance, + }, + // #[codec(index = 33)] + // PayTips { + // tips: BoundedVec, MaxTips> + // }, + // #[codec(index = 34)] + // CreateSwap { + // offered_collection: CollectionId, + // offered_item: ItemId, + // desired_collection: CollectionId, + // maybe_desired_item: Option, + // maybe_price: Option>, + // duration: BlockNumber, + // }, + #[codec(index = 35)] + CancelSwap { + offered_collection: CollectionId, + offered_item: ItemId, + }, + #[codec(index = 36)] + ClaimSwap { + send_collection: CollectionId, + send_item: ItemId, + receive_collection: CollectionId, + receive_item: ItemId, + }, + // #[codec(index = 37)] + // MintPreSigned { + // mint_data: PreSignedMint, + // signature: OffchainSignature, + // signer: AccountId + // }, + // #[codec(index = 38)] + // SetAttributesPreSigned { + // data: PreSignedAttributes, + // signature: OffchainSignature, + // signer: AccountId, + // } +} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 55e33628..a47ddbca 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -83,6 +83,7 @@ parachain-info = { workspace = true } [dev-dependencies] env_logger = "0.11.2" hex = "0.4.3" +enumflags2 = "0.7.9" [features] default = ["std"] diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs index ad704d30..7e3b77c5 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions/pop_api_extension.rs @@ -72,7 +72,7 @@ where let len = env.in_len(); let call: ::RuntimeCall = env.read_as_unbounded(len)?; - log::trace!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); + log::debug!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); let sender = env.ext().caller(); let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); @@ -83,10 +83,10 @@ where let result = call.dispatch(origin); match result { Ok(info) => { - log::trace!(target:LOG_TARGET, "dispatch success, actual weight: {:?}", info.actual_weight); + log::debug!(target:LOG_TARGET, "dispatch success, actual weight: {:?}", info.actual_weight); } Err(err) => { - log::trace!(target:LOG_TARGET, "dispatch failed: error: {:?}", err.error); + log::debug!(target:LOG_TARGET, "dispatch failed: error: {:?}", err.error); return Err(err.error); } } @@ -107,6 +107,7 @@ where E: Ext, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, { + log::debug!(target:LOG_TARGET, " extension called "); let func_id = FuncId::try_from(env.func_id())?; match func_id { FuncId::CallRuntime => dispatch::(env)?, @@ -120,10 +121,13 @@ where mod tests { pub use super::*; pub use crate::*; + use enumflags2::BitFlags; pub use pallet_contracts::Code; + use pallet_nfts::{CollectionConfig, CollectionSetting, CollectionSettings, MintSettings}; + use parachains_common::CollectionId; pub use sp_runtime::{traits::Hash, AccountId32}; - pub const DEBUG_OUTPUT: pallet_contracts::DebugInfo = pallet_contracts::DebugInfo::Skip; + pub const DEBUG_OUTPUT: pallet_contracts::DebugInfo = pallet_contracts::DebugInfo::UnsafeDebug; pub const ALICE: AccountId32 = AccountId32::new([1_u8; 32]); pub const BOB: AccountId32 = AccountId32::new([2_u8; 32]); @@ -146,12 +150,13 @@ mod tests { ext } - pub fn load_wasm_module() -> std::io::Result<(Vec, ::Output)> + pub fn load_wasm_module( + path: &str, + ) -> std::io::Result<(Vec, ::Output)> where T: frame_system::Config, { - let fixture_path = "../demo-contracts/target/ink/pop_api_extension_demo.wasm"; - let wasm_binary = std::fs::read(fixture_path)?; + let wasm_binary = std::fs::read(path)?; let code_hash = T::Hashing::hash(&wasm_binary); Ok((wasm_binary, code_hash)) } @@ -161,12 +166,27 @@ mod tests { [hash[0..4].to_vec()].concat() } + // NFT helper functions + fn collection_config_from_disabled_settings( + settings: BitFlags, + ) -> CollectionConfig { + CollectionConfig { + settings: CollectionSettings::from_disabled(settings), + max_supply: None, + mint_settings: MintSettings::default(), + } + } + + fn default_collection_config() -> CollectionConfig { + collection_config_from_disabled_settings(CollectionSetting::DepositRequired.into()) + } + #[test] fn test_dispatch() { new_test_ext().execute_with(|| { let _ = env_logger::try_init(); - let (wasm_binary, _) = load_wasm_module::().unwrap(); + let (wasm_binary, _) = load_wasm_module::("../contracts/pop-api-examples/balance-transfer/target/ink/pop_api_extension_demo.wasm").unwrap(); let init_value = 100; @@ -226,4 +246,92 @@ mod tests { assert_eq!(bob_balance_before + value_to_send, bob_balance_after); }); } + + #[test] + fn test_nfts_mint() { + new_test_ext().execute_with(|| { + let _ = env_logger::try_init(); + + let (wasm_binary, _) = load_wasm_module::( + "../contracts/pop-api-examples/nfts/target/ink/pop_api_nft_example.wasm", + ) + .unwrap(); + + let init_value = 100; + + let result = Contracts::bare_instantiate( + ALICE, + init_value, + GAS_LIMIT, + None, + Code::Upload(wasm_binary), + function_selector("new"), + vec![], + DEBUG_OUTPUT, + pallet_contracts::CollectEvents::Skip, + ) + .result + .unwrap(); + + assert!( + !result.result.did_revert(), + "deploying contract reverted {:?}", + result + ); + + let addr = result.account_id; + + let collection_id: u32 = 0; + let item_id: u32 = 1; + + // create nft collection + assert_eq!( + Nfts::force_create( + RuntimeOrigin::root(), + ALICE.into(), + default_collection_config() + ), + Ok(()) + ); + + assert_eq!(Nfts::collection_owner(collection_id), Some(ALICE.into())); + // assert that the item does not exist yet + assert_eq!(Nfts::owner(collection_id, item_id), None); + + let function = function_selector("mint_through_runtime"); + + let params = [ + function, + collection_id.encode(), + item_id.encode(), + BOB.encode(), + ] + .concat(); + + let result = Contracts::bare_call( + ALICE, + addr.clone(), + 0, + Weight::from_parts(100_000_000_000, 3 * 1024 * 1024), + None, + params, + DEBUG_OUTPUT, + pallet_contracts::CollectEvents::Skip, + pallet_contracts::Determinism::Enforced, + ); + + if DEBUG_OUTPUT == pallet_contracts::DebugInfo::UnsafeDebug { + log::debug!( + "Contract debug buffer - {:?}", + String::from_utf8(result.debug_message.clone()) + ); + log::debug!("result: {:?}", result); + } + + // check for revert + assert!(!result.result.unwrap().did_revert(), "Contract reverted!"); + + assert_eq!(Nfts::owner(collection_id, item_id), Some(BOB.into())); + }); + } } From 1e03a65683c322151bc2e70ae6cc4811d2a60bf8 Mon Sep 17 00:00:00 2001 From: Peter White Date: Sat, 2 Mar 2024 14:46:20 -0700 Subject: [PATCH 08/19] feat: add secure weight charging for pop-api extension --- runtime/src/extensions/pop_api_extension.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs index 7e3b77c5..c3f1bf21 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions/pop_api_extension.rs @@ -60,26 +60,24 @@ where { let mut env = env.buf_in_buf_out(); - // charge max weight before reading contract memory - // TODO: causing "1010: block limits exhausted" error - // let weight_limit = env.ext().gas_meter().gas_left(); - // let charged_weight = env.charge_weight(weight_limit)?; - - // TODO: debug_message weight is a good approximation of the additional overhead of going - // from contract layer to substrate layer. - // input length let len = env.in_len(); let call: ::RuntimeCall = env.read_as_unbounded(len)?; + // conservative weight estimate for deserializing the input. The actual weight is less and should utilize a custom benchmark + let base_weight: Weight = T::DbWeight::get().reads(len.into()); + + // weight for dispatching the call + let dispatch_weight = call.get_dispatch_info().weight; + + // charge weight for the cost of the deserialization and the dispatch + let _ = env.charge_weight(base_weight.saturating_add(dispatch_weight))?; + log::debug!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); let sender = env.ext().caller(); let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); - // TODO: uncomment once charged_weight is fixed - // let actual_weight = call.get_dispatch_info().weight; - // env.adjust_weight(charged_weight, actual_weight); let result = call.dispatch(origin); match result { Ok(info) => { From ed77f199597238f49da40a1c1e852399b685f152 Mon Sep 17 00:00:00 2001 From: Peter White Date: Mon, 4 Mar 2024 09:47:34 -0700 Subject: [PATCH 09/19] chore: update zombienet config --- networks/rococo.toml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/networks/rococo.toml b/networks/rococo.toml index 41fd5941..4f581f5e 100644 --- a/networks/rococo.toml +++ b/networks/rococo.toml @@ -4,7 +4,7 @@ node_spawn_timeout = 300 [relaychain] chain = "rococo-local" -default_command = "./bin/polkadot" +default_command = "./cache/polkadot-v1.7.1" [[relaychain.nodes]] name = "alice" @@ -19,4 +19,7 @@ id = 909 default_command = "./target/release/pop-node" [[parachains.collators]] - name = "pop" \ No newline at end of file + name = "pop" + command = "./target/release/pop-node" + port = 9944 + args = ["-lruntime::contracts=debug", "-lpopapi::extension=debug"] \ No newline at end of file From 2156a369c29d116d87b820a4f079444885e1cf58 Mon Sep 17 00:00:00 2001 From: Alejandro Martinez Andres <11448715+al3mart@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:56:33 +0100 Subject: [PATCH 10/19] feat: query_state & pop_api_primitives (#14) * demo_contract:query_runtime * pop-api-ext:query * read relay_block# & state * unused import * ci: add build workflow * chore: improve zombienet config * ci: grant write permission to actions * feat: initialize pop-api directory * feat: add codec indexes, and wrap NFT interface * feat: add example contract utilizing pop-api crate -- not working * feat: minting NFT from contract through runtime works * feat: generic state reads * chore: fmt * RuntimeStateKeys * clean keys * fmt * cumulus_parachain_system is accessible --------- Co-authored-by: Frank Bell Co-authored-by: Peter White --- Cargo.lock | 12 +- Cargo.toml | 2 + .../balance-transfer/Cargo.toml | 1 - .../pop-api-examples/balance-transfer/lib.rs | 9 +- .../read-runtime-state/.gitignore | 9 + .../read-runtime-state/Cargo.toml | 33 +++ .../read-runtime-state/lib.rs | 224 ++++++++++++++++++ pop-api/Cargo.toml | 5 +- pop-api/primitives/Cargo.toml | 28 +++ pop-api/primitives/src/lib.rs | 1 + pop-api/primitives/src/storage_keys.rs | 11 + pop-api/src/lib.rs | 1 + runtime/Cargo.toml | 3 + runtime/src/extensions/ext_impl/dispatch.rs | 64 +++++ runtime/src/extensions/ext_impl/mod.rs | 2 + runtime/src/extensions/ext_impl/read_state.rs | 33 +++ runtime/src/extensions/mod.rs | 1 + runtime/src/extensions/pop_api_extension.rs | 56 +---- 18 files changed, 442 insertions(+), 53 deletions(-) create mode 100755 contracts/pop-api-examples/read-runtime-state/.gitignore create mode 100755 contracts/pop-api-examples/read-runtime-state/Cargo.toml create mode 100755 contracts/pop-api-examples/read-runtime-state/lib.rs create mode 100644 pop-api/primitives/Cargo.toml create mode 100644 pop-api/primitives/src/lib.rs create mode 100644 pop-api/primitives/src/storage_keys.rs create mode 100644 runtime/src/extensions/ext_impl/dispatch.rs create mode 100644 runtime/src/extensions/ext_impl/mod.rs create mode 100644 runtime/src/extensions/ext_impl/read_state.rs diff --git a/Cargo.lock b/Cargo.lock index 26c55acf..75af935a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9034,7 +9034,16 @@ name = "pop-api" version = "0.0.0" dependencies = [ "ink", - "ink_env", + "parity-scale-codec", + "pop-api-primitives", + "scale-info", + "sp-runtime 24.0.0", +] + +[[package]] +name = "pop-api-primitives" +version = "0.0.0" +dependencies = [ "parity-scale-codec", "scale-info", "sp-runtime 24.0.0", @@ -9143,6 +9152,7 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain-primitives", "polkadot-runtime-common", + "pop-api-primitives", "scale-info", "smallvec", "sp-api", diff --git a/Cargo.toml b/Cargo.toml index 22df83b4..9fe934cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,9 @@ substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", b substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1" } # Local + pop-runtime = { path = "./runtime" } +pop-api-primitives = { path = "./pop-api/primitives"} # Substrate sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1" } diff --git a/contracts/pop-api-examples/balance-transfer/Cargo.toml b/contracts/pop-api-examples/balance-transfer/Cargo.toml index 88ab4506..cee76dd5 100755 --- a/contracts/pop-api-examples/balance-transfer/Cargo.toml +++ b/contracts/pop-api-examples/balance-transfer/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" [dependencies] ink = { version = "4.3.0", default-features = false } - scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } diff --git a/contracts/pop-api-examples/balance-transfer/lib.rs b/contracts/pop-api-examples/balance-transfer/lib.rs index 53dc73a2..0ed81f21 100755 --- a/contracts/pop-api-examples/balance-transfer/lib.rs +++ b/contracts/pop-api-examples/balance-transfer/lib.rs @@ -1,6 +1,5 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] - use ink::{ env::Environment, prelude::vec::Vec, @@ -8,6 +7,8 @@ use ink::{ use ink::primitives::AccountId; use sp_runtime::MultiAddress; +use scale::{Encode, Decode}; +use scale_info::TypeInfo; /// A part of the runtime dispatchable API. /// @@ -19,7 +20,7 @@ use sp_runtime::MultiAddress; /// You can investigate the full `RuntimeCall` definition by either expanding /// `construct_runtime!` macro application or by using secondary tools for reading chain /// metadata, like `subxt`. -#[derive(scale::Encode)] +#[derive(Encode, Decode, TypeInfo)] enum RuntimeCall { /// This index can be found by investigating runtime configuration. You can check the /// pallet order inside `construct_runtime!` block and read the position of your @@ -80,6 +81,10 @@ pub trait PopApi { /// operations. #[ink(extension = 0xfecb)] fn dispatch(call: RuntimeCall) -> Result>; + + #[ink(extension = 0xfeca)] + fn read_state(key: SafeKeys) -> Result>; + } impl ink::env::chain_extension::FromStatusCode for PopApiError { diff --git a/contracts/pop-api-examples/read-runtime-state/.gitignore b/contracts/pop-api-examples/read-runtime-state/.gitignore new file mode 100755 index 00000000..8de8f877 --- /dev/null +++ b/contracts/pop-api-examples/read-runtime-state/.gitignore @@ -0,0 +1,9 @@ +# Ignore build artifacts from the local tests sub-crate. +/target/ + +# Ignore backup files creates by cargo fmt. +**/*.rs.bk + +# Remove Cargo.lock when creating an executable, leave it for libraries +# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock +Cargo.lock diff --git a/contracts/pop-api-examples/read-runtime-state/Cargo.toml b/contracts/pop-api-examples/read-runtime-state/Cargo.toml new file mode 100755 index 00000000..b53f8415 --- /dev/null +++ b/contracts/pop-api-examples/read-runtime-state/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "pop_api_extension_demo" +version = "0.1.0" +authors = ["[your_name] <[your_email]>"] +edition = "2021" + +[dependencies] +ink = { version = "4.3.0", default-features = false } +scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } +scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } + +pop-api = { path = "../../../pop-api", default-features = false } + +sp-io = { version = "23.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } +sp-runtime = { version = "24.0.0", default-features = false } + +[dev-dependencies] +ink_e2e = "4.3.0" + +[lib] +path = "lib.rs" + +[features] +default = ["std"] +std = [ + "ink/std", + "scale/std", + "scale-info/std", + "sp-runtime/std", + "sp-io/std", +] +ink-as-dependency = [] +e2e-tests = [] diff --git a/contracts/pop-api-examples/read-runtime-state/lib.rs b/contracts/pop-api-examples/read-runtime-state/lib.rs new file mode 100755 index 00000000..391ff857 --- /dev/null +++ b/contracts/pop-api-examples/read-runtime-state/lib.rs @@ -0,0 +1,224 @@ +#![cfg_attr(not(feature = "std"), no_std, no_main)] + +use ink::{ + env::Environment, + prelude::vec::Vec, +}; + +use ink::primitives::AccountId; +use sp_runtime::MultiAddress; +use pop_api::storage_keys::RuntimeStateKeys::ParachainSystemKeys; + + +#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] +#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] +pub enum PopApiError { + TotalSupplyFailed, +} + +pub type Result = core::result::Result; + +use scale; +impl From for PopApiError { + fn from(_: scale::Error) -> Self { + panic!("encountered unexpected invalid SCALE encoding") + } +} + +/// This is an example of how an ink! contract may call the Substrate +/// runtime function `RandomnessCollectiveFlip::random_seed`. See the +/// file `runtime/chain-extension-example.rs` for that implementation. +/// +/// Here we define the operations to interact with the Substrate runtime. +#[ink::chain_extension] +pub trait PopApi { + type ErrorCode = PopApiError; + + /// Note: this gives the operation a corresponding `func_id` (1101 in this case), + /// and the chain-side chain extension will get the `func_id` to do further + /// operations. + + #[ink(extension = 0xfeca)] + fn read_relay_block_number(key: LastRelayChainBlockNumber) -> Result; + +} + +impl ink::env::chain_extension::FromStatusCode for PopApiError { + fn from_status_code(status_code: u32) -> core::result::Result<(), Self> { + match status_code { + 0 => Ok(()), + 1 => Err(Self::TotalSupplyFailed), + _ => panic!("encountered unknown status code"), + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] +pub enum CustomEnvironment {} + +impl Environment for CustomEnvironment { + const MAX_EVENT_TOPICS: usize = + ::MAX_EVENT_TOPICS; + + type AccountId = ::AccountId; + type Balance = ::Balance; + type Hash = ::Hash; + type BlockNumber = ::BlockNumber; + type Timestamp = ::Timestamp; + + type ChainExtension = PopApi; +} + +#[ink::contract(env = crate::CustomEnvironment)] +mod pop_api_extension_demo { + use crate::{ + BalancesCall, + RuntimeCall, + }; + + use super::PopApiError; + + use ink::env::Error as EnvError; + + #[ink(event)] + pub struct RelayBlockNumberRead { + value: BlockNumber + } + + /// A trivial contract with a single message, that uses `call-runtime` API for + /// performing native token transfer. + #[ink(storage)] + #[derive(Default)] + pub struct PopApiExtensionDemo; + + impl From for PopApiError { + fn from(e: EnvError) -> Self { + match e { + EnvError::CallRuntimeFailed => PopApiError::TotalSupplyFailed, + _ => panic!("Unexpected error from `pallet-contracts`."), + } + } + } + + impl PopApiExtensionDemo { + #[ink(constructor, payable)] + pub fn new() -> Self { + ink::env::debug_println!("PopApiExtensionDemo::new"); + Default::default() + } + + #[ink(message)] + pub fn read_relay_block_number( + &self + ) { + let state = self.env().extension().read_state(LastRelayChainBlockNumber); + ink::env::debug_println!("{:?}", state); + ink::env().emit_event( + RelayBlockNumberRead {value: state} + ); + } + } + + #[cfg(all(test, feature = "e2e-tests"))] + mod e2e_tests { + use super::*; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; + + use ink::{ + env::{ + test::default_accounts, + DefaultEnvironment, + }, + primitives::AccountId, + }; + + type E2EResult = Result>; + + /// The base number of indivisible units for balances on the + /// `substrate-contracts-node`. + const UNIT: Balance = 1_000_000_000_000; + + /// The contract will be given 1000 tokens during instantiation. + const CONTRACT_BALANCE: Balance = 1_000 * UNIT; + + /// The receiver will get enough funds to have the required existential deposit. + /// + /// If your chain has this threshold higher, increase the transfer value. + const TRANSFER_VALUE: Balance = 1 / 10 * UNIT; + + /// An amount that is below the existential deposit, so that a transfer to an + /// empty account fails. + /// + /// Must not be zero, because such an operation would be a successful no-op. + const INSUFFICIENT_TRANSFER_VALUE: Balance = 1; + + /// Positive case scenario: + /// - the call is valid + /// - the call execution succeeds + #[ink_e2e::test] + async fn transfer_with_call_runtime_works( + mut client: Client, + ) -> E2EResult<()> { + // given + let mut constructor = RuntimeCallerRef::new(); + let contract = client + .instantiate("call-runtime", &ink_e2e::alice(), &mut constructor) + .value(CONTRACT_BALANCE) + .submit() + .await + .expect("instantiate failed"); + let mut call_builder = contract.call_builder::(); + + let accounts = default_accounts::(); + + let receiver: AccountId = accounts.bob; + + let sender_balance_before = client + .free_balance(accounts.alice) + .await + .expect("Failed to get account balance"); + let receiver_balance_before = client + .free_balance(receiver) + .await + .expect("Failed to get account balance"); + + // when + let transfer_message = + call_builder.transfer_through_runtime(receiver, TRANSFER_VALUE); + + let call_res = client + .call(&ink_e2e::alice(), &transfer_message) + .submit() + .await + .expect("call failed"); + + assert!(call_res.return_value().is_ok()); + + // then + let sender_balance_after = client + .free_balance(accounts.alice) + .await + .expect("Failed to get account balance"); + let receiver_balance_after = client + .free_balance(receiver) + .await + .expect("Failed to get account balance"); + + assert_eq!( + contract_balance_before, + contract_balance_after + TRANSFER_VALUE + ); + assert_eq!( + receiver_balance_before, + receiver_balance_after - TRANSFER_VALUE + ); + + Ok(()) + } + + } +} \ No newline at end of file diff --git a/pop-api/Cargo.toml b/pop-api/Cargo.toml index ee581ba6..b2ffb628 100644 --- a/pop-api/Cargo.toml +++ b/pop-api/Cargo.toml @@ -6,9 +6,12 @@ version = "0.0.0" edition = "2021" [dependencies] + +pop-api-primitives = { path = "./primitives" } + ink = { version = "4.3.0", default-features = false } -ink_env = { version = "4.3.0", default-features = false } sp-runtime = { version = "24.0.0", default-features = false } + scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } diff --git a/pop-api/primitives/Cargo.toml b/pop-api/primitives/Cargo.toml new file mode 100644 index 00000000..0fa865b0 --- /dev/null +++ b/pop-api/primitives/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "pop-api-primitives" +description = "Reserved crate for pop-api-primitives." +license = "GPL-3.0-only" +version = "0.0.0" +edition = "2021" + +[dependencies] +sp-runtime = { version = "24.0.0", default-features = false } + +scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } +scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } + +[lib] +name = "pop_api_primitives" +path = "src/lib.rs" +crate-type = [ + "rlib", +] + + +[features] +default = ["std"] +std = [ + "sp-runtime/std", + "scale/std", + "scale-info/std", +] diff --git a/pop-api/primitives/src/lib.rs b/pop-api/primitives/src/lib.rs new file mode 100644 index 00000000..d37a392a --- /dev/null +++ b/pop-api/primitives/src/lib.rs @@ -0,0 +1 @@ +pub mod storage_keys; diff --git a/pop-api/primitives/src/storage_keys.rs b/pop-api/primitives/src/storage_keys.rs new file mode 100644 index 00000000..a67f3a18 --- /dev/null +++ b/pop-api/primitives/src/storage_keys.rs @@ -0,0 +1,11 @@ +use scale::{Decode, Encode}; + +#[derive(Encode, Decode, Debug)] +pub enum RuntimeStateKeys { + ParachainSystem(ParachainSystemKeys), +} + +#[derive(Encode, Decode, Debug)] +pub enum ParachainSystemKeys { + LastRelayChainBlockNumber, +} diff --git a/pop-api/src/lib.rs b/pop-api/src/lib.rs index 0f9f7f70..6eae52a6 100644 --- a/pop-api/src/lib.rs +++ b/pop-api/src/lib.rs @@ -1,5 +1,6 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] +use pop_api_primitives::storage_keys; pub mod v0; use ink::{env::Environment, prelude::vec::Vec, ChainExtensionInstance}; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index a47ddbca..603c8c96 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -21,6 +21,9 @@ log = { workspace = true } scale-info = { workspace = true } smallvec = { workspace = true } +# Local +pop-api-primitives = { workspace = true } + # Substrate frame-benchmarking = { workspace = true } diff --git a/runtime/src/extensions/ext_impl/dispatch.rs b/runtime/src/extensions/ext_impl/dispatch.rs new file mode 100644 index 00000000..df804bc7 --- /dev/null +++ b/runtime/src/extensions/ext_impl/dispatch.rs @@ -0,0 +1,64 @@ +use frame_support::{ + dispatch::{GetDispatchInfo, PostDispatchInfo, RawOrigin}, + pallet_prelude::*, +}; +use log; +use pallet_contracts::chain_extension::{Environment, Ext, InitState, SysConfig}; +use sp_core::crypto::UncheckedFrom; +use sp_runtime::{traits::Dispatchable, DispatchError}; + +const LOG_TARGET: &str = "popapi::extension::dispatch"; + +pub(crate) fn dispatch(env: Environment) -> Result<(), DispatchError> +where + T: pallet_contracts::Config + frame_system::Config, + ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, + ::RuntimeCall: Parameter + + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> + + GetDispatchInfo + + From>, + E: Ext, +{ + let mut env = env.buf_in_buf_out(); + + // charge max weight before reading contract memory + // TODO: causing "1010: block limits exhausted" error + // let weight_limit = env.ext().gas_meter().gas_left(); + // let charged_weight = env.charge_weight(weight_limit)?; + + // TODO: debug_message weight is a good approximation of the additional overhead of going + // from contract layer to substrate layer. + + // input length + let len = env.in_len(); + let call: ::RuntimeCall = env.read_as_unbounded(len)?; + + // conservative weight estimate for deserializing the input. The actual weight is less and should utilize a custom benchmark + let base_weight: Weight = T::DbWeight::get().reads(len.into()); + + // weight for dispatching the call + let dispatch_weight = call.get_dispatch_info().weight; + + // charge weight for the cost of the deserialization and the dispatch + let _ = env.charge_weight(base_weight.saturating_add(dispatch_weight))?; + + log::debug!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); + + let sender = env.ext().caller(); + let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); + + // TODO: uncomment once charged_weight is fixed + // let actual_weight = call.get_dispatch_info().weight; + // env.adjust_weight(charged_weight, actual_weight); + let result = call.dispatch(origin); + match result { + Ok(info) => { + log::debug!(target:LOG_TARGET, "dispatch success, actual weight: {:?}", info.actual_weight); + } + Err(err) => { + log::debug!(target:LOG_TARGET, "dispatch failed: error: {:?}", err.error); + return Err(err.error); + } + } + Ok(()) +} diff --git a/runtime/src/extensions/ext_impl/mod.rs b/runtime/src/extensions/ext_impl/mod.rs new file mode 100644 index 00000000..2389a49b --- /dev/null +++ b/runtime/src/extensions/ext_impl/mod.rs @@ -0,0 +1,2 @@ +pub mod dispatch; +pub mod read_state; diff --git a/runtime/src/extensions/ext_impl/read_state.rs b/runtime/src/extensions/ext_impl/read_state.rs new file mode 100644 index 00000000..1281810f --- /dev/null +++ b/runtime/src/extensions/ext_impl/read_state.rs @@ -0,0 +1,33 @@ +use codec::Decode; +use cumulus_primitives_core::relay_chain::BlockNumber; +use frame_support::pallet_prelude::*; +use log; +use pallet_contracts::chain_extension::{Environment, Ext, InitState}; +use pop_api_primitives::storage_keys::ParachainSystemKeys; + +const LOG_TARGET: &str = "popapi::extension::read_state"; + +pub(crate) fn read_state(env: Environment) -> Result<(), DispatchError> +where + T: pallet_contracts::Config + frame_system::Config, + E: Ext, +{ + let mut env = env.buf_in_buf_out(); + // TODO: Substitue len u32 with pop_api::src::impls::pop_network::StringLimit. + // Move StringLimit to pop_api_primitives first. + let len: u32 = env.in_len(); + let key: ParachainSystemKeys = env.read_as_unbounded(len)?; + + match key { + ParachainSystemKeys::LastRelayChainBlockNumber => { + let relay_block_num: BlockNumber = crate::ParachainSystem::last_relay_block_number(); + log::debug!( + target:LOG_TARGET, + "Last Relay Chain Block Number is: {:?}.", relay_block_num + ); + //Ok(relay_block_num) + Ok(()) + } + _ => Err(DispatchError::Other("Unable to read provided key.")), + } +} diff --git a/runtime/src/extensions/mod.rs b/runtime/src/extensions/mod.rs index ad18a5a0..3f110092 100644 --- a/runtime/src/extensions/mod.rs +++ b/runtime/src/extensions/mod.rs @@ -1 +1,2 @@ +mod ext_impl; pub mod pop_api_extension; diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs index c3f1bf21..4c15c07c 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions/pop_api_extension.rs @@ -1,18 +1,18 @@ use frame_support::{ - dispatch::{GetDispatchInfo, PostDispatchInfo, RawOrigin}, + dispatch::{GetDispatchInfo, PostDispatchInfo}, pallet_prelude::*, }; - use log; - use pallet_contracts::chain_extension::{ ChainExtension, Environment, Ext, InitState, RetVal, SysConfig, }; - use sp_core::crypto::UncheckedFrom; use sp_runtime::{traits::Dispatchable, DispatchError}; +use crate::extensions::ext_impl::{dispatch::dispatch, read_state::read_state}; + const LOG_TARGET: &str = "popapi::extension"; + #[derive(Default)] pub struct PopApiExtension; @@ -30,6 +30,7 @@ fn convert_err(err_msg: &'static str) -> impl FnOnce(DispatchError) -> DispatchE #[derive(Debug)] enum FuncId { CallRuntime, + QueryState, } impl TryFrom for FuncId { @@ -38,6 +39,7 @@ impl TryFrom for FuncId { fn try_from(func_id: u16) -> Result { let id = match func_id { 0xfecb => Self::CallRuntime, + 0xfeca => Self::QueryState, _ => { log::error!("Called an unregistered `func_id`: {:}", func_id); return Err(DispatchError::Other("Unimplemented func_id")); @@ -48,52 +50,9 @@ impl TryFrom for FuncId { } } -fn dispatch(env: Environment) -> Result<(), DispatchError> -where - T: pallet_contracts::Config + frame_system::Config, - ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, - ::RuntimeCall: Parameter - + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> - + GetDispatchInfo - + From>, - E: Ext, -{ - let mut env = env.buf_in_buf_out(); - - // input length - let len = env.in_len(); - let call: ::RuntimeCall = env.read_as_unbounded(len)?; - - // conservative weight estimate for deserializing the input. The actual weight is less and should utilize a custom benchmark - let base_weight: Weight = T::DbWeight::get().reads(len.into()); - - // weight for dispatching the call - let dispatch_weight = call.get_dispatch_info().weight; - - // charge weight for the cost of the deserialization and the dispatch - let _ = env.charge_weight(base_weight.saturating_add(dispatch_weight))?; - - log::debug!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); - - let sender = env.ext().caller(); - let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); - - let result = call.dispatch(origin); - match result { - Ok(info) => { - log::debug!(target:LOG_TARGET, "dispatch success, actual weight: {:?}", info.actual_weight); - } - Err(err) => { - log::debug!(target:LOG_TARGET, "dispatch failed: error: {:?}", err.error); - return Err(err.error); - } - } - Ok(()) -} - impl ChainExtension for PopApiExtension where - T: pallet_contracts::Config, + T: pallet_contracts::Config + cumulus_pallet_parachain_system::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, ::RuntimeCall: Parameter + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> @@ -109,6 +68,7 @@ where let func_id = FuncId::try_from(env.func_id())?; match func_id { FuncId::CallRuntime => dispatch::(env)?, + FuncId::QueryState => read_state::(env)?, } Ok(RetVal::Converging(0)) From 97f3f9394155c8e0b5b9af804ee3cc28ca293fcf Mon Sep 17 00:00:00 2001 From: Peter White Date: Mon, 4 Mar 2024 12:26:47 -0700 Subject: [PATCH 11/19] fix: failing contract builds --- .../pop-api-examples/balance-transfer/lib.rs | 7 +- .../read-runtime-state/Cargo.toml | 1 + .../read-runtime-state/lib.rs | 120 ++---------------- networks/rococo.toml | 2 +- pop-api/Cargo.toml | 10 +- pop-api/primitives/src/lib.rs | 2 + pop-api/src/lib.rs | 3 +- runtime/Cargo.toml | 1 - 8 files changed, 22 insertions(+), 124 deletions(-) diff --git a/contracts/pop-api-examples/balance-transfer/lib.rs b/contracts/pop-api-examples/balance-transfer/lib.rs index 0ed81f21..64df96e7 100755 --- a/contracts/pop-api-examples/balance-transfer/lib.rs +++ b/contracts/pop-api-examples/balance-transfer/lib.rs @@ -8,7 +8,6 @@ use ink::{ use ink::primitives::AccountId; use sp_runtime::MultiAddress; use scale::{Encode, Decode}; -use scale_info::TypeInfo; /// A part of the runtime dispatchable API. /// @@ -20,7 +19,7 @@ use scale_info::TypeInfo; /// You can investigate the full `RuntimeCall` definition by either expanding /// `construct_runtime!` macro application or by using secondary tools for reading chain /// metadata, like `subxt`. -#[derive(Encode, Decode, TypeInfo)] +#[derive(Encode)] enum RuntimeCall { /// This index can be found by investigating runtime configuration. You can check the /// pallet order inside `construct_runtime!` block and read the position of your @@ -81,10 +80,6 @@ pub trait PopApi { /// operations. #[ink(extension = 0xfecb)] fn dispatch(call: RuntimeCall) -> Result>; - - #[ink(extension = 0xfeca)] - fn read_state(key: SafeKeys) -> Result>; - } impl ink::env::chain_extension::FromStatusCode for PopApiError { diff --git a/contracts/pop-api-examples/read-runtime-state/Cargo.toml b/contracts/pop-api-examples/read-runtime-state/Cargo.toml index b53f8415..44c8965f 100755 --- a/contracts/pop-api-examples/read-runtime-state/Cargo.toml +++ b/contracts/pop-api-examples/read-runtime-state/Cargo.toml @@ -28,6 +28,7 @@ std = [ "scale-info/std", "sp-runtime/std", "sp-io/std", + "pop-api/std", ] ink-as-dependency = [] e2e-tests = [] diff --git a/contracts/pop-api-examples/read-runtime-state/lib.rs b/contracts/pop-api-examples/read-runtime-state/lib.rs index 391ff857..3387ad08 100755 --- a/contracts/pop-api-examples/read-runtime-state/lib.rs +++ b/contracts/pop-api-examples/read-runtime-state/lib.rs @@ -7,7 +7,7 @@ use ink::{ use ink::primitives::AccountId; use sp_runtime::MultiAddress; -use pop_api::storage_keys::RuntimeStateKeys::ParachainSystemKeys; +use pop_api::primitives::storage_keys::ParachainSystemKeys; #[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] @@ -39,7 +39,7 @@ pub trait PopApi { /// operations. #[ink(extension = 0xfeca)] - fn read_relay_block_number(key: LastRelayChainBlockNumber) -> Result; + fn read_state(key: ParachainSystemKeys) -> Result<::BlockNumber>; } @@ -73,8 +73,7 @@ impl Environment for CustomEnvironment { #[ink::contract(env = crate::CustomEnvironment)] mod pop_api_extension_demo { use crate::{ - BalancesCall, - RuntimeCall, + ParachainSystemKeys, }; use super::PopApiError; @@ -86,8 +85,7 @@ mod pop_api_extension_demo { value: BlockNumber } - /// A trivial contract with a single message, that uses `call-runtime` API for - /// performing native token transfer. + #[ink(storage)] #[derive(Default)] pub struct PopApiExtensionDemo; @@ -112,113 +110,11 @@ mod pop_api_extension_demo { pub fn read_relay_block_number( &self ) { - let state = self.env().extension().read_state(LastRelayChainBlockNumber); - ink::env::debug_println!("{:?}", state); - ink::env().emit_event( - RelayBlockNumberRead {value: state} + let result = self.env().extension().read_state(ParachainSystemKeys::LastRelayChainBlockNumber); + ink::env::debug_println!("{:?}", result); + self.env().emit_event( + RelayBlockNumberRead {value: result.expect("Failed to read relay block number.")} ); } } - - #[cfg(all(test, feature = "e2e-tests"))] - mod e2e_tests { - use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; - - use ink::{ - env::{ - test::default_accounts, - DefaultEnvironment, - }, - primitives::AccountId, - }; - - type E2EResult = Result>; - - /// The base number of indivisible units for balances on the - /// `substrate-contracts-node`. - const UNIT: Balance = 1_000_000_000_000; - - /// The contract will be given 1000 tokens during instantiation. - const CONTRACT_BALANCE: Balance = 1_000 * UNIT; - - /// The receiver will get enough funds to have the required existential deposit. - /// - /// If your chain has this threshold higher, increase the transfer value. - const TRANSFER_VALUE: Balance = 1 / 10 * UNIT; - - /// An amount that is below the existential deposit, so that a transfer to an - /// empty account fails. - /// - /// Must not be zero, because such an operation would be a successful no-op. - const INSUFFICIENT_TRANSFER_VALUE: Balance = 1; - - /// Positive case scenario: - /// - the call is valid - /// - the call execution succeeds - #[ink_e2e::test] - async fn transfer_with_call_runtime_works( - mut client: Client, - ) -> E2EResult<()> { - // given - let mut constructor = RuntimeCallerRef::new(); - let contract = client - .instantiate("call-runtime", &ink_e2e::alice(), &mut constructor) - .value(CONTRACT_BALANCE) - .submit() - .await - .expect("instantiate failed"); - let mut call_builder = contract.call_builder::(); - - let accounts = default_accounts::(); - - let receiver: AccountId = accounts.bob; - - let sender_balance_before = client - .free_balance(accounts.alice) - .await - .expect("Failed to get account balance"); - let receiver_balance_before = client - .free_balance(receiver) - .await - .expect("Failed to get account balance"); - - // when - let transfer_message = - call_builder.transfer_through_runtime(receiver, TRANSFER_VALUE); - - let call_res = client - .call(&ink_e2e::alice(), &transfer_message) - .submit() - .await - .expect("call failed"); - - assert!(call_res.return_value().is_ok()); - - // then - let sender_balance_after = client - .free_balance(accounts.alice) - .await - .expect("Failed to get account balance"); - let receiver_balance_after = client - .free_balance(receiver) - .await - .expect("Failed to get account balance"); - - assert_eq!( - contract_balance_before, - contract_balance_after + TRANSFER_VALUE - ); - assert_eq!( - receiver_balance_before, - receiver_balance_after - TRANSFER_VALUE - ); - - Ok(()) - } - - } } \ No newline at end of file diff --git a/networks/rococo.toml b/networks/rococo.toml index 4f581f5e..ab7421fe 100644 --- a/networks/rococo.toml +++ b/networks/rococo.toml @@ -4,7 +4,7 @@ node_spawn_timeout = 300 [relaychain] chain = "rococo-local" -default_command = "./cache/polkadot-v1.7.1" +default_command = "./bin/polkadot" [[relaychain.nodes]] name = "alice" diff --git a/pop-api/Cargo.toml b/pop-api/Cargo.toml index b2ffb628..66483028 100644 --- a/pop-api/Cargo.toml +++ b/pop-api/Cargo.toml @@ -5,16 +5,19 @@ license = "GPL-3.0-only" version = "0.0.0" edition = "2021" -[dependencies] - -pop-api-primitives = { path = "./primitives" } +members = [ + "primitives/" +] +[dependencies] ink = { version = "4.3.0", default-features = false } sp-runtime = { version = "24.0.0", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } +pop-api-primitives = {path = "./primitives", default-features = false} + [lib] name = "pop_api" path = "src/lib.rs" @@ -29,4 +32,5 @@ std = [ "sp-runtime/std", "scale/std", "scale-info/std", + "pop-api-primitives/std", ] diff --git a/pop-api/primitives/src/lib.rs b/pop-api/primitives/src/lib.rs index d37a392a..b401dc5f 100644 --- a/pop-api/primitives/src/lib.rs +++ b/pop-api/primitives/src/lib.rs @@ -1 +1,3 @@ +#![cfg_attr(not(feature = "std"), no_std, no_main)] + pub mod storage_keys; diff --git a/pop-api/src/lib.rs b/pop-api/src/lib.rs index 6eae52a6..c82ed3f4 100644 --- a/pop-api/src/lib.rs +++ b/pop-api/src/lib.rs @@ -1,8 +1,9 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -use pop_api_primitives::storage_keys; pub mod v0; +pub use pop_api_primitives as primitives; + use ink::{env::Environment, prelude::vec::Vec, ChainExtensionInstance}; use scale; use sp_runtime::MultiSignature; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 603c8c96..4ad0ae4f 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -24,7 +24,6 @@ smallvec = { workspace = true } # Local pop-api-primitives = { workspace = true } - # Substrate frame-benchmarking = { workspace = true } frame-executive = { workspace = true } From e26d1a6494a98e8f59e214d7f61548594c8ad08a Mon Sep 17 00:00:00 2001 From: Peter White Date: Mon, 4 Mar 2024 16:27:59 -0700 Subject: [PATCH 12/19] refactor: general refactoring, versioned function selector and code cleanup --- .../pop-api-examples/balance-transfer/lib.rs | 147 +----------------- pop-api/Cargo.toml | 4 - pop-api/src/lib.rs | 6 +- runtime/src/extensions/ext_impl/dispatch.rs | 11 -- runtime/src/extensions/pop_api_extension.rs | 22 +-- 5 files changed, 18 insertions(+), 172 deletions(-) diff --git a/contracts/pop-api-examples/balance-transfer/lib.rs b/contracts/pop-api-examples/balance-transfer/lib.rs index 64df96e7..c1614e97 100755 --- a/contracts/pop-api-examples/balance-transfer/lib.rs +++ b/contracts/pop-api-examples/balance-transfer/lib.rs @@ -9,34 +9,13 @@ use ink::primitives::AccountId; use sp_runtime::MultiAddress; use scale::{Encode, Decode}; -/// A part of the runtime dispatchable API. -/// -/// For now, `ink!` doesn't provide any support for exposing the real `RuntimeCall` enum, -/// which fully describes the composed API of all the pallets present in runtime. Hence, -/// in order to use `call-runtime` functionality, we have to provide at least a partial -/// object, which correctly encodes the target extrinsic. -/// -/// You can investigate the full `RuntimeCall` definition by either expanding -/// `construct_runtime!` macro application or by using secondary tools for reading chain -/// metadata, like `subxt`. #[derive(Encode)] enum RuntimeCall { - /// This index can be found by investigating runtime configuration. You can check the - /// pallet order inside `construct_runtime!` block and read the position of your - /// pallet (0-based). - /// - /// - /// [See here for more.](https://substrate.stackexchange.com/questions/778/how-to-get-pallet-index-u8-of-a-pallet-in-runtime) - #[codec(index = 10)] Balances(BalancesCall), } #[derive(scale::Encode)] enum BalancesCall { - /// This index can be found by investigating the pallet dispatchable API. In your - /// pallet code, look for `#[pallet::call]` section and check - /// `#[pallet::call_index(x)]` attribute of the call. If these attributes are - /// missing, use source-code order (0-based). #[codec(index = 3)] TransferKeepAlive { dest: MultiAddress, @@ -66,19 +45,11 @@ impl From for PopApiError { } } -/// This is an example of how an ink! contract may call the Substrate -/// runtime function `RandomnessCollectiveFlip::random_seed`. See the -/// file `runtime/chain-extension-example.rs` for that implementation. -/// -/// Here we define the operations to interact with the Substrate runtime. #[ink::chain_extension] pub trait PopApi { type ErrorCode = PopApiError; - /// Note: this gives the operation a corresponding `func_id` (1101 in this case), - /// and the chain-side chain extension will get the `func_id` to do further - /// operations. - #[ink(extension = 0xfecb)] + #[ink(extension = 0x0)] fn dispatch(call: RuntimeCall) -> Result>; } @@ -120,8 +91,6 @@ mod pop_api_extension_demo { use ink::env::Error as EnvError; - /// A trivial contract with a single message, that uses `call-runtime` API for - /// performing native token transfer. #[ink(storage)] #[derive(Default)] pub struct PopApiExtensionDemo; @@ -135,18 +104,6 @@ mod pop_api_extension_demo { } } - // impl From for RuntimeError { - // fn from(e: EnvError) -> Self { - // use ink::env::ReturnErrorCode; - // match e { - // EnvError::ReturnError(ReturnErrorCode::CallRuntimeFailed) => { - // RuntimeError::CallRuntimeFailed - // } - // _ => panic!("Unexpected error from `pallet-contracts`."), - // } - // } - // } - impl PopApiExtensionDemo { #[ink(constructor, payable)] pub fn new() -> Self { @@ -172,106 +129,4 @@ mod pop_api_extension_demo { } } - - #[cfg(all(test, feature = "e2e-tests"))] - mod e2e_tests { - use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; - - use ink::{ - env::{ - test::default_accounts, - DefaultEnvironment, - }, - primitives::AccountId, - }; - - type E2EResult = Result>; - - /// The base number of indivisible units for balances on the - /// `substrate-contracts-node`. - const UNIT: Balance = 1_000_000_000_000; - - /// The contract will be given 1000 tokens during instantiation. - const CONTRACT_BALANCE: Balance = 1_000 * UNIT; - - /// The receiver will get enough funds to have the required existential deposit. - /// - /// If your chain has this threshold higher, increase the transfer value. - const TRANSFER_VALUE: Balance = 1 / 10 * UNIT; - - /// An amount that is below the existential deposit, so that a transfer to an - /// empty account fails. - /// - /// Must not be zero, because such an operation would be a successful no-op. - const INSUFFICIENT_TRANSFER_VALUE: Balance = 1; - - /// Positive case scenario: - /// - the call is valid - /// - the call execution succeeds - #[ink_e2e::test] - async fn transfer_with_call_runtime_works( - mut client: Client, - ) -> E2EResult<()> { - // given - let mut constructor = RuntimeCallerRef::new(); - let contract = client - .instantiate("call-runtime", &ink_e2e::alice(), &mut constructor) - .value(CONTRACT_BALANCE) - .submit() - .await - .expect("instantiate failed"); - let mut call_builder = contract.call_builder::(); - - let accounts = default_accounts::(); - - let receiver: AccountId = accounts.bob; - - let sender_balance_before = client - .free_balance(accounts.alice) - .await - .expect("Failed to get account balance"); - let receiver_balance_before = client - .free_balance(receiver) - .await - .expect("Failed to get account balance"); - - // when - let transfer_message = - call_builder.transfer_through_runtime(receiver, TRANSFER_VALUE); - - let call_res = client - .call(&ink_e2e::alice(), &transfer_message) - .submit() - .await - .expect("call failed"); - - assert!(call_res.return_value().is_ok()); - - // then - let sender_balance_after = client - .free_balance(accounts.alice) - .await - .expect("Failed to get account balance"); - let receiver_balance_after = client - .free_balance(receiver) - .await - .expect("Failed to get account balance"); - - assert_eq!( - contract_balance_before, - contract_balance_after + TRANSFER_VALUE - ); - assert_eq!( - receiver_balance_before, - receiver_balance_after - TRANSFER_VALUE - ); - - Ok(()) - } - - } } \ No newline at end of file diff --git a/pop-api/Cargo.toml b/pop-api/Cargo.toml index 66483028..92529fae 100644 --- a/pop-api/Cargo.toml +++ b/pop-api/Cargo.toml @@ -5,10 +5,6 @@ license = "GPL-3.0-only" version = "0.0.0" edition = "2021" -members = [ - "primitives/" -] - [dependencies] ink = { version = "4.3.0", default-features = false } sp-runtime = { version = "24.0.0", default-features = false } diff --git a/pop-api/src/lib.rs b/pop-api/src/lib.rs index c82ed3f4..7ca25fa8 100644 --- a/pop-api/src/lib.rs +++ b/pop-api/src/lib.rs @@ -68,9 +68,13 @@ impl Environment for PopEnv { pub trait PopApi { type ErrorCode = PopApiError; - #[ink(extension = 0xfecb)] + #[ink(extension = 0)] #[allow(private_interfaces)] fn dispatch(call: RuntimeCall) -> crate::Result>; + + #[ink(extension = 1)] + #[allow(private_interfaces)] + fn read_state(call: RuntimeCall) -> crate::Result>; } fn call_runtime(call: RuntimeCall) -> Result> { diff --git a/runtime/src/extensions/ext_impl/dispatch.rs b/runtime/src/extensions/ext_impl/dispatch.rs index df804bc7..3a9dc901 100644 --- a/runtime/src/extensions/ext_impl/dispatch.rs +++ b/runtime/src/extensions/ext_impl/dispatch.rs @@ -21,14 +21,6 @@ where { let mut env = env.buf_in_buf_out(); - // charge max weight before reading contract memory - // TODO: causing "1010: block limits exhausted" error - // let weight_limit = env.ext().gas_meter().gas_left(); - // let charged_weight = env.charge_weight(weight_limit)?; - - // TODO: debug_message weight is a good approximation of the additional overhead of going - // from contract layer to substrate layer. - // input length let len = env.in_len(); let call: ::RuntimeCall = env.read_as_unbounded(len)?; @@ -47,9 +39,6 @@ where let sender = env.ext().caller(); let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); - // TODO: uncomment once charged_weight is fixed - // let actual_weight = call.get_dispatch_info().weight; - // env.adjust_weight(charged_weight, actual_weight); let result = call.dispatch(origin); match result { Ok(info) => { diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs index 4c15c07c..9abd359f 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions/pop_api_extension.rs @@ -27,19 +27,21 @@ fn convert_err(err_msg: &'static str) -> impl FnOnce(DispatchError) -> DispatchE } } -#[derive(Debug)] -enum FuncId { - CallRuntime, - QueryState, +pub mod v0 { + #[derive(Debug)] + pub enum FuncId { + Dispatch, + ReadState, + } } -impl TryFrom for FuncId { +impl TryFrom for v0::FuncId { type Error = DispatchError; fn try_from(func_id: u16) -> Result { let id = match func_id { - 0xfecb => Self::CallRuntime, - 0xfeca => Self::QueryState, + 0x0 => Self::Dispatch, + 0x1 => Self::ReadState, _ => { log::error!("Called an unregistered `func_id`: {:}", func_id); return Err(DispatchError::Other("Unimplemented func_id")); @@ -65,10 +67,10 @@ where ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, { log::debug!(target:LOG_TARGET, " extension called "); - let func_id = FuncId::try_from(env.func_id())?; + let func_id = v0::FuncId::try_from(env.func_id())?; match func_id { - FuncId::CallRuntime => dispatch::(env)?, - FuncId::QueryState => read_state::(env)?, + v0::FuncId::Dispatch => dispatch::(env)?, + v0::FuncId::ReadState => read_state::(env)?, } Ok(RetVal::Converging(0)) From 16e154542354b803873e571b26d0fd43ce51baf5 Mon Sep 17 00:00:00 2001 From: Frank Bell Date: Sat, 2 Mar 2024 22:31:21 +0000 Subject: [PATCH 13/19] feat(pop-api): errors --- contracts/pop-api-examples/nfts/lib.rs | 21 ++- pop-api/src/lib.rs | 16 +- pop-api/src/v0/nfts.rs | 166 +++++++++++++++++++- runtime/src/extensions/pop_api_extension.rs | 98 +++++++++++- 4 files changed, 279 insertions(+), 22 deletions(-) diff --git a/contracts/pop-api-examples/nfts/lib.rs b/contracts/pop-api-examples/nfts/lib.rs index df8bb9d1..5af148ba 100755 --- a/contracts/pop-api-examples/nfts/lib.rs +++ b/contracts/pop-api-examples/nfts/lib.rs @@ -1,16 +1,16 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -use pop_api::PopApiError; +use pop_api::nfts; #[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum ContractError { - SomeError, + MintError(nfts::Error), } -impl From for ContractError { - fn from(_value: PopApiError) -> Self { - ContractError::SomeError +impl From for ContractError { + fn from(value: nfts::Error) -> Self { + ContractError::MintError(value) } } @@ -39,7 +39,16 @@ mod pop_api_extension_demo { ink::env::debug_println!("PopApiExtensionDemo::mint_through_runtime: collection_id: {:?} \nitem_id {:?} \nreceiver: {:?}, ", collection_id, item_id, receiver); // simplified API call - pop_api::nfts::mint(collection_id, item_id, receiver)?; + let result = pop_api::nfts::mint(collection_id, item_id, receiver); + ink::env::debug_println!( + "PopApiExtensionDemo::mint_through_runtime result: {result:?}" + ); + if let Err(pop_api::nfts::Error::NoConfig) = result { + ink::env::debug_println!( + "PopApiExtensionDemo::mint_through_runtime expected error received" + ); + } + result?; ink::env::debug_println!("PopApiExtensionDemo::mint_through_runtime end"); Ok(()) diff --git a/pop-api/src/lib.rs b/pop-api/src/lib.rs index 7ca25fa8..337f0534 100644 --- a/pop-api/src/lib.rs +++ b/pop-api/src/lib.rs @@ -3,8 +3,8 @@ pub mod v0; pub use pop_api_primitives as primitives; - -use ink::{env::Environment, prelude::vec::Vec, ChainExtensionInstance}; +use crate::PopApiError::Nfts; +use ink::{env::Environment, ChainExtensionInstance}; use scale; use sp_runtime::MultiSignature; pub use v0::nfts; @@ -29,14 +29,18 @@ pub type Result = core::result::Result; #[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum PopApiError { - PlaceholderError, + RuntimeError, + Nfts(nfts::Error), } impl ink::env::chain_extension::FromStatusCode for PopApiError { fn from_status_code(status_code: u32) -> core::result::Result<(), Self> { match status_code { 0 => Ok(()), - 1 => Err(Self::PlaceholderError), + 1 => Err(Self::RuntimeError), + 50_000..=50_999 => { + return Err(Nfts((status_code - 50_000).into())); + } _ => panic!("encountered unknown status code"), } } @@ -70,14 +74,14 @@ pub trait PopApi { #[ink(extension = 0)] #[allow(private_interfaces)] - fn dispatch(call: RuntimeCall) -> crate::Result>; + fn dispatch(call: RuntimeCall) -> crate::Result<()>; #[ink(extension = 1)] #[allow(private_interfaces)] fn read_state(call: RuntimeCall) -> crate::Result>; } -fn call_runtime(call: RuntimeCall) -> Result> { +fn dispatch(call: RuntimeCall) -> Result<()> { <::ChainExtension as ChainExtensionInstance>::instantiate() .dispatch(call) } diff --git a/pop-api/src/v0/nfts.rs b/pop-api/src/v0/nfts.rs index 127f393b..89f47a76 100644 --- a/pop-api/src/v0/nfts.rs +++ b/pop-api/src/v0/nfts.rs @@ -3,21 +3,23 @@ use crate::*; use ink::prelude::vec::Vec; use sp_runtime::{BoundedVec, MultiAddress}; +type Result = core::result::Result; + pub fn mint( collection: CollectionId, item: ItemId, mint_to: impl Into>, ) -> Result<()> { - crate::call_runtime(RuntimeCall::Nfts(NftCalls::Mint { + Ok(dispatch(RuntimeCall::Nfts(NftCalls::Mint { collection, item, mint_to: mint_to.into(), witness_data: None, - }))?; - Ok(()) + }))?) } #[derive(scale::Encode)] +#[allow(dead_code)] pub(crate) enum NftCalls { // #[codec(index = 0)] // Create { @@ -211,3 +213,161 @@ pub(crate) enum NftCalls { // signer: AccountId, // } } + +#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] +#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] +pub enum Error { + /// The signing account has no permission to do the operation. + NoPermission, + /// The given item ID is unknown. + UnknownCollection, + /// The item ID has already been used for an item. + AlreadyExists, + /// The approval had a deadline that expired, so the approval isn't valid anymore. + ApprovalExpired, + /// The owner turned out to be different to what was expected. + WrongOwner, + /// The witness data given does not match the current state of the chain. + BadWitness, + /// Collection ID is already taken. + CollectionIdInUse, + /// Items within that collection are non-transferable. + ItemsNonTransferable, + /// The provided account is not a delegate. + NotDelegate, + /// The delegate turned out to be different to what was expected. + WrongDelegate, + /// No approval exists that would allow the transfer. + Unapproved, + /// The named owner has not signed ownership acceptance of the collection. + Unaccepted, + /// The item is locked (non-transferable). + ItemLocked, + /// Item's attributes are locked. + LockedItemAttributes, + /// Collection's attributes are locked. + LockedCollectionAttributes, + /// Item's metadata is locked. + LockedItemMetadata, + /// Collection's metadata is locked. + LockedCollectionMetadata, + /// All items have been minted. + MaxSupplyReached, + /// The max supply is locked and can't be changed. + MaxSupplyLocked, + /// The provided max supply is less than the number of items a collection already has. + MaxSupplyTooSmall, + /// The given item ID is unknown. + UnknownItem, + /// Swap doesn't exist. + UnknownSwap, + /// The given item has no metadata set. + MetadataNotFound, + /// The provided attribute can't be found. + AttributeNotFound, + /// Item is not for sale. + NotForSale, + /// The provided bid is too low. + BidTooLow, + /// The item has reached its approval limit. + ReachedApprovalLimit, + /// The deadline has already expired. + DeadlineExpired, + /// The duration provided should be less than or equal to `MaxDeadlineDuration`. + WrongDuration, + /// The method is disabled by system settings. + MethodDisabled, + /// The provided setting can't be set. + WrongSetting, + /// Item's config already exists and should be equal to the provided one. + InconsistentItemConfig, + /// Config for a collection or an item can't be found. + NoConfig, + /// Some roles were not cleared. + RolesNotCleared, + /// Mint has not started yet. + MintNotStarted, + /// Mint has already ended. + MintEnded, + /// The provided Item was already used for claiming. + AlreadyClaimed, + /// The provided data is incorrect. + IncorrectData, + /// The extrinsic was sent by the wrong origin. + WrongOrigin, + /// The provided signature is incorrect. + WrongSignature, + /// The provided metadata might be too long. + IncorrectMetadata, + /// Can't set more attributes per one call. + MaxAttributesLimitReached, + /// The provided namespace isn't supported in this call. + WrongNamespace, + /// Can't delete non-empty collections. + CollectionNotEmpty, + /// The witness data should be provided. + WitnessRequired, +} + +impl From for Error { + fn from(value: u32) -> Self { + use Error::*; + match value { + 0 => NoPermission, + 1 => UnknownCollection, + 2 => AlreadyExists, + 3 => ApprovalExpired, + 4 => WrongOwner, + 5 => BadWitness, + 6 => CollectionIdInUse, + 7 => ItemsNonTransferable, + 8 => NotDelegate, + 9 => WrongDelegate, + 10 => Unapproved, + 11 => Unaccepted, + 12 => ItemLocked, + 13 => LockedItemAttributes, + 14 => LockedCollectionAttributes, + 15 => LockedItemMetadata, + 16 => LockedCollectionMetadata, + 17 => MaxSupplyReached, + 18 => MaxSupplyLocked, + 19 => MaxSupplyTooSmall, + 20 => UnknownItem, + 21 => UnknownSwap, + 22 => MetadataNotFound, + 23 => AttributeNotFound, + 24 => NotForSale, + 25 => BidTooLow, + 26 => ReachedApprovalLimit, + 27 => DeadlineExpired, + 28 => WrongDuration, + 29 => MethodDisabled, + 30 => WrongSetting, + 31 => InconsistentItemConfig, + 32 => NoConfig, + 33 => RolesNotCleared, + 34 => MintNotStarted, + 35 => MintEnded, + 36 => AlreadyClaimed, + 37 => IncorrectData, + 38 => WrongOrigin, + 39 => WrongSignature, + 40 => IncorrectMetadata, + 41 => MaxAttributesLimitReached, + 42 => WrongNamespace, + 43 => CollectionNotEmpty, + 44 => WitnessRequired, + _ => panic!("encountered unknown status code"), + } + } +} + +impl From for Error { + fn from(error: PopApiError) -> Self { + match error { + PopApiError::Nfts(e) => e, + _ => panic!("expected nfts error"), + } + } +} diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs index 9abd359f..cd083e0d 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions/pop_api_extension.rs @@ -32,7 +32,7 @@ pub mod v0 { pub enum FuncId { Dispatch, ReadState, - } + } } impl TryFrom for v0::FuncId { @@ -67,13 +67,24 @@ where ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, { log::debug!(target:LOG_TARGET, " extension called "); - let func_id = v0::FuncId::try_from(env.func_id())?; - match func_id { - v0::FuncId::Dispatch => dispatch::(env)?, - v0::FuncId::ReadState => read_state::(env)?, + match v0::FuncId::try_from(env.func_id())? { + v0::FuncId::Dispatch => { + match dispatch::(env) { + Ok(()) => Ok(RetVal::Converging(0)), + Err(DispatchError::Module(error)) => { + // encode status code = pallet index in runtime + error index, allowing for 999 errors + Ok(RetVal::Converging( + (error.index as u32 * 1_000) + u32::from_le_bytes(error.error), + )) + } + Err(e) => Err(e), + } + } + v0::FuncId::ReadState => { + read_state::(env)?; + Ok(RetVal::Converging(0)) + } } - - Ok(RetVal::Converging(0)) } } @@ -294,4 +305,77 @@ mod tests { assert_eq!(Nfts::owner(collection_id, item_id), Some(BOB.into())); }); } + + #[test] + fn test_nfts_mint_surfaces_error() { + new_test_ext().execute_with(|| { + let _ = env_logger::try_init(); + + let (wasm_binary, _) = load_wasm_module::( + "../contracts/pop-api-examples/nfts/target/ink/pop_api_nft_example.wasm", + ) + .unwrap(); + + let init_value = 100; + + let result = Contracts::bare_instantiate( + ALICE, + init_value, + GAS_LIMIT, + None, + Code::Upload(wasm_binary), + function_selector("new"), + vec![], + DEBUG_OUTPUT, + pallet_contracts::CollectEvents::Skip, + ) + .result + .unwrap(); + + assert!( + !result.result.did_revert(), + "deploying contract reverted {:?}", + result + ); + + let addr = result.account_id; + + let collection_id: u32 = 0; + let item_id: u32 = 1; + + let function = function_selector("mint_through_runtime"); + + let params = [ + function, + collection_id.encode(), + item_id.encode(), + BOB.encode(), + ] + .concat(); + + let result = Contracts::bare_call( + ALICE, + addr.clone(), + 0, + Weight::from_parts(100_000_000_000, 3 * 1024 * 1024), + None, + params, + DEBUG_OUTPUT, + pallet_contracts::CollectEvents::Skip, + pallet_contracts::Determinism::Enforced, + ); + + if DEBUG_OUTPUT == pallet_contracts::DebugInfo::UnsafeDebug { + log::debug!( + "Contract debug buffer - {:?}", + String::from_utf8(result.debug_message.clone()) + ); + log::debug!("result: {:?}", result); + } + + // check for revert with expected error + let result = result.result.unwrap(); + assert!(result.did_revert()); + }); + } } From 390fe7dd2ee9c38c91a2b28b9d292168cf5ea8e4 Mon Sep 17 00:00:00 2001 From: Frank Bell Date: Tue, 5 Mar 2024 09:45:32 +0000 Subject: [PATCH 14/19] refactor: improve error handling --- pop-api/src/lib.rs | 13 ++---- pop-api/src/v0/nfts.rs | 102 +++++++++++++++++++++-------------------- 2 files changed, 57 insertions(+), 58 deletions(-) diff --git a/pop-api/src/lib.rs b/pop-api/src/lib.rs index 337f0534..a9604481 100644 --- a/pop-api/src/lib.rs +++ b/pop-api/src/lib.rs @@ -2,9 +2,9 @@ pub mod v0; -pub use pop_api_primitives as primitives; -use crate::PopApiError::Nfts; +use crate::PopApiError::{Nfts, UnknownStatusCode}; use ink::{env::Environment, ChainExtensionInstance}; +pub use pop_api_primitives as primitives; use scale; use sp_runtime::MultiSignature; pub use v0::nfts; @@ -29,7 +29,7 @@ pub type Result = core::result::Result; #[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum PopApiError { - RuntimeError, + UnknownStatusCode(u32), Nfts(nfts::Error), } @@ -37,11 +37,8 @@ impl ink::env::chain_extension::FromStatusCode for PopApiError { fn from_status_code(status_code: u32) -> core::result::Result<(), Self> { match status_code { 0 => Ok(()), - 1 => Err(Self::RuntimeError), - 50_000..=50_999 => { - return Err(Nfts((status_code - 50_000).into())); - } - _ => panic!("encountered unknown status code"), + 50_000..=50_999 => Err(Nfts((status_code - 50_000).try_into()?)), + _ => Err(UnknownStatusCode(status_code)), } } } diff --git a/pop-api/src/v0/nfts.rs b/pop-api/src/v0/nfts.rs index 89f47a76..6602d2cf 100644 --- a/pop-api/src/v0/nfts.rs +++ b/pop-api/src/v0/nfts.rs @@ -1,5 +1,5 @@ use super::RuntimeCall; -use crate::*; +use crate::{PopApiError::UnknownStatusCode, *}; use ink::prelude::vec::Vec; use sp_runtime::{BoundedVec, MultiAddress}; @@ -309,56 +309,58 @@ pub enum Error { WitnessRequired, } -impl From for Error { - fn from(value: u32) -> Self { +impl TryFrom for Error { + type Error = PopApiError; + + fn try_from(status_code: u32) -> core::result::Result { use Error::*; - match value { - 0 => NoPermission, - 1 => UnknownCollection, - 2 => AlreadyExists, - 3 => ApprovalExpired, - 4 => WrongOwner, - 5 => BadWitness, - 6 => CollectionIdInUse, - 7 => ItemsNonTransferable, - 8 => NotDelegate, - 9 => WrongDelegate, - 10 => Unapproved, - 11 => Unaccepted, - 12 => ItemLocked, - 13 => LockedItemAttributes, - 14 => LockedCollectionAttributes, - 15 => LockedItemMetadata, - 16 => LockedCollectionMetadata, - 17 => MaxSupplyReached, - 18 => MaxSupplyLocked, - 19 => MaxSupplyTooSmall, - 20 => UnknownItem, - 21 => UnknownSwap, - 22 => MetadataNotFound, - 23 => AttributeNotFound, - 24 => NotForSale, - 25 => BidTooLow, - 26 => ReachedApprovalLimit, - 27 => DeadlineExpired, - 28 => WrongDuration, - 29 => MethodDisabled, - 30 => WrongSetting, - 31 => InconsistentItemConfig, - 32 => NoConfig, - 33 => RolesNotCleared, - 34 => MintNotStarted, - 35 => MintEnded, - 36 => AlreadyClaimed, - 37 => IncorrectData, - 38 => WrongOrigin, - 39 => WrongSignature, - 40 => IncorrectMetadata, - 41 => MaxAttributesLimitReached, - 42 => WrongNamespace, - 43 => CollectionNotEmpty, - 44 => WitnessRequired, - _ => panic!("encountered unknown status code"), + match status_code { + 0 => Ok(NoPermission), + 1 => Ok(UnknownCollection), + 2 => Ok(AlreadyExists), + 3 => Ok(ApprovalExpired), + 4 => Ok(WrongOwner), + 5 => Ok(BadWitness), + 6 => Ok(CollectionIdInUse), + 7 => Ok(ItemsNonTransferable), + 8 => Ok(NotDelegate), + 9 => Ok(WrongDelegate), + 10 => Ok(Unapproved), + 11 => Ok(Unaccepted), + 12 => Ok(ItemLocked), + 13 => Ok(LockedItemAttributes), + 14 => Ok(LockedCollectionAttributes), + 15 => Ok(LockedItemMetadata), + 16 => Ok(LockedCollectionMetadata), + 17 => Ok(MaxSupplyReached), + 18 => Ok(MaxSupplyLocked), + 19 => Ok(MaxSupplyTooSmall), + 20 => Ok(UnknownItem), + 21 => Ok(UnknownSwap), + 22 => Ok(MetadataNotFound), + 23 => Ok(AttributeNotFound), + 24 => Ok(NotForSale), + 25 => Ok(BidTooLow), + 26 => Ok(ReachedApprovalLimit), + 27 => Ok(DeadlineExpired), + 28 => Ok(WrongDuration), + 29 => Ok(MethodDisabled), + 30 => Ok(WrongSetting), + 31 => Ok(InconsistentItemConfig), + 32 => Ok(NoConfig), + 33 => Ok(RolesNotCleared), + 34 => Ok(MintNotStarted), + 35 => Ok(MintEnded), + 36 => Ok(AlreadyClaimed), + 37 => Ok(IncorrectData), + 38 => Ok(WrongOrigin), + 39 => Ok(WrongSignature), + 40 => Ok(IncorrectMetadata), + 41 => Ok(MaxAttributesLimitReached), + 42 => Ok(WrongNamespace), + 43 => Ok(CollectionNotEmpty), + 44 => Ok(WitnessRequired), + _ => Err(UnknownStatusCode(status_code)), } } } From 9006e7dd37764772da851a901f45454a810102ca Mon Sep 17 00:00:00 2001 From: Frank Bell Date: Tue, 5 Mar 2024 09:45:52 +0000 Subject: [PATCH 15/19] chore: tidy up manifest --- pop-api/Cargo.toml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pop-api/Cargo.toml b/pop-api/Cargo.toml index 92529fae..35c0d179 100644 --- a/pop-api/Cargo.toml +++ b/pop-api/Cargo.toml @@ -1,25 +1,24 @@ [package] name = "pop-api" -description = "Reserved crate for pop-api." +description = "Easily access the power of Polkadot via the Pop Network" license = "GPL-3.0-only" version = "0.0.0" edition = "2021" +members = ["primitives/"] + [dependencies] ink = { version = "4.3.0", default-features = false } -sp-runtime = { version = "24.0.0", default-features = false } - scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } +sp-runtime = { version = "24.0.0", default-features = false } -pop-api-primitives = {path = "./primitives", default-features = false} +pop-api-primitives = { path = "./primitives", default-features = false } [lib] name = "pop_api" path = "src/lib.rs" -crate-type = [ - "rlib", -] +crate-type = ["rlib"] [features] default = ["std"] From 2d292697127d8f629f6919d102129b8fec2966c1 Mon Sep 17 00:00:00 2001 From: Alejandro Martinez Andres <11448715+al3mart@users.noreply.github.com> Date: Tue, 5 Mar 2024 14:04:01 +0100 Subject: [PATCH 16/19] clean & rename tests --- runtime/src/extensions/ext_impl/read_state.rs | 1 - runtime/src/extensions/pop_api_extension.rs | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/runtime/src/extensions/ext_impl/read_state.rs b/runtime/src/extensions/ext_impl/read_state.rs index 1281810f..f266a1eb 100644 --- a/runtime/src/extensions/ext_impl/read_state.rs +++ b/runtime/src/extensions/ext_impl/read_state.rs @@ -1,4 +1,3 @@ -use codec::Decode; use cumulus_primitives_core::relay_chain::BlockNumber; use frame_support::pallet_prelude::*; use log; diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs index cd083e0d..2b478c24 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions/pop_api_extension.rs @@ -153,7 +153,7 @@ mod tests { } #[test] - fn test_dispatch() { + fn dispatch_balance_transfer_from_contract_works() { new_test_ext().execute_with(|| { let _ = env_logger::try_init(); @@ -219,7 +219,7 @@ mod tests { } #[test] - fn test_nfts_mint() { + fn dispatch_nfts_mint_from_contract_works() { new_test_ext().execute_with(|| { let _ = env_logger::try_init(); @@ -307,7 +307,7 @@ mod tests { } #[test] - fn test_nfts_mint_surfaces_error() { + fn nfts_mint_surfaces_error() { new_test_ext().execute_with(|| { let _ = env_logger::try_init(); From e9597f899e320a48686586976955e15a4a40063e Mon Sep 17 00:00:00 2001 From: Frank Bell Date: Tue, 5 Mar 2024 14:03:26 +0000 Subject: [PATCH 17/19] refactor: clean up and simplify --- Cargo.lock | 2 +- Cargo.toml | 10 +- .../balance-transfer/Cargo.toml | 7 +- .../pop-api-examples/balance-transfer/lib.rs | 210 +++++++++-------- contracts/pop-api-examples/nfts/Cargo.toml | 6 +- contracts/pop-api-examples/nfts/lib.rs | 6 +- .../read-runtime-state/Cargo.toml | 10 +- .../read-runtime-state/lib.rs | 107 +-------- pop-api/Cargo.toml | 10 +- pop-api/primitives/Cargo.toml | 8 +- pop-api/src/lib.rs | 53 +++-- pop-api/src/primitives.rs | 2 + pop-api/src/v0/balances.rs | 95 ++++++++ pop-api/src/v0/mod.rs | 3 + pop-api/src/v0/nfts.rs | 2 +- pop-api/src/v0/state.rs | 6 + runtime/Cargo.toml | 219 +++++++++--------- runtime/src/contracts_config.rs | 2 +- .../pop_api_extension.rs => extensions.rs} | 162 +++++++++---- runtime/src/extensions/ext_impl/dispatch.rs | 53 ----- runtime/src/extensions/ext_impl/mod.rs | 2 - runtime/src/extensions/ext_impl/read_state.rs | 32 --- runtime/src/extensions/mod.rs | 2 - 23 files changed, 511 insertions(+), 498 deletions(-) create mode 100644 pop-api/src/primitives.rs create mode 100644 pop-api/src/v0/state.rs rename runtime/src/{extensions/pop_api_extension.rs => extensions.rs} (75%) delete mode 100644 runtime/src/extensions/ext_impl/dispatch.rs delete mode 100644 runtime/src/extensions/ext_impl/mod.rs delete mode 100644 runtime/src/extensions/ext_impl/read_state.rs delete mode 100644 runtime/src/extensions/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 75af935a..3bb824fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9037,6 +9037,7 @@ dependencies = [ "parity-scale-codec", "pop-api-primitives", "scale-info", + "sp-io 23.0.0", "sp-runtime 24.0.0", ] @@ -9046,7 +9047,6 @@ version = "0.0.0" dependencies = [ "parity-scale-codec", "scale-info", - "sp-runtime 24.0.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 9fe934cd..1aa86971 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,12 +10,12 @@ repository = "https://github.com/r0gue-io/pop-node/" [workspace] members = [ - "node", - "runtime", - "pop-api", + "node", + "runtime", + "pop-api", ] exclude = [ - "contracts" + "contracts" ] resolver = "2" @@ -39,7 +39,7 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-s # Local pop-runtime = { path = "./runtime" } -pop-api-primitives = { path = "./pop-api/primitives"} +pop-api-primitives = { path = "./pop-api/primitives", default-features = false } # Substrate sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1" } diff --git a/contracts/pop-api-examples/balance-transfer/Cargo.toml b/contracts/pop-api-examples/balance-transfer/Cargo.toml index cee76dd5..20c307ee 100755 --- a/contracts/pop-api-examples/balance-transfer/Cargo.toml +++ b/contracts/pop-api-examples/balance-transfer/Cargo.toml @@ -6,12 +6,10 @@ edition = "2021" [dependencies] ink = { version = "4.3.0", default-features = false } +pop-api = { path = "../../../pop-api", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } -sp-io = { version = "23.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } -sp-runtime = { version = "24.0.0", default-features = false } - [dev-dependencies] ink_e2e = "4.3.0" @@ -22,10 +20,9 @@ path = "lib.rs" default = ["std"] std = [ "ink/std", + "pop-api/std", "scale/std", "scale-info/std", - "sp-runtime/std", - "sp-io/std", ] ink-as-dependency = [] e2e-tests = [] diff --git a/contracts/pop-api-examples/balance-transfer/lib.rs b/contracts/pop-api-examples/balance-transfer/lib.rs index c1614e97..5f791931 100755 --- a/contracts/pop-api-examples/balance-transfer/lib.rs +++ b/contracts/pop-api-examples/balance-transfer/lib.rs @@ -1,109 +1,27 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -use ink::{ - env::Environment, - prelude::vec::Vec, -}; - -use ink::primitives::AccountId; -use sp_runtime::MultiAddress; -use scale::{Encode, Decode}; - -#[derive(Encode)] -enum RuntimeCall { - Balances(BalancesCall), -} - -#[derive(scale::Encode)] -enum BalancesCall { - #[codec(index = 3)] - TransferKeepAlive { - dest: MultiAddress, - #[codec(compact)] - value: u128, - }, - #[codec(index = 8)] - ForceSetBalance { - who: MultiAddress, - #[codec(compact)] - new_free: u128, - }, -} +use pop_api::balances; #[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] -pub enum PopApiError { - TotalSupplyFailed, +pub enum ContractError { + BalancesError(balances::Error), } -pub type Result = core::result::Result; - -use scale; -impl From for PopApiError { - fn from(_: scale::Error) -> Self { - panic!("encountered unexpected invalid SCALE encoding") +impl From for ContractError { + fn from(value: balances::Error) -> Self { + ContractError::BalancesError(value) } } -#[ink::chain_extension] -pub trait PopApi { - type ErrorCode = PopApiError; - - #[ink(extension = 0x0)] - fn dispatch(call: RuntimeCall) -> Result>; -} - -impl ink::env::chain_extension::FromStatusCode for PopApiError { - fn from_status_code(status_code: u32) -> core::result::Result<(), Self> { - match status_code { - 0 => Ok(()), - 1 => Err(Self::TotalSupplyFailed), - _ => panic!("encountered unknown status code"), - } - } -} - -#[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] -pub enum CustomEnvironment {} - -impl Environment for CustomEnvironment { - const MAX_EVENT_TOPICS: usize = - ::MAX_EVENT_TOPICS; - - type AccountId = ::AccountId; - type Balance = ::Balance; - type Hash = ::Hash; - type BlockNumber = ::BlockNumber; - type Timestamp = ::Timestamp; - - type ChainExtension = PopApi; -} - -#[ink::contract(env = crate::CustomEnvironment)] +#[ink::contract(env = pop_api::Environment)] mod pop_api_extension_demo { - use crate::{ - BalancesCall, - RuntimeCall, - }; - - use super::PopApiError; - - use ink::env::Error as EnvError; + use super::ContractError; #[ink(storage)] #[derive(Default)] pub struct PopApiExtensionDemo; - impl From for PopApiError { - fn from(e: EnvError) -> Self { - match e { - EnvError::CallRuntimeFailed => PopApiError::TotalSupplyFailed, - _ => panic!("Unexpected error from `pallet-contracts`."), - } - } - } - impl PopApiExtensionDemo { #[ink(constructor, payable)] pub fn new() -> Self { @@ -116,17 +34,111 @@ mod pop_api_extension_demo { &mut self, receiver: AccountId, value: Balance, - ) { - ink::env::debug_println!("PopApiExtensionDemo::transfer_through_runtime: \nreceiver: {:?}, \nvalue: {:?}", receiver, value); + ) -> Result<(), ContractError> { + ink::env::debug_println!( + "PopApiExtensionDemo::transfer_through_runtime: \nreceiver: {:?}, \nvalue: {:?}", + receiver, + value + ); - let call = RuntimeCall::Balances(BalancesCall::TransferKeepAlive { - dest: receiver.into(), - value: value, - }); - self.env().extension().dispatch(call); + pop_api::balances::transfer_keep_alive(receiver, value)?; ink::env::debug_println!("PopApiExtensionDemo::transfer_through_runtime end"); - + Ok(()) + } + } + + #[cfg(all(test, feature = "e2e-tests"))] + mod e2e_tests { + use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; + + use ink::{ + env::{test::default_accounts, DefaultEnvironment}, + primitives::AccountId, + }; + + type E2EResult = Result>; + + /// The base number of indivisible units for balances on the + /// `substrate-contracts-node`. + const UNIT: Balance = 1_000_000_000_000; + + /// The contract will be given 1000 tokens during instantiation. + const CONTRACT_BALANCE: Balance = 1_000 * UNIT; + + /// The receiver will get enough funds to have the required existential deposit. + /// + /// If your chain has this threshold higher, increase the transfer value. + const TRANSFER_VALUE: Balance = 1 / 10 * UNIT; + + /// An amount that is below the existential deposit, so that a transfer to an + /// empty account fails. + /// + /// Must not be zero, because such an operation would be a successful no-op. + const INSUFFICIENT_TRANSFER_VALUE: Balance = 1; + + /// Positive case scenario: + /// - the call is valid + /// - the call execution succeeds + #[ink_e2e::test] + async fn transfer_with_call_runtime_works( + mut client: Client, + ) -> E2EResult<()> { + // given + let mut constructor = RuntimeCallerRef::new(); + let contract = client + .instantiate("call-runtime", &ink_e2e::alice(), &mut constructor) + .value(CONTRACT_BALANCE) + .submit() + .await + .expect("instantiate failed"); + let mut call_builder = contract.call_builder::(); + + let accounts = default_accounts::(); + + let receiver: AccountId = accounts.bob; + + let sender_balance_before = client + .free_balance(accounts.alice) + .await + .expect("Failed to get account balance"); + let receiver_balance_before = client + .free_balance(receiver) + .await + .expect("Failed to get account balance"); + + // when + let transfer_message = call_builder.transfer_through_runtime(receiver, TRANSFER_VALUE); + + let call_res = client + .call(&ink_e2e::alice(), &transfer_message) + .submit() + .await + .expect("call failed"); + + assert!(call_res.return_value().is_ok()); + + // then + let sender_balance_after = client + .free_balance(accounts.alice) + .await + .expect("Failed to get account balance"); + let receiver_balance_after = client + .free_balance(receiver) + .await + .expect("Failed to get account balance"); + + assert_eq!( + contract_balance_before, + contract_balance_after + TRANSFER_VALUE + ); + assert_eq!( + receiver_balance_before, + receiver_balance_after - TRANSFER_VALUE + ); + + Ok(()) } } -} \ No newline at end of file +} diff --git a/contracts/pop-api-examples/nfts/Cargo.toml b/contracts/pop-api-examples/nfts/Cargo.toml index 282d9a82..7b148648 100755 --- a/contracts/pop-api-examples/nfts/Cargo.toml +++ b/contracts/pop-api-examples/nfts/Cargo.toml @@ -9,8 +9,6 @@ ink = { version = "4.3.0", default-features = false } pop-api = { path = "../../../pop-api", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } -sp-io = { version = "23.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } -sp-runtime = { version = "24.0.0", default-features = false } [dev-dependencies] ink_e2e = "4.3.0" @@ -22,11 +20,9 @@ path = "lib.rs" default = ["std"] std = [ "ink/std", + "pop-api/std", "scale/std", "scale-info/std", - "sp-io/std", - "sp-runtime/std", - "pop-api/std", ] ink-as-dependency = [] e2e-tests = [] diff --git a/contracts/pop-api-examples/nfts/lib.rs b/contracts/pop-api-examples/nfts/lib.rs index 5af148ba..77c5820a 100755 --- a/contracts/pop-api-examples/nfts/lib.rs +++ b/contracts/pop-api-examples/nfts/lib.rs @@ -5,16 +5,16 @@ use pop_api::nfts; #[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum ContractError { - MintError(nfts::Error), + NftsError(nfts::Error), } impl From for ContractError { fn from(value: nfts::Error) -> Self { - ContractError::MintError(value) + ContractError::NftsError(value) } } -#[ink::contract(env = pop_api::PopEnv)] +#[ink::contract(env = pop_api::Environment)] mod pop_api_extension_demo { use super::ContractError; diff --git a/contracts/pop-api-examples/read-runtime-state/Cargo.toml b/contracts/pop-api-examples/read-runtime-state/Cargo.toml index 44c8965f..20c307ee 100755 --- a/contracts/pop-api-examples/read-runtime-state/Cargo.toml +++ b/contracts/pop-api-examples/read-runtime-state/Cargo.toml @@ -6,14 +6,10 @@ edition = "2021" [dependencies] ink = { version = "4.3.0", default-features = false } +pop-api = { path = "../../../pop-api", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } -pop-api = { path = "../../../pop-api", default-features = false } - -sp-io = { version = "23.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } -sp-runtime = { version = "24.0.0", default-features = false } - [dev-dependencies] ink_e2e = "4.3.0" @@ -24,11 +20,9 @@ path = "lib.rs" default = ["std"] std = [ "ink/std", + "pop-api/std", "scale/std", "scale-info/std", - "sp-runtime/std", - "sp-io/std", - "pop-api/std", ] ink-as-dependency = [] e2e-tests = [] diff --git a/contracts/pop-api-examples/read-runtime-state/lib.rs b/contracts/pop-api-examples/read-runtime-state/lib.rs index 3387ad08..9fc5e91b 100755 --- a/contracts/pop-api-examples/read-runtime-state/lib.rs +++ b/contracts/pop-api-examples/read-runtime-state/lib.rs @@ -1,104 +1,20 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -use ink::{ - env::Environment, - prelude::vec::Vec, -}; - -use ink::primitives::AccountId; -use sp_runtime::MultiAddress; -use pop_api::primitives::storage_keys::ParachainSystemKeys; - - -#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] -#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] -pub enum PopApiError { - TotalSupplyFailed, -} - -pub type Result = core::result::Result; - -use scale; -impl From for PopApiError { - fn from(_: scale::Error) -> Self { - panic!("encountered unexpected invalid SCALE encoding") - } -} - -/// This is an example of how an ink! contract may call the Substrate -/// runtime function `RandomnessCollectiveFlip::random_seed`. See the -/// file `runtime/chain-extension-example.rs` for that implementation. -/// -/// Here we define the operations to interact with the Substrate runtime. -#[ink::chain_extension] -pub trait PopApi { - type ErrorCode = PopApiError; - - /// Note: this gives the operation a corresponding `func_id` (1101 in this case), - /// and the chain-side chain extension will get the `func_id` to do further - /// operations. - - #[ink(extension = 0xfeca)] - fn read_state(key: ParachainSystemKeys) -> Result<::BlockNumber>; - -} - -impl ink::env::chain_extension::FromStatusCode for PopApiError { - fn from_status_code(status_code: u32) -> core::result::Result<(), Self> { - match status_code { - 0 => Ok(()), - 1 => Err(Self::TotalSupplyFailed), - _ => panic!("encountered unknown status code"), - } - } -} - -#[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] -pub enum CustomEnvironment {} - -impl Environment for CustomEnvironment { - const MAX_EVENT_TOPICS: usize = - ::MAX_EVENT_TOPICS; - - type AccountId = ::AccountId; - type Balance = ::Balance; - type Hash = ::Hash; - type BlockNumber = ::BlockNumber; - type Timestamp = ::Timestamp; - - type ChainExtension = PopApi; -} - -#[ink::contract(env = crate::CustomEnvironment)] +#[ink::contract(env = pop_api::Environment)] mod pop_api_extension_demo { - use crate::{ - ParachainSystemKeys, + use pop_api::primitives::storage_keys::{ + ParachainSystemKeys::LastRelayChainBlockNumber, RuntimeStateKeys::ParachainSystem, }; - use super::PopApiError; - - use ink::env::Error as EnvError; - #[ink(event)] pub struct RelayBlockNumberRead { - value: BlockNumber + value: BlockNumber, } - #[ink(storage)] #[derive(Default)] pub struct PopApiExtensionDemo; - impl From for PopApiError { - fn from(e: EnvError) -> Self { - match e { - EnvError::CallRuntimeFailed => PopApiError::TotalSupplyFailed, - _ => panic!("Unexpected error from `pallet-contracts`."), - } - } - } - impl PopApiExtensionDemo { #[ink(constructor, payable)] pub fn new() -> Self { @@ -107,14 +23,13 @@ mod pop_api_extension_demo { } #[ink(message)] - pub fn read_relay_block_number( - &self - ) { - let result = self.env().extension().read_state(ParachainSystemKeys::LastRelayChainBlockNumber); + pub fn read_relay_block_number(&self) { + let result = + pop_api::state::read::(ParachainSystem(LastRelayChainBlockNumber)); ink::env::debug_println!("{:?}", result); - self.env().emit_event( - RelayBlockNumberRead {value: result.expect("Failed to read relay block number.")} - ); + self.env().emit_event(RelayBlockNumberRead { + value: result.expect("Failed to read relay block number."), + }); } } -} \ No newline at end of file +} diff --git a/pop-api/Cargo.toml b/pop-api/Cargo.toml index 35c0d179..51d515c8 100644 --- a/pop-api/Cargo.toml +++ b/pop-api/Cargo.toml @@ -5,13 +5,12 @@ license = "GPL-3.0-only" version = "0.0.0" edition = "2021" -members = ["primitives/"] - [dependencies] ink = { version = "4.3.0", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } -sp-runtime = { version = "24.0.0", default-features = false } +sp-io = { version = "23.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } +sp-runtime = { version = "24.0", default-features = false } pop-api-primitives = { path = "./primitives", default-features = false } @@ -24,8 +23,9 @@ crate-type = ["rlib"] default = ["std"] std = [ "ink/std", - "sp-runtime/std", + "pop-api-primitives/std", "scale/std", "scale-info/std", - "pop-api-primitives/std", + "sp-io/std", + "sp-runtime/std", ] diff --git a/pop-api/primitives/Cargo.toml b/pop-api/primitives/Cargo.toml index 0fa865b0..80f0d929 100644 --- a/pop-api/primitives/Cargo.toml +++ b/pop-api/primitives/Cargo.toml @@ -6,23 +6,17 @@ version = "0.0.0" edition = "2021" [dependencies] -sp-runtime = { version = "24.0.0", default-features = false } - scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } [lib] name = "pop_api_primitives" path = "src/lib.rs" -crate-type = [ - "rlib", -] - +crate-type = ["rlib"] [features] default = ["std"] std = [ - "sp-runtime/std", "scale/std", "scale-info/std", ] diff --git a/pop-api/src/lib.rs b/pop-api/src/lib.rs index a9604481..1c9434ad 100644 --- a/pop-api/src/lib.rs +++ b/pop-api/src/lib.rs @@ -1,14 +1,15 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] +pub mod primitives; pub mod v0; -use crate::PopApiError::{Nfts, UnknownStatusCode}; -use ink::{env::Environment, ChainExtensionInstance}; -pub use pop_api_primitives as primitives; +use crate::PopApiError::{Balances, Nfts, UnknownStatusCode}; +use ink::{prelude::vec::Vec, ChainExtensionInstance}; +use primitives::storage_keys::*; use scale; -use sp_runtime::MultiSignature; -pub use v0::nfts; +pub use sp_runtime::{BoundedVec, MultiAddress, MultiSignature}; use v0::RuntimeCall; +pub use v0::{balances, nfts, state}; // Id used for identifying non-fungible collections. pub type CollectionId = u32; @@ -16,10 +17,9 @@ pub type CollectionId = u32; // Id used for identifying non-fungible items. pub type ItemId = u32; -type AccountId = ::AccountId; -type Balance = ::Balance; -type BlockNumber = ::BlockNumber; -type Signature = MultiSignature; +type AccountId = ::AccountId; +type Balance = ::Balance; +type BlockNumber = ::BlockNumber; type StringLimit = u32; type KeyLimit = u32; type MaxTips = u32; @@ -30,6 +30,8 @@ pub type Result = core::result::Result; #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum PopApiError { UnknownStatusCode(u32), + DecodingFailed, + Balances(balances::Error), Nfts(nfts::Error), } @@ -37,6 +39,7 @@ impl ink::env::chain_extension::FromStatusCode for PopApiError { fn from_status_code(status_code: u32) -> core::result::Result<(), Self> { match status_code { 0 => Ok(()), + 10_000..=10_999 => Err(Balances((status_code - 10_000).try_into()?)), 50_000..=50_999 => Err(Nfts((status_code - 50_000).try_into()?)), _ => Err(UnknownStatusCode(status_code)), } @@ -51,16 +54,17 @@ impl From for PopApiError { #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] -pub enum PopEnv {} +pub enum Environment {} -impl Environment for PopEnv { - const MAX_EVENT_TOPICS: usize = ::MAX_EVENT_TOPICS; +impl ink::env::Environment for Environment { + const MAX_EVENT_TOPICS: usize = + ::MAX_EVENT_TOPICS; - type AccountId = ::AccountId; - type Balance = ::Balance; - type Hash = ::Hash; - type BlockNumber = ::BlockNumber; - type Timestamp = ::Timestamp; + type AccountId = ::AccountId; + type Balance = ::Balance; + type Hash = ::Hash; + type BlockNumber = ::BlockNumber; + type Timestamp = ::Timestamp; type ChainExtension = PopApi; } @@ -71,14 +75,21 @@ pub trait PopApi { #[ink(extension = 0)] #[allow(private_interfaces)] - fn dispatch(call: RuntimeCall) -> crate::Result<()>; + fn dispatch(call: RuntimeCall) -> Result<()>; #[ink(extension = 1)] #[allow(private_interfaces)] - fn read_state(call: RuntimeCall) -> crate::Result>; + fn read_state(key: RuntimeStateKeys) -> Result>; } fn dispatch(call: RuntimeCall) -> Result<()> { - <::ChainExtension as ChainExtensionInstance>::instantiate() - .dispatch(call) + <::ChainExtension as ChainExtensionInstance>::instantiate( + ) + .dispatch(call) +} + +fn read_state(key: RuntimeStateKeys) -> Result> { + <::ChainExtension as ChainExtensionInstance>::instantiate( + ) + .read_state(key) } diff --git a/pop-api/src/primitives.rs b/pop-api/src/primitives.rs new file mode 100644 index 00000000..3a77b4fd --- /dev/null +++ b/pop-api/src/primitives.rs @@ -0,0 +1,2 @@ +pub use pop_api_primitives::*; +pub use sp_runtime::{BoundedVec, MultiAddress}; diff --git a/pop-api/src/v0/balances.rs b/pop-api/src/v0/balances.rs index 8b137891..9542b86f 100644 --- a/pop-api/src/v0/balances.rs +++ b/pop-api/src/v0/balances.rs @@ -1 +1,96 @@ +use crate::{ + dispatch, primitives::MultiAddress, v0::RuntimeCall, AccountId, PopApiError, + PopApiError::UnknownStatusCode, +}; +type Result = core::result::Result; + +pub fn transfer_keep_alive( + dest: impl Into>, + value: u128, +) -> Result<()> { + Ok(dispatch(RuntimeCall::Balances( + BalancesCall::TransferKeepAlive { + dest: dest.into(), + value, + }, + ))?) +} + +#[derive(scale::Encode)] +#[allow(dead_code)] +pub(crate) enum BalancesCall { + #[codec(index = 3)] + TransferKeepAlive { + dest: MultiAddress, + #[codec(compact)] + value: u128, + }, + #[codec(index = 8)] + ForceSetBalance { + who: MultiAddress, + #[codec(compact)] + new_free: u128, + }, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] +#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] +pub enum Error { + /// Vesting balance too high to send value. + VestingBalance, + /// Account liquidity restrictions prevent withdrawal. + LiquidityRestrictions, + /// Balance too low to send value. + InsufficientBalance, + /// Value too low to create account due to existential deposit. + ExistentialDeposit, + /// Transfer/payment would kill account. + Expendability, + /// A vesting schedule already exists for this account. + ExistingVestingSchedule, + /// Beneficiary account must pre-exist. + DeadAccount, + /// Number of named reserves exceed `MaxReserves`. + TooManyReserves, + /// Number of holds exceed `VariantCountOf`. + TooManyHolds, + /// Number of freezes exceed `MaxFreezes`. + TooManyFreezes, + /// The issuance cannot be modified since it is already deactivated. + IssuanceDeactivated, + /// The delta cannot be zero. + DeltaZero, +} + +impl TryFrom for Error { + type Error = PopApiError; + + fn try_from(status_code: u32) -> core::result::Result { + use Error::*; + match status_code { + 0 => Ok(VestingBalance), + 1 => Ok(LiquidityRestrictions), + 2 => Ok(InsufficientBalance), + 3 => Ok(ExistentialDeposit), + 4 => Ok(Expendability), + 5 => Ok(ExistingVestingSchedule), + 6 => Ok(DeadAccount), + 7 => Ok(TooManyReserves), + 8 => Ok(TooManyHolds), + 9 => Ok(TooManyFreezes), + 10 => Ok(IssuanceDeactivated), + 11 => Ok(DeltaZero), + _ => Err(UnknownStatusCode(status_code)), + } + } +} + +impl From for Error { + fn from(error: PopApiError) -> Self { + match error { + PopApiError::Balances(e) => e, + _ => panic!("expected balances error"), + } + } +} diff --git a/pop-api/src/v0/mod.rs b/pop-api/src/v0/mod.rs index 9692c233..22df6860 100644 --- a/pop-api/src/v0/mod.rs +++ b/pop-api/src/v0/mod.rs @@ -1,8 +1,11 @@ pub mod balances; pub mod nfts; +pub mod state; #[derive(scale::Encode)] pub(crate) enum RuntimeCall { + #[codec(index = 10)] + Balances(balances::BalancesCall), #[codec(index = 50)] Nfts(nfts::NftCalls), } diff --git a/pop-api/src/v0/nfts.rs b/pop-api/src/v0/nfts.rs index 6602d2cf..207c2674 100644 --- a/pop-api/src/v0/nfts.rs +++ b/pop-api/src/v0/nfts.rs @@ -1,7 +1,7 @@ use super::RuntimeCall; use crate::{PopApiError::UnknownStatusCode, *}; use ink::prelude::vec::Vec; -use sp_runtime::{BoundedVec, MultiAddress}; +use primitives::{BoundedVec, MultiAddress}; type Result = core::result::Result; diff --git a/pop-api/src/v0/state.rs b/pop-api/src/v0/state.rs new file mode 100644 index 00000000..78aa1700 --- /dev/null +++ b/pop-api/src/v0/state.rs @@ -0,0 +1,6 @@ +use crate::{primitives::storage_keys::RuntimeStateKeys, read_state, PopApiError}; +use scale::Decode; + +pub fn read(key: RuntimeStateKeys) -> crate::Result { + read_state(key).and_then(|v| T::decode(&mut &v[..]).map_err(|_e| PopApiError::DecodingFailed)) +} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 4ad0ae4f..a86a9db1 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -90,121 +90,122 @@ enumflags2 = "0.7.9" [features] default = ["std"] std = [ - "codec/std", - "cumulus-pallet-aura-ext/std", - "cumulus-pallet-parachain-system/std", - "cumulus-pallet-session-benchmarking/std", - "cumulus-pallet-xcm/std", - "cumulus-pallet-xcmp-queue/std", - "cumulus-primitives-core/std", - "cumulus-primitives-utility/std", - "frame-benchmarking/std", - "frame-executive/std", - "frame-support/std", - "frame-system-benchmarking/std", - "frame-system-rpc-runtime-api/std", - "frame-system/std", - "frame-try-runtime/std", - "log/std", - "pallet-aura/std", - "pallet-authorship/std", - "pallet-assets/std", - "pallet-balances/std", - "pallet-collator-selection/std", - "pallet-contracts/std", - "pallet-message-queue/std", - "pallet-nft-fractionalization/std", - "pallet-nfts/std", - "pallet-nfts-runtime-api/std", - "pallet-scheduler/std", - "pallet-session/std", - "pallet-sudo/std", - "pallet-preimage/std", - "pallet-timestamp/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "pallet-transaction-payment/std", - "pallet-xcm/std", - "parachain-info/std", - "parachains-common/std", - "polkadot-parachain-primitives/std", - "polkadot-runtime-common/std", - "scale-info/std", - "sp-api/std", - "sp-io/std", - "sp-block-builder/std", - "sp-consensus-aura/std", - "sp-core/std", - "sp-genesis-builder/std", - "sp-inherents/std", - "sp-offchain/std", - "sp-runtime/std", - "sp-session/std", - "sp-std/std", - "sp-transaction-pool/std", - "sp-version/std", - "xcm-builder/std", - "xcm-executor/std", - "xcm/std", + "codec/std", + "cumulus-pallet-aura-ext/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-session-benchmarking/std", + "cumulus-pallet-xcm/std", + "cumulus-pallet-xcmp-queue/std", + "cumulus-primitives-core/std", + "cumulus-primitives-utility/std", + "frame-benchmarking/std", + "frame-executive/std", + "frame-support/std", + "frame-system-benchmarking/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "frame-try-runtime/std", + "log/std", + "pallet-aura/std", + "pallet-authorship/std", + "pallet-assets/std", + "pallet-balances/std", + "pallet-collator-selection/std", + "pallet-contracts/std", + "pallet-message-queue/std", + "pallet-nft-fractionalization/std", + "pallet-nfts/std", + "pallet-nfts-runtime-api/std", + "pallet-scheduler/std", + "pallet-session/std", + "pallet-sudo/std", + "pallet-preimage/std", + "pallet-timestamp/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "pallet-xcm/std", + "parachain-info/std", + "parachains-common/std", + "polkadot-parachain-primitives/std", + "polkadot-runtime-common/std", + "pop-api-primitives/std", + "scale-info/std", + "sp-api/std", + "sp-io/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-core/std", + "sp-genesis-builder/std", + "sp-inherents/std", + "sp-offchain/std", + "sp-runtime/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", + "xcm-builder/std", + "xcm-executor/std", + "xcm/std", ] runtime-benchmarks = [ - "cumulus-pallet-parachain-system/runtime-benchmarks", - "cumulus-pallet-session-benchmarking/runtime-benchmarks", - "cumulus-pallet-xcmp-queue/runtime-benchmarks", - "cumulus-primitives-core/runtime-benchmarks", - "cumulus-primitives-utility/runtime-benchmarks", - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system-benchmarking/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-assets/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-collator-selection/runtime-benchmarks", - "pallet-contracts/runtime-benchmarks", - "pallet-message-queue/runtime-benchmarks", - "pallet-nft-fractionalization/runtime-benchmarks", - "pallet-nfts/runtime-benchmarks", - "pallet-scheduler/runtime-benchmarks", - "pallet-sudo/runtime-benchmarks", - "pallet-preimage/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "pallet-xcm/runtime-benchmarks", - "parachains-common/runtime-benchmarks", - "polkadot-parachain-primitives/runtime-benchmarks", - "polkadot-runtime-common/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "xcm-builder/runtime-benchmarks", - "xcm-executor/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "cumulus-primitives-core/runtime-benchmarks", + "cumulus-primitives-utility/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system-benchmarking/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-collator-selection/runtime-benchmarks", + "pallet-contracts/runtime-benchmarks", + "pallet-message-queue/runtime-benchmarks", + "pallet-nft-fractionalization/runtime-benchmarks", + "pallet-nfts/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "parachains-common/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] try-runtime = [ - "cumulus-pallet-aura-ext/try-runtime", - "cumulus-pallet-parachain-system/try-runtime", - "cumulus-pallet-xcm/try-runtime", - "cumulus-pallet-xcmp-queue/try-runtime", - "frame-executive/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "frame-try-runtime/try-runtime", - "pallet-aura/try-runtime", - "pallet-authorship/try-runtime", - "pallet-assets/try-runtime", - "pallet-balances/try-runtime", - "pallet-collator-selection/try-runtime", - "pallet-contracts/try-runtime", - "pallet-message-queue/try-runtime", - "pallet-nft-fractionalization/try-runtime", - "pallet-nfts/try-runtime", - "pallet-scheduler/try-runtime", - "pallet-session/try-runtime", - "pallet-sudo/try-runtime", - "pallet-preimage/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-transaction-payment/try-runtime", - "pallet-xcm/try-runtime", - "parachain-info/try-runtime", - "polkadot-runtime-common/try-runtime", - "sp-runtime/try-runtime", + "cumulus-pallet-aura-ext/try-runtime", + "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-xcm/try-runtime", + "cumulus-pallet-xcmp-queue/try-runtime", + "frame-executive/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "frame-try-runtime/try-runtime", + "pallet-aura/try-runtime", + "pallet-authorship/try-runtime", + "pallet-assets/try-runtime", + "pallet-balances/try-runtime", + "pallet-collator-selection/try-runtime", + "pallet-contracts/try-runtime", + "pallet-message-queue/try-runtime", + "pallet-nft-fractionalization/try-runtime", + "pallet-nfts/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-session/try-runtime", + "pallet-sudo/try-runtime", + "pallet-preimage/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-xcm/try-runtime", + "parachain-info/try-runtime", + "polkadot-runtime-common/try-runtime", + "sp-runtime/try-runtime", ] experimental = ["pallet-aura/experimental"] diff --git a/runtime/src/contracts_config.rs b/runtime/src/contracts_config.rs index 534a2d05..ea8aa661 100644 --- a/runtime/src/contracts_config.rs +++ b/runtime/src/contracts_config.rs @@ -63,7 +63,7 @@ impl pallet_contracts::Config for Runtime { type CallStack = [pallet_contracts::Frame; 23]; type WeightPrice = pallet_transaction_payment::Pallet; type WeightInfo = pallet_contracts::weights::SubstrateWeight; - type ChainExtension = extensions::pop_api_extension::PopApiExtension; + type ChainExtension = extensions::PopApiExtension; type Schedule = Schedule; type AddressGenerator = pallet_contracts::DefaultAddressGenerator; // This node is geared towards development and testing of contracts. diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions.rs similarity index 75% rename from runtime/src/extensions/pop_api_extension.rs rename to runtime/src/extensions.rs index 2b478c24..675d52c6 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions.rs @@ -1,29 +1,54 @@ +use cumulus_primitives_core::relay_chain::BlockNumber; use frame_support::{ - dispatch::{GetDispatchInfo, PostDispatchInfo}, + dispatch::{GetDispatchInfo, PostDispatchInfo, RawOrigin}, pallet_prelude::*, }; use log; use pallet_contracts::chain_extension::{ ChainExtension, Environment, Ext, InitState, RetVal, SysConfig, }; +use pop_api_primitives::storage_keys::ParachainSystemKeys; use sp_core::crypto::UncheckedFrom; use sp_runtime::{traits::Dispatchable, DispatchError}; -use crate::extensions::ext_impl::{dispatch::dispatch, read_state::read_state}; - -const LOG_TARGET: &str = "popapi::extension"; +const LOG_TARGET: &str = "pop-api::extension"; #[derive(Default)] pub struct PopApiExtension; -fn convert_err(err_msg: &'static str) -> impl FnOnce(DispatchError) -> DispatchError { - move |err| { - log::trace!( - target: LOG_TARGET, - "Pop API failed:{:?}", - err - ); - DispatchError::Other(err_msg) +impl ChainExtension for PopApiExtension +where + T: pallet_contracts::Config + cumulus_pallet_parachain_system::Config, + ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, + ::RuntimeCall: Parameter + + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> + + GetDispatchInfo + + From>, +{ + fn call(&mut self, env: Environment) -> Result + where + E: Ext, + ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, + { + log::debug!(target:LOG_TARGET, " extension called "); + match v0::FuncId::try_from(env.func_id())? { + v0::FuncId::Dispatch => { + match dispatch::(env) { + Ok(()) => Ok(RetVal::Converging(0)), + Err(DispatchError::Module(error)) => { + // encode status code = pallet index in runtime + error index, allowing for 999 errors + Ok(RetVal::Converging( + (error.index as u32 * 1_000) + u32::from_le_bytes(error.error), + )) + } + Err(e) => Err(e), + } + } + v0::FuncId::ReadState => { + read_state::(env)?; + Ok(RetVal::Converging(0)) + } + } } } @@ -43,8 +68,8 @@ impl TryFrom for v0::FuncId { 0x0 => Self::Dispatch, 0x1 => Self::ReadState, _ => { - log::error!("Called an unregistered `func_id`: {:}", func_id); - return Err(DispatchError::Other("Unimplemented func_id")); + log::error!("called an unregistered `func_id`: {:}", func_id); + return Err(DispatchError::Other("unimplemented func_id")); } }; @@ -52,40 +77,91 @@ impl TryFrom for v0::FuncId { } } -impl ChainExtension for PopApiExtension +pub(crate) fn dispatch(env: Environment) -> Result<(), DispatchError> where - T: pallet_contracts::Config + cumulus_pallet_parachain_system::Config, + T: pallet_contracts::Config + frame_system::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, ::RuntimeCall: Parameter + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> + GetDispatchInfo + From>, + E: Ext, { - fn call(&mut self, env: Environment) -> Result - where - E: Ext, - ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, - { - log::debug!(target:LOG_TARGET, " extension called "); - match v0::FuncId::try_from(env.func_id())? { - v0::FuncId::Dispatch => { - match dispatch::(env) { - Ok(()) => Ok(RetVal::Converging(0)), - Err(DispatchError::Module(error)) => { - // encode status code = pallet index in runtime + error index, allowing for 999 errors - Ok(RetVal::Converging( - (error.index as u32 * 1_000) + u32::from_le_bytes(error.error), - )) - } - Err(e) => Err(e), - } - } - v0::FuncId::ReadState => { - read_state::(env)?; - Ok(RetVal::Converging(0)) - } + const LOG_TARGET: &str = "pop-api::extension::dispatch"; + + let mut env = env.buf_in_buf_out(); + + // charge max weight before reading contract memory + // TODO: causing "1010: block limits exhausted" error + // let weight_limit = env.ext().gas_meter().gas_left(); + // let charged_weight = env.charge_weight(weight_limit)?; + + // TODO: debug_message weight is a good approximation of the additional overhead of going + // from contract layer to substrate layer. + + // input length + let len = env.in_len(); + let call: ::RuntimeCall = env.read_as_unbounded(len)?; + + // conservative weight estimate for deserializing the input. The actual weight is less and should utilize a custom benchmark + let base_weight: Weight = T::DbWeight::get().reads(len.into()); + + // weight for dispatching the call + let dispatch_weight = call.get_dispatch_info().weight; + + // charge weight for the cost of the deserialization and the dispatch + let _ = env.charge_weight(base_weight.saturating_add(dispatch_weight))?; + + log::debug!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); + + let sender = env.ext().caller(); + let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); + + // TODO: uncomment once charged_weight is fixed + // let actual_weight = call.get_dispatch_info().weight; + // env.adjust_weight(charged_weight, actual_weight); + let result = call.dispatch(origin); + match result { + Ok(info) => { + log::debug!(target:LOG_TARGET, "dispatch success, actual weight: {:?}", info.actual_weight); + } + Err(err) => { + log::debug!(target:LOG_TARGET, "dispatch failed: error: {:?}", err.error); + return Err(err.error); + } + } + Ok(()) +} + +pub(crate) fn read_state(env: Environment) -> Result<(), DispatchError> +where + T: pallet_contracts::Config + frame_system::Config, + E: Ext, +{ + const LOG_TARGET: &str = "pop-api::extension::read_state"; + + let mut env = env.buf_in_buf_out(); + + // TODO: Substitute len u32 with pop_api::src::impls::pop_network::StringLimit. + // Move StringLimit to pop_api_primitives first. + let len: u32 = env.in_len(); + let key: ParachainSystemKeys = env.read_as_unbounded(len)?; + + let result = match key { + ParachainSystemKeys::LastRelayChainBlockNumber => { + let relay_block_num: BlockNumber = crate::ParachainSystem::last_relay_block_number(); + log::debug!( + target:LOG_TARGET, + "last relay chain block number is: {:?}.", relay_block_num + ); + relay_block_num } } + .encode(); + env.write(&result, false, None).map_err(|e| { + log::trace!(target: LOG_TARGET, "{:?}", e); + DispatchError::Other("unable to write results to contract memory") + }) } #[cfg(test)] @@ -140,7 +216,7 @@ mod tests { // NFT helper functions fn collection_config_from_disabled_settings( settings: BitFlags, - ) -> CollectionConfig { + ) -> CollectionConfig { CollectionConfig { settings: CollectionSettings::from_disabled(settings), max_supply: None, @@ -148,7 +224,7 @@ mod tests { } } - fn default_collection_config() -> CollectionConfig { + fn default_collection_config() -> CollectionConfig { collection_config_from_disabled_settings(CollectionSetting::DepositRequired.into()) } @@ -172,8 +248,8 @@ mod tests { DEBUG_OUTPUT, pallet_contracts::CollectEvents::Skip, ) - .result - .unwrap(); + .result + .unwrap(); assert!( !result.result.did_revert(), diff --git a/runtime/src/extensions/ext_impl/dispatch.rs b/runtime/src/extensions/ext_impl/dispatch.rs deleted file mode 100644 index 3a9dc901..00000000 --- a/runtime/src/extensions/ext_impl/dispatch.rs +++ /dev/null @@ -1,53 +0,0 @@ -use frame_support::{ - dispatch::{GetDispatchInfo, PostDispatchInfo, RawOrigin}, - pallet_prelude::*, -}; -use log; -use pallet_contracts::chain_extension::{Environment, Ext, InitState, SysConfig}; -use sp_core::crypto::UncheckedFrom; -use sp_runtime::{traits::Dispatchable, DispatchError}; - -const LOG_TARGET: &str = "popapi::extension::dispatch"; - -pub(crate) fn dispatch(env: Environment) -> Result<(), DispatchError> -where - T: pallet_contracts::Config + frame_system::Config, - ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, - ::RuntimeCall: Parameter - + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> - + GetDispatchInfo - + From>, - E: Ext, -{ - let mut env = env.buf_in_buf_out(); - - // input length - let len = env.in_len(); - let call: ::RuntimeCall = env.read_as_unbounded(len)?; - - // conservative weight estimate for deserializing the input. The actual weight is less and should utilize a custom benchmark - let base_weight: Weight = T::DbWeight::get().reads(len.into()); - - // weight for dispatching the call - let dispatch_weight = call.get_dispatch_info().weight; - - // charge weight for the cost of the deserialization and the dispatch - let _ = env.charge_weight(base_weight.saturating_add(dispatch_weight))?; - - log::debug!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); - - let sender = env.ext().caller(); - let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); - - let result = call.dispatch(origin); - match result { - Ok(info) => { - log::debug!(target:LOG_TARGET, "dispatch success, actual weight: {:?}", info.actual_weight); - } - Err(err) => { - log::debug!(target:LOG_TARGET, "dispatch failed: error: {:?}", err.error); - return Err(err.error); - } - } - Ok(()) -} diff --git a/runtime/src/extensions/ext_impl/mod.rs b/runtime/src/extensions/ext_impl/mod.rs deleted file mode 100644 index 2389a49b..00000000 --- a/runtime/src/extensions/ext_impl/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod dispatch; -pub mod read_state; diff --git a/runtime/src/extensions/ext_impl/read_state.rs b/runtime/src/extensions/ext_impl/read_state.rs deleted file mode 100644 index f266a1eb..00000000 --- a/runtime/src/extensions/ext_impl/read_state.rs +++ /dev/null @@ -1,32 +0,0 @@ -use cumulus_primitives_core::relay_chain::BlockNumber; -use frame_support::pallet_prelude::*; -use log; -use pallet_contracts::chain_extension::{Environment, Ext, InitState}; -use pop_api_primitives::storage_keys::ParachainSystemKeys; - -const LOG_TARGET: &str = "popapi::extension::read_state"; - -pub(crate) fn read_state(env: Environment) -> Result<(), DispatchError> -where - T: pallet_contracts::Config + frame_system::Config, - E: Ext, -{ - let mut env = env.buf_in_buf_out(); - // TODO: Substitue len u32 with pop_api::src::impls::pop_network::StringLimit. - // Move StringLimit to pop_api_primitives first. - let len: u32 = env.in_len(); - let key: ParachainSystemKeys = env.read_as_unbounded(len)?; - - match key { - ParachainSystemKeys::LastRelayChainBlockNumber => { - let relay_block_num: BlockNumber = crate::ParachainSystem::last_relay_block_number(); - log::debug!( - target:LOG_TARGET, - "Last Relay Chain Block Number is: {:?}.", relay_block_num - ); - //Ok(relay_block_num) - Ok(()) - } - _ => Err(DispatchError::Other("Unable to read provided key.")), - } -} diff --git a/runtime/src/extensions/mod.rs b/runtime/src/extensions/mod.rs deleted file mode 100644 index 3f110092..00000000 --- a/runtime/src/extensions/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod ext_impl; -pub mod pop_api_extension; From ffefc61008c92489600d4e0c4513ab35bfdec87d Mon Sep 17 00:00:00 2001 From: Frank Bell Date: Tue, 5 Mar 2024 23:36:26 +0000 Subject: [PATCH 18/19] test: ignore tests which expect built contracts --- runtime/src/extensions.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/src/extensions.rs b/runtime/src/extensions.rs index 675d52c6..ae0081ae 100644 --- a/runtime/src/extensions.rs +++ b/runtime/src/extensions.rs @@ -229,6 +229,7 @@ mod tests { } #[test] + #[ignore] fn dispatch_balance_transfer_from_contract_works() { new_test_ext().execute_with(|| { let _ = env_logger::try_init(); @@ -295,6 +296,7 @@ mod tests { } #[test] + #[ignore] fn dispatch_nfts_mint_from_contract_works() { new_test_ext().execute_with(|| { let _ = env_logger::try_init(); @@ -383,6 +385,7 @@ mod tests { } #[test] + #[ignore] fn nfts_mint_surfaces_error() { new_test_ext().execute_with(|| { let _ = env_logger::try_init(); From d4c9e3232ad57215ff1a345e097615d3e70ee16b Mon Sep 17 00:00:00 2001 From: Frank Bell Date: Wed, 6 Mar 2024 01:34:14 +0000 Subject: [PATCH 19/19] style: formatting --- .../pop-api-examples/balance-transfer/lib.rs | 248 +++---- pop-api/primitives/src/storage_keys.rs | 4 +- pop-api/src/lib.rs | 72 +- pop-api/src/v0/balances.rs | 140 ++-- pop-api/src/v0/mod.rs | 8 +- pop-api/src/v0/nfts.rs | 643 ++++++++-------- pop-api/src/v0/state.rs | 2 +- runtime/src/contracts_config.rs | 4 +- runtime/src/extensions.rs | 702 +++++++++--------- runtime/src/extensions/ext_impl/dispatch.rs | 53 -- runtime/src/extensions/ext_impl/mod.rs | 2 - runtime/src/extensions/ext_impl/read_state.rs | 33 - runtime/src/extensions/mod.rs | 2 - runtime/src/extensions/pop_api_extension.rs | 297 -------- 14 files changed, 870 insertions(+), 1340 deletions(-) delete mode 100644 runtime/src/extensions/ext_impl/dispatch.rs delete mode 100644 runtime/src/extensions/ext_impl/mod.rs delete mode 100644 runtime/src/extensions/ext_impl/read_state.rs delete mode 100644 runtime/src/extensions/mod.rs delete mode 100644 runtime/src/extensions/pop_api_extension.rs diff --git a/contracts/pop-api-examples/balance-transfer/lib.rs b/contracts/pop-api-examples/balance-transfer/lib.rs index 5f791931..34c6a2cf 100755 --- a/contracts/pop-api-examples/balance-transfer/lib.rs +++ b/contracts/pop-api-examples/balance-transfer/lib.rs @@ -5,140 +5,130 @@ use pop_api::balances; #[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum ContractError { - BalancesError(balances::Error), + BalancesError(balances::Error), } impl From for ContractError { - fn from(value: balances::Error) -> Self { - ContractError::BalancesError(value) - } + fn from(value: balances::Error) -> Self { + ContractError::BalancesError(value) + } } #[ink::contract(env = pop_api::Environment)] mod pop_api_extension_demo { - use super::ContractError; - - #[ink(storage)] - #[derive(Default)] - pub struct PopApiExtensionDemo; - - impl PopApiExtensionDemo { - #[ink(constructor, payable)] - pub fn new() -> Self { - ink::env::debug_println!("PopApiExtensionDemo::new"); - Default::default() - } - - #[ink(message)] - pub fn transfer_through_runtime( - &mut self, - receiver: AccountId, - value: Balance, - ) -> Result<(), ContractError> { - ink::env::debug_println!( - "PopApiExtensionDemo::transfer_through_runtime: \nreceiver: {:?}, \nvalue: {:?}", - receiver, - value - ); - - pop_api::balances::transfer_keep_alive(receiver, value)?; - - ink::env::debug_println!("PopApiExtensionDemo::transfer_through_runtime end"); - Ok(()) - } - } - - #[cfg(all(test, feature = "e2e-tests"))] - mod e2e_tests { - use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; - - use ink::{ - env::{test::default_accounts, DefaultEnvironment}, - primitives::AccountId, - }; - - type E2EResult = Result>; - - /// The base number of indivisible units for balances on the - /// `substrate-contracts-node`. - const UNIT: Balance = 1_000_000_000_000; - - /// The contract will be given 1000 tokens during instantiation. - const CONTRACT_BALANCE: Balance = 1_000 * UNIT; - - /// The receiver will get enough funds to have the required existential deposit. - /// - /// If your chain has this threshold higher, increase the transfer value. - const TRANSFER_VALUE: Balance = 1 / 10 * UNIT; - - /// An amount that is below the existential deposit, so that a transfer to an - /// empty account fails. - /// - /// Must not be zero, because such an operation would be a successful no-op. - const INSUFFICIENT_TRANSFER_VALUE: Balance = 1; - - /// Positive case scenario: - /// - the call is valid - /// - the call execution succeeds - #[ink_e2e::test] - async fn transfer_with_call_runtime_works( - mut client: Client, - ) -> E2EResult<()> { - // given - let mut constructor = RuntimeCallerRef::new(); - let contract = client - .instantiate("call-runtime", &ink_e2e::alice(), &mut constructor) - .value(CONTRACT_BALANCE) - .submit() - .await - .expect("instantiate failed"); - let mut call_builder = contract.call_builder::(); - - let accounts = default_accounts::(); - - let receiver: AccountId = accounts.bob; - - let sender_balance_before = client - .free_balance(accounts.alice) - .await - .expect("Failed to get account balance"); - let receiver_balance_before = client - .free_balance(receiver) - .await - .expect("Failed to get account balance"); - - // when - let transfer_message = call_builder.transfer_through_runtime(receiver, TRANSFER_VALUE); - - let call_res = client - .call(&ink_e2e::alice(), &transfer_message) - .submit() - .await - .expect("call failed"); - - assert!(call_res.return_value().is_ok()); - - // then - let sender_balance_after = client - .free_balance(accounts.alice) - .await - .expect("Failed to get account balance"); - let receiver_balance_after = client - .free_balance(receiver) - .await - .expect("Failed to get account balance"); - - assert_eq!( - contract_balance_before, - contract_balance_after + TRANSFER_VALUE - ); - assert_eq!( - receiver_balance_before, - receiver_balance_after - TRANSFER_VALUE - ); - - Ok(()) - } - } + use super::ContractError; + + #[ink(storage)] + #[derive(Default)] + pub struct PopApiExtensionDemo; + + impl PopApiExtensionDemo { + #[ink(constructor, payable)] + pub fn new() -> Self { + ink::env::debug_println!("PopApiExtensionDemo::new"); + Default::default() + } + + #[ink(message)] + pub fn transfer_through_runtime( + &mut self, + receiver: AccountId, + value: Balance, + ) -> Result<(), ContractError> { + ink::env::debug_println!( + "PopApiExtensionDemo::transfer_through_runtime: \nreceiver: {:?}, \nvalue: {:?}", + receiver, + value + ); + + pop_api::balances::transfer_keep_alive(receiver, value)?; + + ink::env::debug_println!("PopApiExtensionDemo::transfer_through_runtime end"); + Ok(()) + } + } + + #[cfg(all(test, feature = "e2e-tests"))] + mod e2e_tests { + use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; + + use ink::{ + env::{test::default_accounts, DefaultEnvironment}, + primitives::AccountId, + }; + + type E2EResult = Result>; + + /// The base number of indivisible units for balances on the + /// `substrate-contracts-node`. + const UNIT: Balance = 1_000_000_000_000; + + /// The contract will be given 1000 tokens during instantiation. + const CONTRACT_BALANCE: Balance = 1_000 * UNIT; + + /// The receiver will get enough funds to have the required existential deposit. + /// + /// If your chain has this threshold higher, increase the transfer value. + const TRANSFER_VALUE: Balance = 1 / 10 * UNIT; + + /// An amount that is below the existential deposit, so that a transfer to an + /// empty account fails. + /// + /// Must not be zero, because such an operation would be a successful no-op. + const INSUFFICIENT_TRANSFER_VALUE: Balance = 1; + + /// Positive case scenario: + /// - the call is valid + /// - the call execution succeeds + #[ink_e2e::test] + async fn transfer_with_call_runtime_works( + mut client: Client, + ) -> E2EResult<()> { + // given + let mut constructor = RuntimeCallerRef::new(); + let contract = client + .instantiate("call-runtime", &ink_e2e::alice(), &mut constructor) + .value(CONTRACT_BALANCE) + .submit() + .await + .expect("instantiate failed"); + let mut call_builder = contract.call_builder::(); + + let accounts = default_accounts::(); + + let receiver: AccountId = accounts.bob; + + let sender_balance_before = client + .free_balance(accounts.alice) + .await + .expect("Failed to get account balance"); + let receiver_balance_before = + client.free_balance(receiver).await.expect("Failed to get account balance"); + + // when + let transfer_message = call_builder.transfer_through_runtime(receiver, TRANSFER_VALUE); + + let call_res = client + .call(&ink_e2e::alice(), &transfer_message) + .submit() + .await + .expect("call failed"); + + assert!(call_res.return_value().is_ok()); + + // then + let sender_balance_after = client + .free_balance(accounts.alice) + .await + .expect("Failed to get account balance"); + let receiver_balance_after = + client.free_balance(receiver).await.expect("Failed to get account balance"); + + assert_eq!(contract_balance_before, contract_balance_after + TRANSFER_VALUE); + assert_eq!(receiver_balance_before, receiver_balance_after - TRANSFER_VALUE); + + Ok(()) + } + } } diff --git a/pop-api/primitives/src/storage_keys.rs b/pop-api/primitives/src/storage_keys.rs index a67f3a18..63595cf3 100644 --- a/pop-api/primitives/src/storage_keys.rs +++ b/pop-api/primitives/src/storage_keys.rs @@ -2,10 +2,10 @@ use scale::{Decode, Encode}; #[derive(Encode, Decode, Debug)] pub enum RuntimeStateKeys { - ParachainSystem(ParachainSystemKeys), + ParachainSystem(ParachainSystemKeys), } #[derive(Encode, Decode, Debug)] pub enum ParachainSystemKeys { - LastRelayChainBlockNumber, + LastRelayChainBlockNumber, } diff --git a/pop-api/src/lib.rs b/pop-api/src/lib.rs index 1c9434ad..af96523f 100644 --- a/pop-api/src/lib.rs +++ b/pop-api/src/lib.rs @@ -29,27 +29,27 @@ pub type Result = core::result::Result; #[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum PopApiError { - UnknownStatusCode(u32), - DecodingFailed, - Balances(balances::Error), - Nfts(nfts::Error), + UnknownStatusCode(u32), + DecodingFailed, + Balances(balances::Error), + Nfts(nfts::Error), } impl ink::env::chain_extension::FromStatusCode for PopApiError { - fn from_status_code(status_code: u32) -> core::result::Result<(), Self> { - match status_code { - 0 => Ok(()), - 10_000..=10_999 => Err(Balances((status_code - 10_000).try_into()?)), - 50_000..=50_999 => Err(Nfts((status_code - 50_000).try_into()?)), - _ => Err(UnknownStatusCode(status_code)), - } - } + fn from_status_code(status_code: u32) -> core::result::Result<(), Self> { + match status_code { + 0 => Ok(()), + 10_000..=10_999 => Err(Balances((status_code - 10_000).try_into()?)), + 50_000..=50_999 => Err(Nfts((status_code - 50_000).try_into()?)), + _ => Err(UnknownStatusCode(status_code)), + } + } } impl From for PopApiError { - fn from(_: scale::Error) -> Self { - panic!("encountered unexpected invalid SCALE encoding") - } + fn from(_: scale::Error) -> Self { + panic!("encountered unexpected invalid SCALE encoding") + } } #[derive(Debug, Clone, PartialEq, Eq)] @@ -57,39 +57,39 @@ impl From for PopApiError { pub enum Environment {} impl ink::env::Environment for Environment { - const MAX_EVENT_TOPICS: usize = - ::MAX_EVENT_TOPICS; + const MAX_EVENT_TOPICS: usize = + ::MAX_EVENT_TOPICS; - type AccountId = ::AccountId; - type Balance = ::Balance; - type Hash = ::Hash; - type BlockNumber = ::BlockNumber; - type Timestamp = ::Timestamp; + type AccountId = ::AccountId; + type Balance = ::Balance; + type Hash = ::Hash; + type BlockNumber = ::BlockNumber; + type Timestamp = ::Timestamp; - type ChainExtension = PopApi; + type ChainExtension = PopApi; } #[ink::chain_extension] pub trait PopApi { - type ErrorCode = PopApiError; + type ErrorCode = PopApiError; - #[ink(extension = 0)] - #[allow(private_interfaces)] - fn dispatch(call: RuntimeCall) -> Result<()>; + #[ink(extension = 0)] + #[allow(private_interfaces)] + fn dispatch(call: RuntimeCall) -> Result<()>; - #[ink(extension = 1)] - #[allow(private_interfaces)] - fn read_state(key: RuntimeStateKeys) -> Result>; + #[ink(extension = 1)] + #[allow(private_interfaces)] + fn read_state(key: RuntimeStateKeys) -> Result>; } fn dispatch(call: RuntimeCall) -> Result<()> { - <::ChainExtension as ChainExtensionInstance>::instantiate( - ) - .dispatch(call) + <::ChainExtension as ChainExtensionInstance>::instantiate( + ) + .dispatch(call) } fn read_state(key: RuntimeStateKeys) -> Result> { - <::ChainExtension as ChainExtensionInstance>::instantiate( - ) - .read_state(key) + <::ChainExtension as ChainExtensionInstance>::instantiate( + ) + .read_state(key) } diff --git a/pop-api/src/v0/balances.rs b/pop-api/src/v0/balances.rs index 9542b86f..d8ba16d0 100644 --- a/pop-api/src/v0/balances.rs +++ b/pop-api/src/v0/balances.rs @@ -1,96 +1,94 @@ use crate::{ - dispatch, primitives::MultiAddress, v0::RuntimeCall, AccountId, PopApiError, - PopApiError::UnknownStatusCode, + dispatch, primitives::MultiAddress, v0::RuntimeCall, AccountId, PopApiError, + PopApiError::UnknownStatusCode, }; type Result = core::result::Result; pub fn transfer_keep_alive( - dest: impl Into>, - value: u128, + dest: impl Into>, + value: u128, ) -> Result<()> { - Ok(dispatch(RuntimeCall::Balances( - BalancesCall::TransferKeepAlive { - dest: dest.into(), - value, - }, - ))?) + Ok(dispatch(RuntimeCall::Balances(BalancesCall::TransferKeepAlive { + dest: dest.into(), + value, + }))?) } #[derive(scale::Encode)] #[allow(dead_code)] pub(crate) enum BalancesCall { - #[codec(index = 3)] - TransferKeepAlive { - dest: MultiAddress, - #[codec(compact)] - value: u128, - }, - #[codec(index = 8)] - ForceSetBalance { - who: MultiAddress, - #[codec(compact)] - new_free: u128, - }, + #[codec(index = 3)] + TransferKeepAlive { + dest: MultiAddress, + #[codec(compact)] + value: u128, + }, + #[codec(index = 8)] + ForceSetBalance { + who: MultiAddress, + #[codec(compact)] + new_free: u128, + }, } #[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum Error { - /// Vesting balance too high to send value. - VestingBalance, - /// Account liquidity restrictions prevent withdrawal. - LiquidityRestrictions, - /// Balance too low to send value. - InsufficientBalance, - /// Value too low to create account due to existential deposit. - ExistentialDeposit, - /// Transfer/payment would kill account. - Expendability, - /// A vesting schedule already exists for this account. - ExistingVestingSchedule, - /// Beneficiary account must pre-exist. - DeadAccount, - /// Number of named reserves exceed `MaxReserves`. - TooManyReserves, - /// Number of holds exceed `VariantCountOf`. - TooManyHolds, - /// Number of freezes exceed `MaxFreezes`. - TooManyFreezes, - /// The issuance cannot be modified since it is already deactivated. - IssuanceDeactivated, - /// The delta cannot be zero. - DeltaZero, + /// Vesting balance too high to send value. + VestingBalance, + /// Account liquidity restrictions prevent withdrawal. + LiquidityRestrictions, + /// Balance too low to send value. + InsufficientBalance, + /// Value too low to create account due to existential deposit. + ExistentialDeposit, + /// Transfer/payment would kill account. + Expendability, + /// A vesting schedule already exists for this account. + ExistingVestingSchedule, + /// Beneficiary account must pre-exist. + DeadAccount, + /// Number of named reserves exceed `MaxReserves`. + TooManyReserves, + /// Number of holds exceed `VariantCountOf`. + TooManyHolds, + /// Number of freezes exceed `MaxFreezes`. + TooManyFreezes, + /// The issuance cannot be modified since it is already deactivated. + IssuanceDeactivated, + /// The delta cannot be zero. + DeltaZero, } impl TryFrom for Error { - type Error = PopApiError; + type Error = PopApiError; - fn try_from(status_code: u32) -> core::result::Result { - use Error::*; - match status_code { - 0 => Ok(VestingBalance), - 1 => Ok(LiquidityRestrictions), - 2 => Ok(InsufficientBalance), - 3 => Ok(ExistentialDeposit), - 4 => Ok(Expendability), - 5 => Ok(ExistingVestingSchedule), - 6 => Ok(DeadAccount), - 7 => Ok(TooManyReserves), - 8 => Ok(TooManyHolds), - 9 => Ok(TooManyFreezes), - 10 => Ok(IssuanceDeactivated), - 11 => Ok(DeltaZero), - _ => Err(UnknownStatusCode(status_code)), - } - } + fn try_from(status_code: u32) -> core::result::Result { + use Error::*; + match status_code { + 0 => Ok(VestingBalance), + 1 => Ok(LiquidityRestrictions), + 2 => Ok(InsufficientBalance), + 3 => Ok(ExistentialDeposit), + 4 => Ok(Expendability), + 5 => Ok(ExistingVestingSchedule), + 6 => Ok(DeadAccount), + 7 => Ok(TooManyReserves), + 8 => Ok(TooManyHolds), + 9 => Ok(TooManyFreezes), + 10 => Ok(IssuanceDeactivated), + 11 => Ok(DeltaZero), + _ => Err(UnknownStatusCode(status_code)), + } + } } impl From for Error { - fn from(error: PopApiError) -> Self { - match error { - PopApiError::Balances(e) => e, - _ => panic!("expected balances error"), - } - } + fn from(error: PopApiError) -> Self { + match error { + PopApiError::Balances(e) => e, + _ => panic!("expected balances error"), + } + } } diff --git a/pop-api/src/v0/mod.rs b/pop-api/src/v0/mod.rs index 22df6860..7b87dc25 100644 --- a/pop-api/src/v0/mod.rs +++ b/pop-api/src/v0/mod.rs @@ -4,8 +4,8 @@ pub mod state; #[derive(scale::Encode)] pub(crate) enum RuntimeCall { - #[codec(index = 10)] - Balances(balances::BalancesCall), - #[codec(index = 50)] - Nfts(nfts::NftCalls), + #[codec(index = 10)] + Balances(balances::BalancesCall), + #[codec(index = 50)] + Nfts(nfts::NftCalls), } diff --git a/pop-api/src/v0/nfts.rs b/pop-api/src/v0/nfts.rs index 207c2674..90e5cac0 100644 --- a/pop-api/src/v0/nfts.rs +++ b/pop-api/src/v0/nfts.rs @@ -6,370 +6,317 @@ use primitives::{BoundedVec, MultiAddress}; type Result = core::result::Result; pub fn mint( - collection: CollectionId, - item: ItemId, - mint_to: impl Into>, + collection: CollectionId, + item: ItemId, + mint_to: impl Into>, ) -> Result<()> { - Ok(dispatch(RuntimeCall::Nfts(NftCalls::Mint { - collection, - item, - mint_to: mint_to.into(), - witness_data: None, - }))?) + Ok(dispatch(RuntimeCall::Nfts(NftCalls::Mint { + collection, + item, + mint_to: mint_to.into(), + witness_data: None, + }))?) } #[derive(scale::Encode)] #[allow(dead_code)] pub(crate) enum NftCalls { - // #[codec(index = 0)] - // Create { - // admin: MultiAddress, - // config: CollectionConfig - // }, - #[codec(index = 2)] - Destroy { collection: CollectionId }, - #[codec(index = 3)] - Mint { - collection: CollectionId, - item: ItemId, - mint_to: MultiAddress, - witness_data: Option<()>, - }, - #[codec(index = 5)] - Burn { - collection: CollectionId, - item: ItemId, - }, - #[codec(index = 6)] - Transfer { - collection: CollectionId, - item: ItemId, - dest: MultiAddress, - }, - #[codec(index = 7)] - Redeposit { - collection: CollectionId, - items: Vec, - }, - #[codec(index = 8)] - LockItemTransfer { - collection: CollectionId, - item: ItemId, - }, - #[codec(index = 9)] - UnlockItemTransfer { - collection: CollectionId, - item: ItemId, - }, - // #[codec(index = 10)] - // LockCollection { - // collection: CollectionId, - // lock_settings: CollectionSettings, - // }, - #[codec(index = 11)] - TransferOwnership { - collection: CollectionId, - new_owner: MultiAddress, - }, - #[codec(index = 12)] - SetTeam { - collection: CollectionId, - issuer: Option>, - admin: Option>, - freezer: Option>, - }, - #[codec(index = 15)] - ApproveTransfer { - collection: CollectionId, - item: ItemId, - delegate: MultiAddress, - maybe_deadline: Option, - }, - #[codec(index = 16)] - CancelApproval { - collection: CollectionId, - item: ItemId, - delegate: MultiAddress, - }, - #[codec(index = 17)] - ClearAllTransferApprovals { - collection: CollectionId, - item: ItemId, - }, - #[codec(index = 18)] - LockItemProperties { - collection: CollectionId, - item: ItemId, - lock_metadata: bool, - lock_attributes: bool, - }, - // #[codec(index = 19)] - // SetAttribute { - // collection: CollectionId, - // maybe_item: Option, - // namespace: AttributeNamespace, - // key: BoundedVec, - // value: BoundedVec, - // }, - // #[codec(index = 21)] - // ClearAttribute { - // collection: CollectionId, - // maybe_item: Option, - // namespace: AttributeNamespace, - // key: BoundedVec, - // }, - #[codec(index = 22)] - ApproveItemAttribute { - collection: CollectionId, - item: ItemId, - delegate: MultiAddress, - }, - #[codec(index = 23)] - CancelItemAttributesApproval { - collection: CollectionId, - item: ItemId, - delegate: MultiAddress, - }, - #[codec(index = 24)] - SetMetadata { - collection: CollectionId, - item: ItemId, - data: BoundedVec, - }, - #[codec(index = 25)] - ClearMetadata { - collection: CollectionId, - item: ItemId, - }, - #[codec(index = 26)] - SetCollectionMetadata { - collection: CollectionId, - data: BoundedVec, - }, - #[codec(index = 27)] - ClearCollectionMetadata { collection: CollectionId }, - #[codec(index = 28)] - SetAcceptOwnership { - collection: CollectionId, - maybe_collection: Option, - }, - #[codec(index = 29)] - SetCollectionMaxSupply { - collection: CollectionId, - max_supply: u32, - }, - // #[codec(index = 30)] - // UpdateMintSettings { - // collection: CollectionId, - // mint_settings: MintSettings, - // }, - #[codec(index = 31)] - Price { - collection: CollectionId, - item: ItemId, - price: Option, - }, - #[codec(index = 32)] - BuyItem { - collection: CollectionId, - item: ItemId, - bid_price: Balance, - }, - // #[codec(index = 33)] - // PayTips { - // tips: BoundedVec, MaxTips> - // }, - // #[codec(index = 34)] - // CreateSwap { - // offered_collection: CollectionId, - // offered_item: ItemId, - // desired_collection: CollectionId, - // maybe_desired_item: Option, - // maybe_price: Option>, - // duration: BlockNumber, - // }, - #[codec(index = 35)] - CancelSwap { - offered_collection: CollectionId, - offered_item: ItemId, - }, - #[codec(index = 36)] - ClaimSwap { - send_collection: CollectionId, - send_item: ItemId, - receive_collection: CollectionId, - receive_item: ItemId, - }, - // #[codec(index = 37)] - // MintPreSigned { - // mint_data: PreSignedMint, - // signature: OffchainSignature, - // signer: AccountId - // }, - // #[codec(index = 38)] - // SetAttributesPreSigned { - // data: PreSignedAttributes, - // signature: OffchainSignature, - // signer: AccountId, - // } + // #[codec(index = 0)] + // Create { + // admin: MultiAddress, + // config: CollectionConfig + // }, + #[codec(index = 2)] + Destroy { collection: CollectionId }, + #[codec(index = 3)] + Mint { + collection: CollectionId, + item: ItemId, + mint_to: MultiAddress, + witness_data: Option<()>, + }, + #[codec(index = 5)] + Burn { collection: CollectionId, item: ItemId }, + #[codec(index = 6)] + Transfer { collection: CollectionId, item: ItemId, dest: MultiAddress }, + #[codec(index = 7)] + Redeposit { collection: CollectionId, items: Vec }, + #[codec(index = 8)] + LockItemTransfer { collection: CollectionId, item: ItemId }, + #[codec(index = 9)] + UnlockItemTransfer { collection: CollectionId, item: ItemId }, + // #[codec(index = 10)] + // LockCollection { + // collection: CollectionId, + // lock_settings: CollectionSettings, + // }, + #[codec(index = 11)] + TransferOwnership { collection: CollectionId, new_owner: MultiAddress }, + #[codec(index = 12)] + SetTeam { + collection: CollectionId, + issuer: Option>, + admin: Option>, + freezer: Option>, + }, + #[codec(index = 15)] + ApproveTransfer { + collection: CollectionId, + item: ItemId, + delegate: MultiAddress, + maybe_deadline: Option, + }, + #[codec(index = 16)] + CancelApproval { collection: CollectionId, item: ItemId, delegate: MultiAddress }, + #[codec(index = 17)] + ClearAllTransferApprovals { collection: CollectionId, item: ItemId }, + #[codec(index = 18)] + LockItemProperties { + collection: CollectionId, + item: ItemId, + lock_metadata: bool, + lock_attributes: bool, + }, + // #[codec(index = 19)] + // SetAttribute { + // collection: CollectionId, + // maybe_item: Option, + // namespace: AttributeNamespace, + // key: BoundedVec, + // value: BoundedVec, + // }, + // #[codec(index = 21)] + // ClearAttribute { + // collection: CollectionId, + // maybe_item: Option, + // namespace: AttributeNamespace, + // key: BoundedVec, + // }, + #[codec(index = 22)] + ApproveItemAttribute { + collection: CollectionId, + item: ItemId, + delegate: MultiAddress, + }, + #[codec(index = 23)] + CancelItemAttributesApproval { + collection: CollectionId, + item: ItemId, + delegate: MultiAddress, + }, + #[codec(index = 24)] + SetMetadata { collection: CollectionId, item: ItemId, data: BoundedVec }, + #[codec(index = 25)] + ClearMetadata { collection: CollectionId, item: ItemId }, + #[codec(index = 26)] + SetCollectionMetadata { collection: CollectionId, data: BoundedVec }, + #[codec(index = 27)] + ClearCollectionMetadata { collection: CollectionId }, + #[codec(index = 28)] + SetAcceptOwnership { collection: CollectionId, maybe_collection: Option }, + #[codec(index = 29)] + SetCollectionMaxSupply { collection: CollectionId, max_supply: u32 }, + // #[codec(index = 30)] + // UpdateMintSettings { + // collection: CollectionId, + // mint_settings: MintSettings, + // }, + #[codec(index = 31)] + Price { collection: CollectionId, item: ItemId, price: Option }, + #[codec(index = 32)] + BuyItem { collection: CollectionId, item: ItemId, bid_price: Balance }, + // #[codec(index = 33)] + // PayTips { + // tips: BoundedVec, MaxTips> + // }, + // #[codec(index = 34)] + // CreateSwap { + // offered_collection: CollectionId, + // offered_item: ItemId, + // desired_collection: CollectionId, + // maybe_desired_item: Option, + // maybe_price: Option>, + // duration: BlockNumber, + // }, + #[codec(index = 35)] + CancelSwap { offered_collection: CollectionId, offered_item: ItemId }, + #[codec(index = 36)] + ClaimSwap { + send_collection: CollectionId, + send_item: ItemId, + receive_collection: CollectionId, + receive_item: ItemId, + }, + // #[codec(index = 37)] + // MintPreSigned { + // mint_data: PreSignedMint, + // signature: OffchainSignature, + // signer: AccountId + // }, + // #[codec(index = 38)] + // SetAttributesPreSigned { + // data: PreSignedAttributes, + // signature: OffchainSignature, + // signer: AccountId, + // } } #[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum Error { - /// The signing account has no permission to do the operation. - NoPermission, - /// The given item ID is unknown. - UnknownCollection, - /// The item ID has already been used for an item. - AlreadyExists, - /// The approval had a deadline that expired, so the approval isn't valid anymore. - ApprovalExpired, - /// The owner turned out to be different to what was expected. - WrongOwner, - /// The witness data given does not match the current state of the chain. - BadWitness, - /// Collection ID is already taken. - CollectionIdInUse, - /// Items within that collection are non-transferable. - ItemsNonTransferable, - /// The provided account is not a delegate. - NotDelegate, - /// The delegate turned out to be different to what was expected. - WrongDelegate, - /// No approval exists that would allow the transfer. - Unapproved, - /// The named owner has not signed ownership acceptance of the collection. - Unaccepted, - /// The item is locked (non-transferable). - ItemLocked, - /// Item's attributes are locked. - LockedItemAttributes, - /// Collection's attributes are locked. - LockedCollectionAttributes, - /// Item's metadata is locked. - LockedItemMetadata, - /// Collection's metadata is locked. - LockedCollectionMetadata, - /// All items have been minted. - MaxSupplyReached, - /// The max supply is locked and can't be changed. - MaxSupplyLocked, - /// The provided max supply is less than the number of items a collection already has. - MaxSupplyTooSmall, - /// The given item ID is unknown. - UnknownItem, - /// Swap doesn't exist. - UnknownSwap, - /// The given item has no metadata set. - MetadataNotFound, - /// The provided attribute can't be found. - AttributeNotFound, - /// Item is not for sale. - NotForSale, - /// The provided bid is too low. - BidTooLow, - /// The item has reached its approval limit. - ReachedApprovalLimit, - /// The deadline has already expired. - DeadlineExpired, - /// The duration provided should be less than or equal to `MaxDeadlineDuration`. - WrongDuration, - /// The method is disabled by system settings. - MethodDisabled, - /// The provided setting can't be set. - WrongSetting, - /// Item's config already exists and should be equal to the provided one. - InconsistentItemConfig, - /// Config for a collection or an item can't be found. - NoConfig, - /// Some roles were not cleared. - RolesNotCleared, - /// Mint has not started yet. - MintNotStarted, - /// Mint has already ended. - MintEnded, - /// The provided Item was already used for claiming. - AlreadyClaimed, - /// The provided data is incorrect. - IncorrectData, - /// The extrinsic was sent by the wrong origin. - WrongOrigin, - /// The provided signature is incorrect. - WrongSignature, - /// The provided metadata might be too long. - IncorrectMetadata, - /// Can't set more attributes per one call. - MaxAttributesLimitReached, - /// The provided namespace isn't supported in this call. - WrongNamespace, - /// Can't delete non-empty collections. - CollectionNotEmpty, - /// The witness data should be provided. - WitnessRequired, + /// The signing account has no permission to do the operation. + NoPermission, + /// The given item ID is unknown. + UnknownCollection, + /// The item ID has already been used for an item. + AlreadyExists, + /// The approval had a deadline that expired, so the approval isn't valid anymore. + ApprovalExpired, + /// The owner turned out to be different to what was expected. + WrongOwner, + /// The witness data given does not match the current state of the chain. + BadWitness, + /// Collection ID is already taken. + CollectionIdInUse, + /// Items within that collection are non-transferable. + ItemsNonTransferable, + /// The provided account is not a delegate. + NotDelegate, + /// The delegate turned out to be different to what was expected. + WrongDelegate, + /// No approval exists that would allow the transfer. + Unapproved, + /// The named owner has not signed ownership acceptance of the collection. + Unaccepted, + /// The item is locked (non-transferable). + ItemLocked, + /// Item's attributes are locked. + LockedItemAttributes, + /// Collection's attributes are locked. + LockedCollectionAttributes, + /// Item's metadata is locked. + LockedItemMetadata, + /// Collection's metadata is locked. + LockedCollectionMetadata, + /// All items have been minted. + MaxSupplyReached, + /// The max supply is locked and can't be changed. + MaxSupplyLocked, + /// The provided max supply is less than the number of items a collection already has. + MaxSupplyTooSmall, + /// The given item ID is unknown. + UnknownItem, + /// Swap doesn't exist. + UnknownSwap, + /// The given item has no metadata set. + MetadataNotFound, + /// The provided attribute can't be found. + AttributeNotFound, + /// Item is not for sale. + NotForSale, + /// The provided bid is too low. + BidTooLow, + /// The item has reached its approval limit. + ReachedApprovalLimit, + /// The deadline has already expired. + DeadlineExpired, + /// The duration provided should be less than or equal to `MaxDeadlineDuration`. + WrongDuration, + /// The method is disabled by system settings. + MethodDisabled, + /// The provided setting can't be set. + WrongSetting, + /// Item's config already exists and should be equal to the provided one. + InconsistentItemConfig, + /// Config for a collection or an item can't be found. + NoConfig, + /// Some roles were not cleared. + RolesNotCleared, + /// Mint has not started yet. + MintNotStarted, + /// Mint has already ended. + MintEnded, + /// The provided Item was already used for claiming. + AlreadyClaimed, + /// The provided data is incorrect. + IncorrectData, + /// The extrinsic was sent by the wrong origin. + WrongOrigin, + /// The provided signature is incorrect. + WrongSignature, + /// The provided metadata might be too long. + IncorrectMetadata, + /// Can't set more attributes per one call. + MaxAttributesLimitReached, + /// The provided namespace isn't supported in this call. + WrongNamespace, + /// Can't delete non-empty collections. + CollectionNotEmpty, + /// The witness data should be provided. + WitnessRequired, } impl TryFrom for Error { - type Error = PopApiError; + type Error = PopApiError; - fn try_from(status_code: u32) -> core::result::Result { - use Error::*; - match status_code { - 0 => Ok(NoPermission), - 1 => Ok(UnknownCollection), - 2 => Ok(AlreadyExists), - 3 => Ok(ApprovalExpired), - 4 => Ok(WrongOwner), - 5 => Ok(BadWitness), - 6 => Ok(CollectionIdInUse), - 7 => Ok(ItemsNonTransferable), - 8 => Ok(NotDelegate), - 9 => Ok(WrongDelegate), - 10 => Ok(Unapproved), - 11 => Ok(Unaccepted), - 12 => Ok(ItemLocked), - 13 => Ok(LockedItemAttributes), - 14 => Ok(LockedCollectionAttributes), - 15 => Ok(LockedItemMetadata), - 16 => Ok(LockedCollectionMetadata), - 17 => Ok(MaxSupplyReached), - 18 => Ok(MaxSupplyLocked), - 19 => Ok(MaxSupplyTooSmall), - 20 => Ok(UnknownItem), - 21 => Ok(UnknownSwap), - 22 => Ok(MetadataNotFound), - 23 => Ok(AttributeNotFound), - 24 => Ok(NotForSale), - 25 => Ok(BidTooLow), - 26 => Ok(ReachedApprovalLimit), - 27 => Ok(DeadlineExpired), - 28 => Ok(WrongDuration), - 29 => Ok(MethodDisabled), - 30 => Ok(WrongSetting), - 31 => Ok(InconsistentItemConfig), - 32 => Ok(NoConfig), - 33 => Ok(RolesNotCleared), - 34 => Ok(MintNotStarted), - 35 => Ok(MintEnded), - 36 => Ok(AlreadyClaimed), - 37 => Ok(IncorrectData), - 38 => Ok(WrongOrigin), - 39 => Ok(WrongSignature), - 40 => Ok(IncorrectMetadata), - 41 => Ok(MaxAttributesLimitReached), - 42 => Ok(WrongNamespace), - 43 => Ok(CollectionNotEmpty), - 44 => Ok(WitnessRequired), - _ => Err(UnknownStatusCode(status_code)), - } - } + fn try_from(status_code: u32) -> core::result::Result { + use Error::*; + match status_code { + 0 => Ok(NoPermission), + 1 => Ok(UnknownCollection), + 2 => Ok(AlreadyExists), + 3 => Ok(ApprovalExpired), + 4 => Ok(WrongOwner), + 5 => Ok(BadWitness), + 6 => Ok(CollectionIdInUse), + 7 => Ok(ItemsNonTransferable), + 8 => Ok(NotDelegate), + 9 => Ok(WrongDelegate), + 10 => Ok(Unapproved), + 11 => Ok(Unaccepted), + 12 => Ok(ItemLocked), + 13 => Ok(LockedItemAttributes), + 14 => Ok(LockedCollectionAttributes), + 15 => Ok(LockedItemMetadata), + 16 => Ok(LockedCollectionMetadata), + 17 => Ok(MaxSupplyReached), + 18 => Ok(MaxSupplyLocked), + 19 => Ok(MaxSupplyTooSmall), + 20 => Ok(UnknownItem), + 21 => Ok(UnknownSwap), + 22 => Ok(MetadataNotFound), + 23 => Ok(AttributeNotFound), + 24 => Ok(NotForSale), + 25 => Ok(BidTooLow), + 26 => Ok(ReachedApprovalLimit), + 27 => Ok(DeadlineExpired), + 28 => Ok(WrongDuration), + 29 => Ok(MethodDisabled), + 30 => Ok(WrongSetting), + 31 => Ok(InconsistentItemConfig), + 32 => Ok(NoConfig), + 33 => Ok(RolesNotCleared), + 34 => Ok(MintNotStarted), + 35 => Ok(MintEnded), + 36 => Ok(AlreadyClaimed), + 37 => Ok(IncorrectData), + 38 => Ok(WrongOrigin), + 39 => Ok(WrongSignature), + 40 => Ok(IncorrectMetadata), + 41 => Ok(MaxAttributesLimitReached), + 42 => Ok(WrongNamespace), + 43 => Ok(CollectionNotEmpty), + 44 => Ok(WitnessRequired), + _ => Err(UnknownStatusCode(status_code)), + } + } } impl From for Error { - fn from(error: PopApiError) -> Self { - match error { - PopApiError::Nfts(e) => e, - _ => panic!("expected nfts error"), - } - } + fn from(error: PopApiError) -> Self { + match error { + PopApiError::Nfts(e) => e, + _ => panic!("expected nfts error"), + } + } } diff --git a/pop-api/src/v0/state.rs b/pop-api/src/v0/state.rs index 78aa1700..9f5e4c0c 100644 --- a/pop-api/src/v0/state.rs +++ b/pop-api/src/v0/state.rs @@ -2,5 +2,5 @@ use crate::{primitives::storage_keys::RuntimeStateKeys, read_state, PopApiError} use scale::Decode; pub fn read(key: RuntimeStateKeys) -> crate::Result { - read_state(key).and_then(|v| T::decode(&mut &v[..]).map_err(|_e| PopApiError::DecodingFailed)) + read_state(key).and_then(|v| T::decode(&mut &v[..]).map_err(|_e| PopApiError::DecodingFailed)) } diff --git a/runtime/src/contracts_config.rs b/runtime/src/contracts_config.rs index ea8aa661..36d62f7f 100644 --- a/runtime/src/contracts_config.rs +++ b/runtime/src/contracts_config.rs @@ -1,6 +1,6 @@ use crate::{ - deposit, extensions, Balance, Balances, BalancesCall, Perbill, Runtime, RuntimeCall, RuntimeEvent, - RuntimeHoldReason, Timestamp, + deposit, extensions, Balance, Balances, BalancesCall, Perbill, Runtime, RuntimeCall, + RuntimeEvent, RuntimeHoldReason, Timestamp, }; use frame_support::{ parameter_types, diff --git a/runtime/src/extensions.rs b/runtime/src/extensions.rs index ae0081ae..a11ab181 100644 --- a/runtime/src/extensions.rs +++ b/runtime/src/extensions.rs @@ -1,11 +1,11 @@ use cumulus_primitives_core::relay_chain::BlockNumber; use frame_support::{ - dispatch::{GetDispatchInfo, PostDispatchInfo, RawOrigin}, - pallet_prelude::*, + dispatch::{GetDispatchInfo, PostDispatchInfo, RawOrigin}, + pallet_prelude::*, }; use log; use pallet_contracts::chain_extension::{ - ChainExtension, Environment, Ext, InitState, RetVal, SysConfig, + ChainExtension, Environment, Ext, InitState, RetVal, SysConfig, }; use pop_api_primitives::storage_keys::ParachainSystemKeys; use sp_core::crypto::UncheckedFrom; @@ -18,220 +18,220 @@ pub struct PopApiExtension; impl ChainExtension for PopApiExtension where - T: pallet_contracts::Config + cumulus_pallet_parachain_system::Config, - ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, - ::RuntimeCall: Parameter - + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> - + GetDispatchInfo - + From>, + T: pallet_contracts::Config + cumulus_pallet_parachain_system::Config, + ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, + ::RuntimeCall: Parameter + + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> + + GetDispatchInfo + + From>, { - fn call(&mut self, env: Environment) -> Result - where - E: Ext, - ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, - { - log::debug!(target:LOG_TARGET, " extension called "); - match v0::FuncId::try_from(env.func_id())? { - v0::FuncId::Dispatch => { - match dispatch::(env) { - Ok(()) => Ok(RetVal::Converging(0)), - Err(DispatchError::Module(error)) => { - // encode status code = pallet index in runtime + error index, allowing for 999 errors - Ok(RetVal::Converging( - (error.index as u32 * 1_000) + u32::from_le_bytes(error.error), - )) - } - Err(e) => Err(e), - } - } - v0::FuncId::ReadState => { - read_state::(env)?; - Ok(RetVal::Converging(0)) - } - } - } + fn call(&mut self, env: Environment) -> Result + where + E: Ext, + ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, + { + log::debug!(target:LOG_TARGET, " extension called "); + match v0::FuncId::try_from(env.func_id())? { + v0::FuncId::Dispatch => { + match dispatch::(env) { + Ok(()) => Ok(RetVal::Converging(0)), + Err(DispatchError::Module(error)) => { + // encode status code = pallet index in runtime + error index, allowing for 999 errors + Ok(RetVal::Converging( + (error.index as u32 * 1_000) + u32::from_le_bytes(error.error), + )) + }, + Err(e) => Err(e), + } + }, + v0::FuncId::ReadState => { + read_state::(env)?; + Ok(RetVal::Converging(0)) + }, + } + } } pub mod v0 { - #[derive(Debug)] - pub enum FuncId { - Dispatch, - ReadState, - } + #[derive(Debug)] + pub enum FuncId { + Dispatch, + ReadState, + } } impl TryFrom for v0::FuncId { - type Error = DispatchError; - - fn try_from(func_id: u16) -> Result { - let id = match func_id { - 0x0 => Self::Dispatch, - 0x1 => Self::ReadState, - _ => { - log::error!("called an unregistered `func_id`: {:}", func_id); - return Err(DispatchError::Other("unimplemented func_id")); - } - }; - - Ok(id) - } + type Error = DispatchError; + + fn try_from(func_id: u16) -> Result { + let id = match func_id { + 0x0 => Self::Dispatch, + 0x1 => Self::ReadState, + _ => { + log::error!("called an unregistered `func_id`: {:}", func_id); + return Err(DispatchError::Other("unimplemented func_id")); + }, + }; + + Ok(id) + } } pub(crate) fn dispatch(env: Environment) -> Result<(), DispatchError> where - T: pallet_contracts::Config + frame_system::Config, - ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, - ::RuntimeCall: Parameter - + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> - + GetDispatchInfo - + From>, - E: Ext, + T: pallet_contracts::Config + frame_system::Config, + ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, + ::RuntimeCall: Parameter + + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> + + GetDispatchInfo + + From>, + E: Ext, { - const LOG_TARGET: &str = "pop-api::extension::dispatch"; - - let mut env = env.buf_in_buf_out(); - - // charge max weight before reading contract memory - // TODO: causing "1010: block limits exhausted" error - // let weight_limit = env.ext().gas_meter().gas_left(); - // let charged_weight = env.charge_weight(weight_limit)?; - - // TODO: debug_message weight is a good approximation of the additional overhead of going - // from contract layer to substrate layer. - - // input length - let len = env.in_len(); - let call: ::RuntimeCall = env.read_as_unbounded(len)?; - - // conservative weight estimate for deserializing the input. The actual weight is less and should utilize a custom benchmark - let base_weight: Weight = T::DbWeight::get().reads(len.into()); - - // weight for dispatching the call - let dispatch_weight = call.get_dispatch_info().weight; - - // charge weight for the cost of the deserialization and the dispatch - let _ = env.charge_weight(base_weight.saturating_add(dispatch_weight))?; - - log::debug!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); - - let sender = env.ext().caller(); - let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); - - // TODO: uncomment once charged_weight is fixed - // let actual_weight = call.get_dispatch_info().weight; - // env.adjust_weight(charged_weight, actual_weight); - let result = call.dispatch(origin); - match result { - Ok(info) => { - log::debug!(target:LOG_TARGET, "dispatch success, actual weight: {:?}", info.actual_weight); - } - Err(err) => { - log::debug!(target:LOG_TARGET, "dispatch failed: error: {:?}", err.error); - return Err(err.error); - } - } - Ok(()) + const LOG_TARGET: &str = "pop-api::extension::dispatch"; + + let mut env = env.buf_in_buf_out(); + + // charge max weight before reading contract memory + // TODO: causing "1010: block limits exhausted" error + // let weight_limit = env.ext().gas_meter().gas_left(); + // let charged_weight = env.charge_weight(weight_limit)?; + + // TODO: debug_message weight is a good approximation of the additional overhead of going + // from contract layer to substrate layer. + + // input length + let len = env.in_len(); + let call: ::RuntimeCall = env.read_as_unbounded(len)?; + + // conservative weight estimate for deserializing the input. The actual weight is less and should utilize a custom benchmark + let base_weight: Weight = T::DbWeight::get().reads(len.into()); + + // weight for dispatching the call + let dispatch_weight = call.get_dispatch_info().weight; + + // charge weight for the cost of the deserialization and the dispatch + let _ = env.charge_weight(base_weight.saturating_add(dispatch_weight))?; + + log::debug!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); + + let sender = env.ext().caller(); + let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); + + // TODO: uncomment once charged_weight is fixed + // let actual_weight = call.get_dispatch_info().weight; + // env.adjust_weight(charged_weight, actual_weight); + let result = call.dispatch(origin); + match result { + Ok(info) => { + log::debug!(target:LOG_TARGET, "dispatch success, actual weight: {:?}", info.actual_weight); + }, + Err(err) => { + log::debug!(target:LOG_TARGET, "dispatch failed: error: {:?}", err.error); + return Err(err.error); + }, + } + Ok(()) } pub(crate) fn read_state(env: Environment) -> Result<(), DispatchError> where - T: pallet_contracts::Config + frame_system::Config, - E: Ext, + T: pallet_contracts::Config + frame_system::Config, + E: Ext, { - const LOG_TARGET: &str = "pop-api::extension::read_state"; - - let mut env = env.buf_in_buf_out(); - - // TODO: Substitute len u32 with pop_api::src::impls::pop_network::StringLimit. - // Move StringLimit to pop_api_primitives first. - let len: u32 = env.in_len(); - let key: ParachainSystemKeys = env.read_as_unbounded(len)?; - - let result = match key { - ParachainSystemKeys::LastRelayChainBlockNumber => { - let relay_block_num: BlockNumber = crate::ParachainSystem::last_relay_block_number(); - log::debug!( - target:LOG_TARGET, - "last relay chain block number is: {:?}.", relay_block_num - ); - relay_block_num - } - } - .encode(); - env.write(&result, false, None).map_err(|e| { - log::trace!(target: LOG_TARGET, "{:?}", e); - DispatchError::Other("unable to write results to contract memory") - }) + const LOG_TARGET: &str = "pop-api::extension::read_state"; + + let mut env = env.buf_in_buf_out(); + + // TODO: Substitute len u32 with pop_api::src::impls::pop_network::StringLimit. + // Move StringLimit to pop_api_primitives first. + let len: u32 = env.in_len(); + let key: ParachainSystemKeys = env.read_as_unbounded(len)?; + + let result = match key { + ParachainSystemKeys::LastRelayChainBlockNumber => { + let relay_block_num: BlockNumber = crate::ParachainSystem::last_relay_block_number(); + log::debug!( + target:LOG_TARGET, + "last relay chain block number is: {:?}.", relay_block_num + ); + relay_block_num + }, + } + .encode(); + env.write(&result, false, None).map_err(|e| { + log::trace!(target: LOG_TARGET, "{:?}", e); + DispatchError::Other("unable to write results to contract memory") + }) } #[cfg(test)] mod tests { - pub use super::*; - pub use crate::*; - use enumflags2::BitFlags; - pub use pallet_contracts::Code; - use pallet_nfts::{CollectionConfig, CollectionSetting, CollectionSettings, MintSettings}; - use parachains_common::CollectionId; - pub use sp_runtime::{traits::Hash, AccountId32}; - - pub const DEBUG_OUTPUT: pallet_contracts::DebugInfo = pallet_contracts::DebugInfo::UnsafeDebug; - - pub const ALICE: AccountId32 = AccountId32::new([1_u8; 32]); - pub const BOB: AccountId32 = AccountId32::new([2_u8; 32]); - pub const INITIAL_AMOUNT: u128 = 100_000 * UNIT; - pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000, 3 * 1024 * 1024); - - pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::::default() - .build_storage() - .expect("Frame system builds valid default genesis config"); - - pallet_balances::GenesisConfig:: { - balances: vec![(ALICE, INITIAL_AMOUNT), (BOB, INITIAL_AMOUNT)], - } - .assimilate_storage(&mut t) - .expect("Pallet balances storage can be assimilated"); - - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext - } - - pub fn load_wasm_module( - path: &str, - ) -> std::io::Result<(Vec, ::Output)> - where - T: frame_system::Config, - { - let wasm_binary = std::fs::read(path)?; - let code_hash = T::Hashing::hash(&wasm_binary); - Ok((wasm_binary, code_hash)) - } - - pub fn function_selector(name: &str) -> Vec { - let hash = sp_io::hashing::blake2_256(name.as_bytes()); - [hash[0..4].to_vec()].concat() - } - - // NFT helper functions - fn collection_config_from_disabled_settings( - settings: BitFlags, - ) -> CollectionConfig { - CollectionConfig { - settings: CollectionSettings::from_disabled(settings), - max_supply: None, - mint_settings: MintSettings::default(), - } - } - - fn default_collection_config() -> CollectionConfig { - collection_config_from_disabled_settings(CollectionSetting::DepositRequired.into()) - } - - #[test] - #[ignore] - fn dispatch_balance_transfer_from_contract_works() { - new_test_ext().execute_with(|| { + pub use super::*; + pub use crate::*; + use enumflags2::BitFlags; + pub use pallet_contracts::Code; + use pallet_nfts::{CollectionConfig, CollectionSetting, CollectionSettings, MintSettings}; + use parachains_common::CollectionId; + pub use sp_runtime::{traits::Hash, AccountId32}; + + pub const DEBUG_OUTPUT: pallet_contracts::DebugInfo = pallet_contracts::DebugInfo::UnsafeDebug; + + pub const ALICE: AccountId32 = AccountId32::new([1_u8; 32]); + pub const BOB: AccountId32 = AccountId32::new([2_u8; 32]); + pub const INITIAL_AMOUNT: u128 = 100_000 * UNIT; + pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000, 3 * 1024 * 1024); + + pub fn new_test_ext() -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .expect("Frame system builds valid default genesis config"); + + pallet_balances::GenesisConfig:: { + balances: vec![(ALICE, INITIAL_AMOUNT), (BOB, INITIAL_AMOUNT)], + } + .assimilate_storage(&mut t) + .expect("Pallet balances storage can be assimilated"); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext + } + + pub fn load_wasm_module( + path: &str, + ) -> std::io::Result<(Vec, ::Output)> + where + T: frame_system::Config, + { + let wasm_binary = std::fs::read(path)?; + let code_hash = T::Hashing::hash(&wasm_binary); + Ok((wasm_binary, code_hash)) + } + + pub fn function_selector(name: &str) -> Vec { + let hash = sp_io::hashing::blake2_256(name.as_bytes()); + [hash[0..4].to_vec()].concat() + } + + // NFT helper functions + fn collection_config_from_disabled_settings( + settings: BitFlags, + ) -> CollectionConfig { + CollectionConfig { + settings: CollectionSettings::from_disabled(settings), + max_supply: None, + mint_settings: MintSettings::default(), + } + } + + fn default_collection_config() -> CollectionConfig { + collection_config_from_disabled_settings(CollectionSetting::DepositRequired.into()) + } + + #[test] + #[ignore] + fn dispatch_balance_transfer_from_contract_works() { + new_test_ext().execute_with(|| { let _ = env_logger::try_init(); let (wasm_binary, _) = load_wasm_module::("../contracts/pop-api-examples/balance-transfer/target/ink/pop_api_extension_demo.wasm").unwrap(); @@ -293,168 +293,150 @@ mod tests { let bob_balance_after = Balances::free_balance(&BOB); assert_eq!(bob_balance_before + value_to_send, bob_balance_after); }); - } - - #[test] - #[ignore] - fn dispatch_nfts_mint_from_contract_works() { - new_test_ext().execute_with(|| { - let _ = env_logger::try_init(); - - let (wasm_binary, _) = load_wasm_module::( - "../contracts/pop-api-examples/nfts/target/ink/pop_api_nft_example.wasm", - ) - .unwrap(); - - let init_value = 100; - - let result = Contracts::bare_instantiate( - ALICE, - init_value, - GAS_LIMIT, - None, - Code::Upload(wasm_binary), - function_selector("new"), - vec![], - DEBUG_OUTPUT, - pallet_contracts::CollectEvents::Skip, - ) - .result - .unwrap(); - - assert!( - !result.result.did_revert(), - "deploying contract reverted {:?}", - result - ); - - let addr = result.account_id; - - let collection_id: u32 = 0; - let item_id: u32 = 1; - - // create nft collection - assert_eq!( - Nfts::force_create( - RuntimeOrigin::root(), - ALICE.into(), - default_collection_config() - ), - Ok(()) - ); - - assert_eq!(Nfts::collection_owner(collection_id), Some(ALICE.into())); - // assert that the item does not exist yet - assert_eq!(Nfts::owner(collection_id, item_id), None); - - let function = function_selector("mint_through_runtime"); - - let params = [ - function, - collection_id.encode(), - item_id.encode(), - BOB.encode(), - ] - .concat(); - - let result = Contracts::bare_call( - ALICE, - addr.clone(), - 0, - Weight::from_parts(100_000_000_000, 3 * 1024 * 1024), - None, - params, - DEBUG_OUTPUT, - pallet_contracts::CollectEvents::Skip, - pallet_contracts::Determinism::Enforced, - ); - - if DEBUG_OUTPUT == pallet_contracts::DebugInfo::UnsafeDebug { - log::debug!( - "Contract debug buffer - {:?}", - String::from_utf8(result.debug_message.clone()) - ); - log::debug!("result: {:?}", result); - } - - // check for revert - assert!(!result.result.unwrap().did_revert(), "Contract reverted!"); - - assert_eq!(Nfts::owner(collection_id, item_id), Some(BOB.into())); - }); - } - - #[test] - #[ignore] - fn nfts_mint_surfaces_error() { - new_test_ext().execute_with(|| { - let _ = env_logger::try_init(); - - let (wasm_binary, _) = load_wasm_module::( - "../contracts/pop-api-examples/nfts/target/ink/pop_api_nft_example.wasm", - ) - .unwrap(); - - let init_value = 100; - - let result = Contracts::bare_instantiate( - ALICE, - init_value, - GAS_LIMIT, - None, - Code::Upload(wasm_binary), - function_selector("new"), - vec![], - DEBUG_OUTPUT, - pallet_contracts::CollectEvents::Skip, - ) - .result - .unwrap(); - - assert!( - !result.result.did_revert(), - "deploying contract reverted {:?}", - result - ); - - let addr = result.account_id; - - let collection_id: u32 = 0; - let item_id: u32 = 1; - - let function = function_selector("mint_through_runtime"); - - let params = [ - function, - collection_id.encode(), - item_id.encode(), - BOB.encode(), - ] - .concat(); - - let result = Contracts::bare_call( - ALICE, - addr.clone(), - 0, - Weight::from_parts(100_000_000_000, 3 * 1024 * 1024), - None, - params, - DEBUG_OUTPUT, - pallet_contracts::CollectEvents::Skip, - pallet_contracts::Determinism::Enforced, - ); - - if DEBUG_OUTPUT == pallet_contracts::DebugInfo::UnsafeDebug { - log::debug!( - "Contract debug buffer - {:?}", - String::from_utf8(result.debug_message.clone()) - ); - log::debug!("result: {:?}", result); - } - - // check for revert with expected error - let result = result.result.unwrap(); - assert!(result.did_revert()); - }); - } + } + + #[test] + #[ignore] + fn dispatch_nfts_mint_from_contract_works() { + new_test_ext().execute_with(|| { + let _ = env_logger::try_init(); + + let (wasm_binary, _) = load_wasm_module::( + "../contracts/pop-api-examples/nfts/target/ink/pop_api_nft_example.wasm", + ) + .unwrap(); + + let init_value = 100; + + let result = Contracts::bare_instantiate( + ALICE, + init_value, + GAS_LIMIT, + None, + Code::Upload(wasm_binary), + function_selector("new"), + vec![], + DEBUG_OUTPUT, + pallet_contracts::CollectEvents::Skip, + ) + .result + .unwrap(); + + assert!(!result.result.did_revert(), "deploying contract reverted {:?}", result); + + let addr = result.account_id; + + let collection_id: u32 = 0; + let item_id: u32 = 1; + + // create nft collection + assert_eq!( + Nfts::force_create( + RuntimeOrigin::root(), + ALICE.into(), + default_collection_config() + ), + Ok(()) + ); + + assert_eq!(Nfts::collection_owner(collection_id), Some(ALICE.into())); + // assert that the item does not exist yet + assert_eq!(Nfts::owner(collection_id, item_id), None); + + let function = function_selector("mint_through_runtime"); + + let params = + [function, collection_id.encode(), item_id.encode(), BOB.encode()].concat(); + + let result = Contracts::bare_call( + ALICE, + addr.clone(), + 0, + Weight::from_parts(100_000_000_000, 3 * 1024 * 1024), + None, + params, + DEBUG_OUTPUT, + pallet_contracts::CollectEvents::Skip, + pallet_contracts::Determinism::Enforced, + ); + + if DEBUG_OUTPUT == pallet_contracts::DebugInfo::UnsafeDebug { + log::debug!( + "Contract debug buffer - {:?}", + String::from_utf8(result.debug_message.clone()) + ); + log::debug!("result: {:?}", result); + } + + // check for revert + assert!(!result.result.unwrap().did_revert(), "Contract reverted!"); + + assert_eq!(Nfts::owner(collection_id, item_id), Some(BOB.into())); + }); + } + + #[test] + #[ignore] + fn nfts_mint_surfaces_error() { + new_test_ext().execute_with(|| { + let _ = env_logger::try_init(); + + let (wasm_binary, _) = load_wasm_module::( + "../contracts/pop-api-examples/nfts/target/ink/pop_api_nft_example.wasm", + ) + .unwrap(); + + let init_value = 100; + + let result = Contracts::bare_instantiate( + ALICE, + init_value, + GAS_LIMIT, + None, + Code::Upload(wasm_binary), + function_selector("new"), + vec![], + DEBUG_OUTPUT, + pallet_contracts::CollectEvents::Skip, + ) + .result + .unwrap(); + + assert!(!result.result.did_revert(), "deploying contract reverted {:?}", result); + + let addr = result.account_id; + + let collection_id: u32 = 0; + let item_id: u32 = 1; + + let function = function_selector("mint_through_runtime"); + + let params = + [function, collection_id.encode(), item_id.encode(), BOB.encode()].concat(); + + let result = Contracts::bare_call( + ALICE, + addr.clone(), + 0, + Weight::from_parts(100_000_000_000, 3 * 1024 * 1024), + None, + params, + DEBUG_OUTPUT, + pallet_contracts::CollectEvents::Skip, + pallet_contracts::Determinism::Enforced, + ); + + if DEBUG_OUTPUT == pallet_contracts::DebugInfo::UnsafeDebug { + log::debug!( + "Contract debug buffer - {:?}", + String::from_utf8(result.debug_message.clone()) + ); + log::debug!("result: {:?}", result); + } + + // check for revert with expected error + let result = result.result.unwrap(); + assert!(result.did_revert()); + }); + } } diff --git a/runtime/src/extensions/ext_impl/dispatch.rs b/runtime/src/extensions/ext_impl/dispatch.rs deleted file mode 100644 index 3a9dc901..00000000 --- a/runtime/src/extensions/ext_impl/dispatch.rs +++ /dev/null @@ -1,53 +0,0 @@ -use frame_support::{ - dispatch::{GetDispatchInfo, PostDispatchInfo, RawOrigin}, - pallet_prelude::*, -}; -use log; -use pallet_contracts::chain_extension::{Environment, Ext, InitState, SysConfig}; -use sp_core::crypto::UncheckedFrom; -use sp_runtime::{traits::Dispatchable, DispatchError}; - -const LOG_TARGET: &str = "popapi::extension::dispatch"; - -pub(crate) fn dispatch(env: Environment) -> Result<(), DispatchError> -where - T: pallet_contracts::Config + frame_system::Config, - ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, - ::RuntimeCall: Parameter - + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> - + GetDispatchInfo - + From>, - E: Ext, -{ - let mut env = env.buf_in_buf_out(); - - // input length - let len = env.in_len(); - let call: ::RuntimeCall = env.read_as_unbounded(len)?; - - // conservative weight estimate for deserializing the input. The actual weight is less and should utilize a custom benchmark - let base_weight: Weight = T::DbWeight::get().reads(len.into()); - - // weight for dispatching the call - let dispatch_weight = call.get_dispatch_info().weight; - - // charge weight for the cost of the deserialization and the dispatch - let _ = env.charge_weight(base_weight.saturating_add(dispatch_weight))?; - - log::debug!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); - - let sender = env.ext().caller(); - let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); - - let result = call.dispatch(origin); - match result { - Ok(info) => { - log::debug!(target:LOG_TARGET, "dispatch success, actual weight: {:?}", info.actual_weight); - } - Err(err) => { - log::debug!(target:LOG_TARGET, "dispatch failed: error: {:?}", err.error); - return Err(err.error); - } - } - Ok(()) -} diff --git a/runtime/src/extensions/ext_impl/mod.rs b/runtime/src/extensions/ext_impl/mod.rs deleted file mode 100644 index 2389a49b..00000000 --- a/runtime/src/extensions/ext_impl/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod dispatch; -pub mod read_state; diff --git a/runtime/src/extensions/ext_impl/read_state.rs b/runtime/src/extensions/ext_impl/read_state.rs deleted file mode 100644 index 1281810f..00000000 --- a/runtime/src/extensions/ext_impl/read_state.rs +++ /dev/null @@ -1,33 +0,0 @@ -use codec::Decode; -use cumulus_primitives_core::relay_chain::BlockNumber; -use frame_support::pallet_prelude::*; -use log; -use pallet_contracts::chain_extension::{Environment, Ext, InitState}; -use pop_api_primitives::storage_keys::ParachainSystemKeys; - -const LOG_TARGET: &str = "popapi::extension::read_state"; - -pub(crate) fn read_state(env: Environment) -> Result<(), DispatchError> -where - T: pallet_contracts::Config + frame_system::Config, - E: Ext, -{ - let mut env = env.buf_in_buf_out(); - // TODO: Substitue len u32 with pop_api::src::impls::pop_network::StringLimit. - // Move StringLimit to pop_api_primitives first. - let len: u32 = env.in_len(); - let key: ParachainSystemKeys = env.read_as_unbounded(len)?; - - match key { - ParachainSystemKeys::LastRelayChainBlockNumber => { - let relay_block_num: BlockNumber = crate::ParachainSystem::last_relay_block_number(); - log::debug!( - target:LOG_TARGET, - "Last Relay Chain Block Number is: {:?}.", relay_block_num - ); - //Ok(relay_block_num) - Ok(()) - } - _ => Err(DispatchError::Other("Unable to read provided key.")), - } -} diff --git a/runtime/src/extensions/mod.rs b/runtime/src/extensions/mod.rs deleted file mode 100644 index 3f110092..00000000 --- a/runtime/src/extensions/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod ext_impl; -pub mod pop_api_extension; diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs deleted file mode 100644 index 9abd359f..00000000 --- a/runtime/src/extensions/pop_api_extension.rs +++ /dev/null @@ -1,297 +0,0 @@ -use frame_support::{ - dispatch::{GetDispatchInfo, PostDispatchInfo}, - pallet_prelude::*, -}; -use log; -use pallet_contracts::chain_extension::{ - ChainExtension, Environment, Ext, InitState, RetVal, SysConfig, -}; -use sp_core::crypto::UncheckedFrom; -use sp_runtime::{traits::Dispatchable, DispatchError}; - -use crate::extensions::ext_impl::{dispatch::dispatch, read_state::read_state}; - -const LOG_TARGET: &str = "popapi::extension"; - -#[derive(Default)] -pub struct PopApiExtension; - -fn convert_err(err_msg: &'static str) -> impl FnOnce(DispatchError) -> DispatchError { - move |err| { - log::trace!( - target: LOG_TARGET, - "Pop API failed:{:?}", - err - ); - DispatchError::Other(err_msg) - } -} - -pub mod v0 { - #[derive(Debug)] - pub enum FuncId { - Dispatch, - ReadState, - } -} - -impl TryFrom for v0::FuncId { - type Error = DispatchError; - - fn try_from(func_id: u16) -> Result { - let id = match func_id { - 0x0 => Self::Dispatch, - 0x1 => Self::ReadState, - _ => { - log::error!("Called an unregistered `func_id`: {:}", func_id); - return Err(DispatchError::Other("Unimplemented func_id")); - } - }; - - Ok(id) - } -} - -impl ChainExtension for PopApiExtension -where - T: pallet_contracts::Config + cumulus_pallet_parachain_system::Config, - ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, - ::RuntimeCall: Parameter - + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> - + GetDispatchInfo - + From>, -{ - fn call(&mut self, env: Environment) -> Result - where - E: Ext, - ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, - { - log::debug!(target:LOG_TARGET, " extension called "); - let func_id = v0::FuncId::try_from(env.func_id())?; - match func_id { - v0::FuncId::Dispatch => dispatch::(env)?, - v0::FuncId::ReadState => read_state::(env)?, - } - - Ok(RetVal::Converging(0)) - } -} - -#[cfg(test)] -mod tests { - pub use super::*; - pub use crate::*; - use enumflags2::BitFlags; - pub use pallet_contracts::Code; - use pallet_nfts::{CollectionConfig, CollectionSetting, CollectionSettings, MintSettings}; - use parachains_common::CollectionId; - pub use sp_runtime::{traits::Hash, AccountId32}; - - pub const DEBUG_OUTPUT: pallet_contracts::DebugInfo = pallet_contracts::DebugInfo::UnsafeDebug; - - pub const ALICE: AccountId32 = AccountId32::new([1_u8; 32]); - pub const BOB: AccountId32 = AccountId32::new([2_u8; 32]); - pub const INITIAL_AMOUNT: u128 = 100_000 * UNIT; - pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000, 3 * 1024 * 1024); - - pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::::default() - .build_storage() - .expect("Frame system builds valid default genesis config"); - - pallet_balances::GenesisConfig:: { - balances: vec![(ALICE, INITIAL_AMOUNT), (BOB, INITIAL_AMOUNT)], - } - .assimilate_storage(&mut t) - .expect("Pallet balances storage can be assimilated"); - - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext - } - - pub fn load_wasm_module( - path: &str, - ) -> std::io::Result<(Vec, ::Output)> - where - T: frame_system::Config, - { - let wasm_binary = std::fs::read(path)?; - let code_hash = T::Hashing::hash(&wasm_binary); - Ok((wasm_binary, code_hash)) - } - - pub fn function_selector(name: &str) -> Vec { - let hash = sp_io::hashing::blake2_256(name.as_bytes()); - [hash[0..4].to_vec()].concat() - } - - // NFT helper functions - fn collection_config_from_disabled_settings( - settings: BitFlags, - ) -> CollectionConfig { - CollectionConfig { - settings: CollectionSettings::from_disabled(settings), - max_supply: None, - mint_settings: MintSettings::default(), - } - } - - fn default_collection_config() -> CollectionConfig { - collection_config_from_disabled_settings(CollectionSetting::DepositRequired.into()) - } - - #[test] - fn test_dispatch() { - new_test_ext().execute_with(|| { - let _ = env_logger::try_init(); - - let (wasm_binary, _) = load_wasm_module::("../contracts/pop-api-examples/balance-transfer/target/ink/pop_api_extension_demo.wasm").unwrap(); - - let init_value = 100; - - let result = Contracts::bare_instantiate( - ALICE, - init_value, - GAS_LIMIT, - None, - Code::Upload(wasm_binary), - function_selector("new"), - vec![], - DEBUG_OUTPUT, - pallet_contracts::CollectEvents::Skip, - ) - .result - .unwrap(); - - assert!( - !result.result.did_revert(), - "deploying contract reverted {:?}", - result - ); - - let addr = result.account_id; - - let function = function_selector("transfer_through_runtime"); - let value_to_send: u128 = 1_000_000_000_000_000; - let params = [function, BOB.encode(), value_to_send.encode()].concat(); - - let bob_balance_before = Balances::free_balance(&BOB); - assert_eq!(bob_balance_before, INITIAL_AMOUNT); - - let result = Contracts::bare_call( - ALICE, - addr.clone(), - 0, - Weight::from_parts(100_000_000_000, 3 * 1024 * 1024), - None, - params, - DEBUG_OUTPUT, - pallet_contracts::CollectEvents::Skip, - pallet_contracts::Determinism::Enforced, - ); - - if DEBUG_OUTPUT == pallet_contracts::DebugInfo::UnsafeDebug { - log::debug!( - "Contract debug buffer - {:?}", - String::from_utf8(result.debug_message.clone()) - ); - log::debug!("result: {:?}", result); - } - - // check for revert - assert!(!result.result.unwrap().did_revert(), "Contract reverted!"); - - let bob_balance_after = Balances::free_balance(&BOB); - assert_eq!(bob_balance_before + value_to_send, bob_balance_after); - }); - } - - #[test] - fn test_nfts_mint() { - new_test_ext().execute_with(|| { - let _ = env_logger::try_init(); - - let (wasm_binary, _) = load_wasm_module::( - "../contracts/pop-api-examples/nfts/target/ink/pop_api_nft_example.wasm", - ) - .unwrap(); - - let init_value = 100; - - let result = Contracts::bare_instantiate( - ALICE, - init_value, - GAS_LIMIT, - None, - Code::Upload(wasm_binary), - function_selector("new"), - vec![], - DEBUG_OUTPUT, - pallet_contracts::CollectEvents::Skip, - ) - .result - .unwrap(); - - assert!( - !result.result.did_revert(), - "deploying contract reverted {:?}", - result - ); - - let addr = result.account_id; - - let collection_id: u32 = 0; - let item_id: u32 = 1; - - // create nft collection - assert_eq!( - Nfts::force_create( - RuntimeOrigin::root(), - ALICE.into(), - default_collection_config() - ), - Ok(()) - ); - - assert_eq!(Nfts::collection_owner(collection_id), Some(ALICE.into())); - // assert that the item does not exist yet - assert_eq!(Nfts::owner(collection_id, item_id), None); - - let function = function_selector("mint_through_runtime"); - - let params = [ - function, - collection_id.encode(), - item_id.encode(), - BOB.encode(), - ] - .concat(); - - let result = Contracts::bare_call( - ALICE, - addr.clone(), - 0, - Weight::from_parts(100_000_000_000, 3 * 1024 * 1024), - None, - params, - DEBUG_OUTPUT, - pallet_contracts::CollectEvents::Skip, - pallet_contracts::Determinism::Enforced, - ); - - if DEBUG_OUTPUT == pallet_contracts::DebugInfo::UnsafeDebug { - log::debug!( - "Contract debug buffer - {:?}", - String::from_utf8(result.debug_message.clone()) - ); - log::debug!("result: {:?}", result); - } - - // check for revert - assert!(!result.result.unwrap().did_revert(), "Contract reverted!"); - - assert_eq!(Nfts::owner(collection_id, item_id), Some(BOB.into())); - }); - } -}