diff --git a/pop-api/examples/balance-transfer/Cargo.toml b/pop-api/examples/balance-transfer/Cargo.toml index 282a84d9..29cd0ea5 100755 --- a/pop-api/examples/balance-transfer/Cargo.toml +++ b/pop-api/examples/balance-transfer/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pop_api_extension_demo" +name = "balance_transfer" version = "0.1.0" authors = ["[your_name] <[your_email]>"] edition = "2021" diff --git a/pop-api/examples/balance-transfer/lib.rs b/pop-api/examples/balance-transfer/lib.rs index 34c6a2cf..328a818b 100755 --- a/pop-api/examples/balance-transfer/lib.rs +++ b/pop-api/examples/balance-transfer/lib.rs @@ -1,49 +1,49 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -use pop_api::balances; +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(Error), } -impl From for ContractError { - fn from(value: balances::Error) -> Self { +impl From for ContractError { + fn from(value: Error) -> Self { ContractError::BalancesError(value) } } #[ink::contract(env = pop_api::Environment)] -mod pop_api_extension_demo { - use super::ContractError; +mod balance_transfer { + use super::*; #[ink(storage)] #[derive(Default)] - pub struct PopApiExtensionDemo; + pub struct BalanceTransfer; - impl PopApiExtensionDemo { + impl BalanceTransfer { #[ink(constructor, payable)] pub fn new() -> Self { - ink::env::debug_println!("PopApiExtensionDemo::new"); + ink::env::debug_println!("BalanceTransfer::new"); Default::default() } #[ink(message)] - pub fn transfer_through_runtime( + pub fn transfer( &mut self, receiver: AccountId, value: Balance, ) -> Result<(), ContractError> { ink::env::debug_println!( - "PopApiExtensionDemo::transfer_through_runtime: \nreceiver: {:?}, \nvalue: {:?}", + "BalanceTransfer::transfer: \nreceiver: {:?}, \nvalue: {:?}", receiver, value ); - pop_api::balances::transfer_keep_alive(receiver, value)?; + transfer_keep_alive(receiver, value)?; - ink::env::debug_println!("PopApiExtensionDemo::transfer_through_runtime end"); + ink::env::debug_println!("BalanceTransfer::transfer end"); Ok(()) } } @@ -107,7 +107,7 @@ mod pop_api_extension_demo { client.free_balance(receiver).await.expect("Failed to get account balance"); // when - let transfer_message = call_builder.transfer_through_runtime(receiver, TRANSFER_VALUE); + let transfer_message = call_builder.transfer(receiver, TRANSFER_VALUE); let call_res = client .call(&ink_e2e::alice(), &transfer_message) @@ -131,4 +131,4 @@ mod pop_api_extension_demo { Ok(()) } } -} +} \ No newline at end of file diff --git a/pop-api/examples/nfts/Cargo.toml b/pop-api/examples/nfts/Cargo.toml index 20251306..e931cf9f 100755 --- a/pop-api/examples/nfts/Cargo.toml +++ b/pop-api/examples/nfts/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pop_api_nft_example" +name = "nfts" version = "0.1.0" authors = ["[your_name] <[your_email]>"] edition = "2021" diff --git a/pop-api/examples/nfts/lib.rs b/pop-api/examples/nfts/lib.rs index e9d97a99..d47140e7 100755 --- a/pop-api/examples/nfts/lib.rs +++ b/pop-api/examples/nfts/lib.rs @@ -18,7 +18,7 @@ impl From for ContractError { } #[ink::contract(env = pop_api::Environment)] -mod pop_api_nfts { +mod nfts { use super::*; #[ink(storage)] @@ -64,26 +64,26 @@ mod pop_api_nfts { receiver: AccountId, ) -> Result<(), ContractError> { ink::env::debug_println!( - "Nfts::mint_through_runtime: collection_id: {:?} item_id {:?} receiver: {:?}", + "Nfts::mint: collection_id: {:?} item_id {:?} receiver: {:?}", collection_id, item_id, receiver ); // Check if item already exists (demo purposes only, unnecessary as would expect check in mint call) - if pop_api::nfts::item(collection_id, item_id)?.is_some() { + if item(collection_id, item_id)?.is_some() { return Err(ContractError::ItemAlreadyExists); } // mint api - pop_api::nfts::mint(collection_id, item_id, receiver)?; - ink::env::debug_println!("Nfts::mint_through_runtime: item minted successfully"); + mint(collection_id, item_id, receiver)?; + ink::env::debug_println!("Nfts::mint: item minted successfully"); // check owner - match pop_api::nfts::owner(collection_id, item_id)? { + match owner(collection_id, item_id)? { Some(owner) if owner == receiver => { ink::env::debug_println!( - "Nfts::mint_through_runtime success: minted item belongs to receiver" + "Nfts::mint success: minted item belongs to receiver" ); }, _ => { @@ -91,7 +91,7 @@ mod pop_api_nfts { }, } - ink::env::debug_println!("Nfts::mint_through_runtime end"); + ink::env::debug_println!("Nfts::mint end"); Ok(()) } @@ -113,4 +113,4 @@ mod pop_api_nfts { Nfts::new(); } } -} +} \ No newline at end of file diff --git a/pop-api/examples/place-spot-order/Cargo.toml b/pop-api/examples/place-spot-order/Cargo.toml index 6ed5ed2b..2c67313d 100755 --- a/pop-api/examples/place-spot-order/Cargo.toml +++ b/pop-api/examples/place-spot-order/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pop_api_spot_order_example" +name = "spot_order" version = "0.1.0" authors = ["[your_name] <[your_email]>"] edition = "2021" diff --git a/pop-api/examples/place-spot-order/lib.rs b/pop-api/examples/place-spot-order/lib.rs index e8994f69..f5e34f7f 100755 --- a/pop-api/examples/place-spot-order/lib.rs +++ b/pop-api/examples/place-spot-order/lib.rs @@ -1,34 +1,16 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -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 { - InvalidCollection, - ItemAlreadyExists, - NftsError(nfts::Error), - NotOwner, -} - -impl From for ContractError { - fn from(value: nfts::Error) -> Self { - ContractError::NftsError(value) - } -} - #[ink::contract(env = pop_api::Environment)] -mod pop_api_spot_order_example { - use super::ContractError; +mod spot_order { #[ink(storage)] #[derive(Default)] - pub struct PopApiSpotOrderExample; + pub struct SpotOrder; - impl PopApiSpotOrderExample { + impl SpotOrder { #[ink(constructor, payable)] pub fn new() -> Self { - ink::env::debug_println!("Contract::new"); + ink::env::debug_println!("SpotOrder::new"); Default::default() } @@ -37,21 +19,21 @@ mod pop_api_spot_order_example { &mut self, max_amount: Balance, para_id: u32, - ) -> Result<(), ContractError> { + ) { ink::env::debug_println!( - "Contract::place_spot_order: max_amount {:?} para_id: {:?} ", + "SpotOrder::place_spot_order: max_amount {:?} para_id: {:?} ", max_amount, para_id, ); + #[allow(unused_variables)] let res = pop_api::cross_chain::coretime::place_spot_order(max_amount, para_id); ink::env::debug_println!( - "Contract::place_spot_order: res {:?} ", + "SpotOrder::place_spot_order: res {:?} ", res, ); - ink::env::debug_println!("Contract::place_spot_order end"); - Ok(()) + ink::env::debug_println!("SpotOrder::place_spot_order end"); } } @@ -61,7 +43,7 @@ mod pop_api_spot_order_example { #[ink::test] fn default_works() { - PopApiSpotOrderExample::new(); + SpotOrder::new(); } } -} +} \ No newline at end of file diff --git a/pop-api/examples/read-runtime-state/Cargo.toml b/pop-api/examples/read-runtime-state/Cargo.toml index 2186c17b..379152dd 100755 --- a/pop-api/examples/read-runtime-state/Cargo.toml +++ b/pop-api/examples/read-runtime-state/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pop_api_extension_demo" +name = "read_relay_blocknumber" version = "0.1.0" authors = ["[your_name] <[your_email]>"] edition = "2021" diff --git a/pop-api/examples/read-runtime-state/lib.rs b/pop-api/examples/read-runtime-state/lib.rs index 8d0004f9..05a44108 100755 --- a/pop-api/examples/read-runtime-state/lib.rs +++ b/pop-api/examples/read-runtime-state/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] #[ink::contract(env = pop_api::Environment)] -mod pop_api_extension_demo { +mod read_relay_blocknumber { use pop_api::primitives::storage_keys::{ ParachainSystemKeys::LastRelayChainBlockNumber, RuntimeStateKeys::ParachainSystem, }; @@ -13,12 +13,12 @@ mod pop_api_extension_demo { #[ink(storage)] #[derive(Default)] - pub struct PopApiExtensionDemo; + pub struct ReadRelayBlockNumber; - impl PopApiExtensionDemo { + impl ReadRelayBlockNumber { #[ink(constructor, payable)] pub fn new() -> Self { - ink::env::debug_println!("PopApiExtensionDemo::new"); + ink::env::debug_println!("ReadRelayBlockNumber::new"); Default::default() } @@ -32,4 +32,4 @@ mod pop_api_extension_demo { }); } } -} +} \ No newline at end of file diff --git a/runtime/devnet/src/extensions.rs b/runtime/devnet/src/extensions.rs index 89c070ee..7e2a53c0 100644 --- a/runtime/devnet/src/extensions.rs +++ b/runtime/devnet/src/extensions.rs @@ -415,7 +415,7 @@ mod tests { let _ = env_logger::try_init(); let (wasm_binary, _) = load_wasm_module::( - "../../pop-api/examples/balance-transfer/target/ink/pop_api_extension_demo.wasm", + "../../pop-api/examples/balance-transfer/target/ink/balance_transfer.wasm", ) .unwrap(); @@ -569,10 +569,9 @@ mod tests { new_test_ext().execute_with(|| { let _ = env_logger::try_init(); - let (wasm_binary, _) = load_wasm_module::( - "../../pop-api/examples/nfts/target/ink/pop_api_nft_example.wasm", - ) - .unwrap(); + let (wasm_binary, _) = + load_wasm_module::("../../pop-api/examples/nfts/target/ink/nfts.wasm") + .unwrap(); let init_value = 100; @@ -649,10 +648,9 @@ mod tests { new_test_ext().execute_with(|| { let _ = env_logger::try_init(); - let (wasm_binary, _) = load_wasm_module::( - "../../pop-api/examples/nfts/target/ink/pop_api_nft_example.wasm", - ) - .unwrap(); + let (wasm_binary, _) = + load_wasm_module::("../../pop-api/examples/nfts/target/ink/nfts.wasm") + .unwrap(); let init_value = 100; @@ -715,7 +713,7 @@ mod tests { let _ = env_logger::try_init(); let (wasm_binary, _) = load_wasm_module::( - "../../pop-api/examples/read-runtime-state/target/ink/pop_api_extension_demo.wasm", + "../../pop-api/examples/read-runtime-state/target/ink/read_relay_blocknumber.wasm", ) .unwrap(); @@ -774,7 +772,7 @@ mod tests { let _ = env_logger::try_init(); let (wasm_binary, _) = load_wasm_module::( - "../../pop-api/examples/place-spot-order/target/ink/pop_api_spot_order_example.wasm", + "../../pop-api/examples/place-spot-order/target/ink/spot_order.wasm", ) .unwrap(); diff --git a/runtime/testnet/src/extensions.rs b/runtime/testnet/src/extensions.rs index 27223107..d6f2d656 100644 --- a/runtime/testnet/src/extensions.rs +++ b/runtime/testnet/src/extensions.rs @@ -350,7 +350,7 @@ mod tests { let _ = env_logger::try_init(); let (wasm_binary, _) = load_wasm_module::( - "../../pop-api/examples/balance-transfer/target/ink/pop_api_extension_demo.wasm", + "../../pop-api/examples/balance-transfer/target/ink/balance_transfer.wasm", ) .unwrap(); @@ -415,10 +415,9 @@ mod tests { new_test_ext().execute_with(|| { let _ = env_logger::try_init(); - let (wasm_binary, _) = load_wasm_module::( - "../../pop-api/examples/nfts/target/ink/pop_api_nft_example.wasm", - ) - .unwrap(); + let (wasm_binary, _) = + load_wasm_module::("../../pop-api/examples/nfts/target/ink/nfts.wasm") + .unwrap(); let init_value = 100; @@ -495,10 +494,9 @@ mod tests { new_test_ext().execute_with(|| { let _ = env_logger::try_init(); - let (wasm_binary, _) = load_wasm_module::( - "../../pop-api/examples/nfts/target/ink/pop_api_nft_example.wasm", - ) - .unwrap(); + let (wasm_binary, _) = + load_wasm_module::("../../pop-api/examples/nfts/target/ink/nfts.wasm") + .unwrap(); let init_value = 100; @@ -561,7 +559,7 @@ mod tests { let _ = env_logger::try_init(); let (wasm_binary, _) = load_wasm_module::( - "../../pop-api/examples/read-runtime-state/target/ink/pop_api_extension_demo.wasm", + "../../pop-api/examples/read-runtime-state/target/ink/read_relay_blocknumber.wasm", ) .unwrap(); @@ -620,7 +618,7 @@ mod tests { let _ = env_logger::try_init(); let (wasm_binary, _) = load_wasm_module::( - "../../pop-api/examples/place-spot-order/target/ink/pop_api_spot_order_example.wasm", + "../../pop-api/examples/place-spot-order/target/ink/spot_order.wasm", ) .unwrap();