diff --git a/networks/rococo.toml b/networks/rococo.toml index 89314aa1..4f581f5e 100644 --- a/networks/rococo.toml +++ b/networks/rococo.toml @@ -20,3 +20,6 @@ default_command = "./target/release/pop-node" [[parachains.collators]] name = "pop" + command = "./target/release/pop-node" + port = 9944 + args = ["-lruntime::contracts=debug", "-lpopapi::extension=debug"] \ No newline at end of file diff --git a/pop-api/src/impls/mod.rs b/pop-api/src/impls/mod.rs deleted file mode 100644 index 64ac4692..00000000 --- a/pop-api/src/impls/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod pop_network; diff --git a/pop-api/src/impls/pop_network.rs b/pop-api/src/impls/pop_network.rs deleted file mode 100644 index 5c11dbc2..00000000 --- a/pop-api/src/impls/pop_network.rs +++ /dev/null @@ -1,107 +0,0 @@ -use crate::interfaces::nfts::NftCalls; -use ink::prelude::vec::Vec; -use scale; -use sp_runtime::{MultiAddress, MultiSignature}; - -use ink::env::Environment; - -// 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 struct Pop { - pub api: Api, -} - -pub struct Api { - nft: Nfts, -} - -pub type NftCallsOf = NftCalls; - -pub struct Nfts; - -impl Nfts { - // pub fn create(&self, admin: MultiAddress, config: CollectionConfig) -> RuntimeCall { - // RuntimeCall::Nfts(NftCallsOf::Create { admin, config }) - // } - - pub fn mint( - collection: CollectionId, - item: ItemId, - mint_to: impl Into>, - ) -> RuntimeCall { - RuntimeCall::Nfts(NftCallsOf::Mint { - collection, - item, - mint_to: mint_to.into(), - witness_data: None, - }) - } -} - -#[derive(scale::Encode)] -pub enum RuntimeCall { - #[codec(index = 50)] - Nfts(NftCalls), -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] -#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] -pub enum PopApiError { - PlaceholderError, -} - -pub type Result = core::result::Result; - -#[ink::chain_extension] -pub trait PopApi { - type ErrorCode = PopApiError; - - #[ink(extension = 0xfecb)] - 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::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; -} diff --git a/pop-api/src/interfaces/mod.rs b/pop-api/src/interfaces/mod.rs deleted file mode 100644 index 1b48ba08..00000000 --- a/pop-api/src/interfaces/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod nfts; diff --git a/pop-api/src/interfaces/nfts.rs b/pop-api/src/interfaces/nfts.rs deleted file mode 100644 index e0289a52..00000000 --- a/pop-api/src/interfaces/nfts.rs +++ /dev/null @@ -1,197 +0,0 @@ -use ink::prelude::vec::Vec; -use sp_runtime::{BoundedVec, MultiAddress}; - -#[derive(scale::Encode)] -pub 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/pop-api/src/lib.rs b/pop-api/src/lib.rs index 8faac9d9..6eae52a6 100644 --- a/pop-api/src/lib.rs +++ b/pop-api/src/lib.rs @@ -1,8 +1,5 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -pub mod impls; -pub mod interfaces; - use pop_api_primitives::storage_keys; pub mod v0; diff --git a/runtime/src/extensions/ext_impl/dispatch.rs b/runtime/src/extensions/ext_impl/dispatch.rs index c6713c78..df804bc7 100644 --- a/runtime/src/extensions/ext_impl/dispatch.rs +++ b/runtime/src/extensions/ext_impl/dispatch.rs @@ -33,6 +33,15 @@ where 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();