diff --git a/Cargo.lock b/Cargo.lock index df25046..11e8963 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3758,7 +3758,7 @@ dependencies = [ [[package]] name = "myriad" -version = "2.1.8" +version = "2.1.9" dependencies = [ "beefy-gadget", "beefy-gadget-rpc", @@ -3817,7 +3817,7 @@ dependencies = [ [[package]] name = "myriad-runtime" -version = "2.1.8" +version = "2.1.9" dependencies = [ "beefy-primitives", "frame-benchmarking", @@ -3848,7 +3848,6 @@ dependencies = [ "pallet-sudo", "pallet-timestamp", "pallet-tipping", - "pallet-tipping-benchmarking", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-uniques", @@ -4421,7 +4420,7 @@ dependencies = [ [[package]] name = "pallet-server" -version = "2.1.8" +version = "2.1.9" dependencies = [ "frame-benchmarking", "frame-support", @@ -4490,7 +4489,7 @@ dependencies = [ [[package]] name = "pallet-tipping" -version = "2.1.8" +version = "2.1.9" dependencies = [ "frame-benchmarking", "frame-support", @@ -4500,7 +4499,6 @@ dependencies = [ "log", "pallet-assets", "pallet-balances", - "pallet-server", "parity-scale-codec", "scale-info", "serde", @@ -4511,27 +4509,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-tipping-benchmarking" -version = "2.1.8" -dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", - "hex-literal", - "pallet-assets", - "pallet-balances", - "pallet-server", - "pallet-tipping", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" diff --git a/node/Cargo.toml b/node/Cargo.toml index eefbd8d..f9a7f89 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'myriad' -version = '2.1.8' +version = '2.1.9' edition = '2021' license = 'AGPL-3.0' authors = ['Myriad Dev Team '] diff --git a/pallets/server/Cargo.toml b/pallets/server/Cargo.toml index 6996f14..7ba3bc9 100644 --- a/pallets/server/Cargo.toml +++ b/pallets/server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-server' -version = '2.1.8' +version = '2.1.9' edition = '2021' license = 'AGPL-3.0' authors = ['Myriad Dev Team '] diff --git a/pallets/server/src/benchmarking.rs b/pallets/server/src/benchmarking.rs index a116c22..07c9f0d 100644 --- a/pallets/server/src/benchmarking.rs +++ b/pallets/server/src/benchmarking.rs @@ -5,7 +5,6 @@ use super::*; #[allow(unused)] use crate::{Pallet as Server, ServerInterface}; use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; -use frame_support::sp_runtime::SaturatedConversion; use frame_system::RawOrigin; use sp_std::vec; @@ -21,10 +20,8 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); let caller_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); - let server_id = 0; - let server_name = "myriad".as_bytes().to_vec(); + let server_id = 0_u64; let server_api_url = "https://api.dev.myriad.social".as_bytes().to_vec(); - let server_web_url = "https://app.dev.myriad.social".as_bytes().to_vec(); let _ = Server::::register(caller_origin.clone(), server_api_url); let new_api_url = "https://api.testnet.myriad.social".as_bytes().to_vec(); @@ -34,10 +31,8 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); let caller_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); - let server_id = 0; - let server_name = "myriad".as_bytes().to_vec(); + let server_id = 0_u64; let server_api_url = "https://api.dev.myriad.social".as_bytes().to_vec(); - let server_web_url = "https://app.dev.myriad.social".as_bytes().to_vec(); let _ = Server::::register(caller_origin.clone(), server_api_url); let new_owner: T::AccountId = account("new_owner", 0, SEED); @@ -47,10 +42,8 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); let caller_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); - let server_id = 0; - let server_name = "myriad".as_bytes().to_vec(); + let server_id = 0_u64; let server_api_url = "https://api.dev.myriad.social".as_bytes().to_vec(); - let server_web_url = "https://app.dev.myriad.social".as_bytes().to_vec(); let _ = Server::::register(caller_origin.clone(), server_api_url); }: _(RawOrigin::Signed(caller), server_id) diff --git a/pallets/server/src/functions.rs b/pallets/server/src/functions.rs index 0199759..a3650c4 100644 --- a/pallets/server/src/functions.rs +++ b/pallets/server/src/functions.rs @@ -1,6 +1,14 @@ use crate::*; impl Pallet { + pub fn do_api_url_exist(api_url: &[u8]) -> Result<(), Error> { + if Self::server_by_api_url(api_url).is_some() { + return Err(Error::::AlreadyExists) + } + + Ok(()) + } + pub fn do_mutate_server( server_id: u64, owner: &T::AccountId, @@ -14,7 +22,10 @@ impl Pallet { let updated_server = match data { ServerDataKind::Owner(new_owner) => server.clone().set_owner(new_owner), - ServerDataKind::ApiUrl(new_url) => server.clone().set_api_url(new_url), + ServerDataKind::ApiUrl(new_url) => { + ServerByApiUrl::::swap(server.get_api_url(), &new_url); + server.clone().set_api_url(new_url) + }, }; ServerByOwner::::insert(owner, server_id, &updated_server); diff --git a/pallets/server/src/impl_server.rs b/pallets/server/src/impl_server.rs index 64069c9..e26b5cf 100644 --- a/pallets/server/src/impl_server.rs +++ b/pallets/server/src/impl_server.rs @@ -9,6 +9,8 @@ impl ServerInterface for Pallet { } fn register(owner: &T::AccountId, api_url: &[u8]) -> Result { + Self::do_api_url_exist(api_url)?; + let count = Self::server_count(); let index = Self::server_index(); @@ -20,6 +22,7 @@ impl ServerInterface for Pallet { ServerCount::::set(updated_count); ServerIndex::::set(updated_index); ServerById::::insert(index, &server); + ServerByApiUrl::::insert(api_url, index); ServerByOwner::::insert(owner, index, &server); Ok(server) @@ -42,6 +45,7 @@ impl ServerInterface for Pallet { owner: &T::AccountId, new_api_url: &[u8], ) -> Result<(), Self::Error> { + Self::do_api_url_exist(new_api_url)?; Self::do_mutate_server(server_id, owner, &ServerDataKind::ApiUrl(new_api_url.to_vec()))?; Ok(()) @@ -59,9 +63,10 @@ impl ServerInterface for Pallet { let count = Self::server_count().checked_sub(1).ok_or(Error::::Overflow)?; + ServerCount::::set(count); ServerById::::remove(server_id); ServerByOwner::::remove(owner, server_id); - ServerCount::::set(count); + ServerByApiUrl::::remove(server.get_api_url()); Ok(()) } diff --git a/pallets/server/src/lib.rs b/pallets/server/src/lib.rs index 535b64a..675a2ec 100644 --- a/pallets/server/src/lib.rs +++ b/pallets/server/src/lib.rs @@ -23,7 +23,7 @@ pub use weights::WeightInfo; use frame_support::traits::StorageVersion; /// The current storage version. -const STORAGE_VERSION: StorageVersion = StorageVersion::new(3); +const STORAGE_VERSION: StorageVersion = StorageVersion::new(4); #[frame_support::pallet] pub mod pallet { @@ -47,7 +47,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn server_count)] - pub type ServerCount = StorageValue<_, ServerId, ValueQuery>; + pub type ServerCount = StorageValue<_, u64, ValueQuery>; #[pallet::storage] #[pallet::getter(fn server_index)] @@ -57,6 +57,10 @@ pub mod pallet { #[pallet::getter(fn server_by_id)] pub(super) type ServerById = StorageMap<_, Blake2_128Concat, ServerId, ServerOf>; + #[pallet::storage] + #[pallet::getter(fn server_by_api_url)] + pub(super) type ServerByApiUrl = StorageMap<_, Blake2_128Concat, ApiUrl, ServerId>; + #[pallet::storage] #[pallet::getter(fn server_by_owner)] pub(super) type ServerByOwner = StorageDoubleMap< diff --git a/pallets/server/src/migrations.rs b/pallets/server/src/migrations.rs index 29addc5..aae1a0a 100644 --- a/pallets/server/src/migrations.rs +++ b/pallets/server/src/migrations.rs @@ -1,5 +1,5 @@ use crate::{ - AccountIdOf, Config, Pallet, Server as NewServer, ServerById as NewServerById, + AccountIdOf, Config, Pallet, Server as NewServer, ServerByApiUrl, ServerById as NewServerById, ServerByOwner as NewServerByOwner, ServerCount as NewServerCount, ServerId, ServerIndex as NewServerIndex, ServerOf, }; @@ -29,6 +29,11 @@ pub fn migrate() -> Weight { version = StorageVersion::new(3); } + if version == 3 { + weight = weight.saturating_add(versions::v4::migrate::()); + version = StorageVersion::new(4); + } + version.put::>(); weight } @@ -149,4 +154,22 @@ mod versions { weight } } + + pub mod v4 { + use super::*; + + pub fn migrate() -> Weight { + let mut weight = T::DbWeight::get().writes(1); + + NewServerById::::translate(|server_id: ServerId, server: ServerOf| { + weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); + + ServerByApiUrl::::insert(server.get_api_url(), server_id); + + Some(server) + }); + + weight + } + } } diff --git a/pallets/server/src/tests.rs b/pallets/server/src/tests.rs index 2c516d1..790ebab 100644 --- a/pallets/server/src/tests.rs +++ b/pallets/server/src/tests.rs @@ -12,10 +12,11 @@ fn register_works() { let server = pallet_server::Server::new(server_id, &owner, &api_url); - assert_ok!(Server::register(owner_origin, api_url)); + assert_ok!(Server::register(owner_origin, api_url.clone())); assert_eq!(Server::server_by_id(server_id), Some(server.clone())); assert_eq!(Server::server_by_owner(owner, server_id), Some(server)); + assert_eq!(Server::server_by_api_url(api_url), Some(server_id)); assert_eq!(Server::server_count(), 1); assert_eq!(Server::server_index(), 1); }) @@ -38,7 +39,7 @@ pub fn transfer_owner_works() { assert_eq!(Server::server_by_id(server_id), Some(server.clone())); assert_eq!(Server::server_by_owner(owner, server_id), None); - assert_eq!(Server::server_by_owner(new_owner, server_id), Some(server.clone())); + assert_eq!(Server::server_by_owner(new_owner, server_id), Some(server)); }) } @@ -54,10 +55,12 @@ pub fn change_api_url_works() { let new_api_url = "https://api.testnet.myriad.social".as_bytes().to_vec(); let server = pallet_server::Server::new(server_id, &owner, &new_api_url); - assert_ok!(Server::register(Origin::signed(owner), api_url)); - assert_ok!(Server::update_api_url(owner_origin, 0, new_api_url,)); + assert_ok!(Server::register(Origin::signed(owner), api_url.clone())); + assert_ok!(Server::update_api_url(owner_origin, 0, new_api_url.clone())); + assert_eq!(Server::server_by_api_url(api_url), None); assert_eq!(Server::server_by_id(server_id), Some(server)); + assert_eq!(Server::server_by_api_url(new_api_url), Some(server_id)); }) } @@ -70,12 +73,34 @@ pub fn deregister_works() { let server_id = 0_u64; let api_url = "https://api.dev.myriad.social".as_bytes().to_vec(); - assert_ok!(Server::register(Origin::signed(owner), api_url)); + assert_ok!(Server::register(Origin::signed(owner), api_url.clone())); assert_ok!(Server::unregister(owner_origin, 0)); assert_eq!(Server::server_by_id(server_id), None); assert_eq!(Server::server_by_owner(owner, server_id), None); + assert_eq!(Server::server_by_api_url(api_url), None); assert_eq!(Server::server_count(), 0); + assert_eq!(Server::server_index(), 1); + }) +} + +#[test] +pub fn cant_register_when_api_url_exist() { + ExternalityBuilder::build().execute_with(|| { + let owner = 1; + let owner_origin = Origin::signed(owner); + let api_url = b"https://api.dev.myriad.social".to_vec(); + + assert_ok!(Server::register(owner_origin, api_url)); + + let other_owner = 2; + let other_owner_origin = Origin::signed(other_owner); + let other_api_url = b"https://api.dev.myriad.social".to_vec(); + + assert_noop!( + Server::register(other_owner_origin, other_api_url), + Error::::AlreadyExists, + ); }) } @@ -146,7 +171,7 @@ pub fn cant_change_api_url_when_not_owner() { let fake_owner = 3; let fake_owner_origin = Origin::signed(fake_owner); - let new_api_url = "https://api.dev.myriad.social".as_bytes().to_vec(); + let new_api_url = "https://api.testnet.myriad.social".as_bytes().to_vec(); assert_noop!( Server::update_api_url(fake_owner_origin, server_id, new_api_url), @@ -155,6 +180,32 @@ pub fn cant_change_api_url_when_not_owner() { }) } +#[test] +pub fn cant_change_api_url_when_api_url_exist() { + ExternalityBuilder::build().execute_with(|| { + let owner = 1; + let owner_origin = Origin::signed(owner); + + let server_id = 0; + let api_url = b"https://api.dev.myriad.social".to_vec(); + + assert_ok!(Server::register(owner_origin.clone(), api_url)); + + let other_owner = 2; + let other_owner_origin = Origin::signed(other_owner); + let other_api_url = b"https://api.testnet.myriad.social".to_vec(); + + assert_ok!(Server::register(other_owner_origin, other_api_url)); + + let new_api_url = b"https://api.testnet.myriad.social".to_vec(); + + assert_noop!( + Server::update_api_url(owner_origin, server_id, new_api_url), + Error::::AlreadyExists, + ); + }) +} + #[test] pub fn cant_deregister_when_server_id_not_exist() { ExternalityBuilder::build().execute_with(|| { diff --git a/pallets/server/src/types.rs b/pallets/server/src/types.rs index c995e89..520f425 100644 --- a/pallets/server/src/types.rs +++ b/pallets/server/src/types.rs @@ -73,3 +73,4 @@ pub enum OperatorKind { pub type AccountIdOf = ::AccountId; pub type ServerOf = Server>; pub type ServerId = u64; +pub type ApiUrl = Vec; diff --git a/pallets/server/src/weights.rs b/pallets/server/src/weights.rs index c2bab76..9db9492 100644 --- a/pallets/server/src/weights.rs +++ b/pallets/server/src/weights.rs @@ -1,7 +1,7 @@ //! Autogenerated weights for pallet_server //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-09-02, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-09-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -36,66 +36,76 @@ pub trait WeightInfo { /// Weights for pallet_server using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { + // Storage: Server ServerByApiUrl (r:1 w:1) // Storage: Server ServerCount (r:1 w:1) + // Storage: Server ServerIndex (r:1 w:1) // Storage: Server ServerById (r:0 w:1) // Storage: Server ServerByOwner (r:0 w:1) - fn register(s: u32, ) -> Weight { - 49_624_000_u64 // Standard Error: 36_000 - .saturating_add((46_000_u64).saturating_mul(s as Weight)) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + fn register(_s: u32, ) -> Weight { + 59_386_000_u64 + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } + // Storage: Server ServerByApiUrl (r:2 w:2) // Storage: Server ServerById (r:1 w:1) + // Storage: Server ServerByOwner (r:0 w:1) fn update_api_url() -> Weight { - 59_300_000_u64 - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + 91_800_000_u64 + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: Server ServerById (r:1 w:1) + // Storage: Server ServerByOwner (r:1 w:2) fn transfer_owner() -> Weight { - 42_600_000_u64 - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + 51_600_000_u64 + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: Server ServerById (r:1 w:1) // Storage: Server ServerCount (r:1 w:1) // Storage: Server ServerByOwner (r:0 w:1) + // Storage: Server ServerByApiUrl (r:0 w:1) fn unregister() -> Weight { - 41_000_000_u64 + 47_600_000_u64 .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { + // Storage: Server ServerByApiUrl (r:1 w:1) // Storage: Server ServerCount (r:1 w:1) + // Storage: Server ServerIndex (r:1 w:1) // Storage: Server ServerById (r:0 w:1) // Storage: Server ServerByOwner (r:0 w:1) - fn register(s: u32, ) -> Weight { - 49_624_000_u64 // Standard Error: 36_000 - .saturating_add((46_000_u64).saturating_mul(s as Weight)) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(3_u64)) + fn register(_s: u32, ) -> Weight { + 59_386_000_u64 + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) } + // Storage: Server ServerByApiUrl (r:2 w:2) // Storage: Server ServerById (r:1 w:1) + // Storage: Server ServerByOwner (r:0 w:1) fn update_api_url() -> Weight { - 59_300_000_u64 - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + 91_800_000_u64 + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: Server ServerById (r:1 w:1) + // Storage: Server ServerByOwner (r:1 w:2) fn transfer_owner() -> Weight { - 42_600_000_u64 - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + 51_600_000_u64 + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: Server ServerById (r:1 w:1) // Storage: Server ServerCount (r:1 w:1) // Storage: Server ServerByOwner (r:0 w:1) + // Storage: Server ServerByApiUrl (r:0 w:1) fn unregister() -> Weight { - 41_000_000_u64 + 47_600_000_u64 .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(3_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) } } diff --git a/pallets/tipping/Cargo.toml b/pallets/tipping/Cargo.toml index 76d0605..7f4cd5e 100644 --- a/pallets/tipping/Cargo.toml +++ b/pallets/tipping/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-tipping' -version = '2.1.8' +version = '2.1.9' edition = '2021' license = 'AGPL-3.0' authors = ['Myriad Dev Team '] @@ -34,9 +34,6 @@ frame-benchmarking = { git = 'https://github.com/paritytech/substrate', branch = pallet-balances = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.18', default-features = false } pallet-assets = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18', default-features = false } -# Local Dependencies -pallet-server = { path = '../server', default-features = false } - [dev-dependencies] # External Dependencies serde = { version = '1.0.136', default-features = false } @@ -60,8 +57,6 @@ std = [ 'pallet-balances/std', 'pallet-assets/std', - - 'pallet-server/std', ] runtime-benchmarks = [ 'frame-benchmarking' diff --git a/pallets/tipping/benchmarking/Cargo.toml b/pallets/tipping/benchmarking/Cargo.toml deleted file mode 100644 index de4c9a3..0000000 --- a/pallets/tipping/benchmarking/Cargo.toml +++ /dev/null @@ -1,64 +0,0 @@ -[package] -name = 'pallet-tipping-benchmarking' -version = '2.1.8' -edition = '2021' -license = 'AGPL-3.0' -authors = ['Myriad Dev Team '] -homepage = 'https://myriad.social' -repository = 'https://github.com/myriadsocial/myriad-node' - -[package.metadata.docs.rs] -targets = ['x86_64-unknown-linux-gnu'] - -[dependencies] -# External Dependencies -codec = { package = 'parity-scale-codec', version = '3.0.0', default-features = false, features = ['derive'] } -scale-info = { version = '2.0.1', default-features = false, features = ['derive'] } - -# Substrate packages -## Substrate Primitive Dependencies -sp-std = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.18', default-features = false } - -## Substrate Frame Dependencies -frame-support = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18', default-features = false } -frame-system = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18', default-features = false } -frame-benchmarking = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.18', default-features = false } - -# Substrate Pallet Dependencies -pallet-balances = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.18', default-features = false } -pallet-assets = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18', default-features = false } - -# Substrate Local Dependencies -pallet-server = { path = '../../server', default-features = false } -pallet-tipping = { path = '../../tipping', default-features = false } - -[dev-dependencies] -# External Dependencies -serde = { version = '1.0.136', default-features = false } -hex-literal = { version = '0.3.4', default-features = false } - -# Substrate Dependencies -## Substrate Primitive Dependencies -sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18', default-features = false } -sp-io = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18', default-features = false } -sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18', default-features = false } - -[features] -default = ['std'] -std = [ - 'codec/std', - 'scale-info/std', - - 'sp-io/std', - 'sp-std/std', - - 'frame-support/std', - 'frame-system/std', - 'frame-benchmarking/std', - - 'pallet-balances/std', - 'pallet-assets/std', - - 'pallet-server/std', - 'pallet-tipping/std', -] diff --git a/pallets/tipping/benchmarking/src/mock.rs b/pallets/tipping/benchmarking/src/mock.rs deleted file mode 100644 index 091d475..0000000 --- a/pallets/tipping/benchmarking/src/mock.rs +++ /dev/null @@ -1,128 +0,0 @@ -#![cfg(test)] - -use frame_support::{ - construct_runtime, parameter_types, - traits::{ConstU128, ConstU32, Everything}, -}; -use frame_system as system; -use pallet_balances::AccountData; -use sp_core::{sr25519::Signature, H256}; -use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify}, -}; - -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; - -construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - Tipping: pallet_tipping::{Pallet, Call, Storage, Event}, - Server: pallet_server::{Pallet, Call, Storage, Event}, - Assets: pallet_assets::{Pallet, Call, Storage, Event}, - } -); - -parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; - pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(1024); -} - -impl system::Config for Test { - type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); - type Origin = Origin; - type Index = u64; - type Call = Call; - type BlockNumber = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = sp_core::sr25519::Public; - type Lookup = IdentityLookup; - type Header = Header; - type Event = Event; - type BlockHashCount = BlockHashCount; - type DbWeight = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = ConstU32<2>; -} - -type Balance = u128; - -parameter_types! { - pub static ExistentialDeposit: Balance = 0; -} - -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - /// The type for recording an account's balance. - type Balance = Balance; - /// The ubiquitous event type. - type Event = Event; - type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} - -impl pallet_tipping::Config for Test { - type Call = Call; - type Event = Event; - type Currency = Balances; - type Server = Server; - type Assets = Assets; - type WeightInfo = (); -} - -impl pallet_server::Config for Test { - type Event = Event; - type WeightInfo = (); -} - -pub type OctopusAssetId = u32; -pub type OctopusAssetBalance = u128; - -parameter_types! { - pub const ApprovalDeposit: Balance = 1; - pub const AssetDeposit: Balance = 1; - pub const MetadataDepositBase: Balance = 1; - pub const MetadataDepositPerByte: Balance = 1; - pub const StringLimit: u32 = 50; -} - -type AccountId = <::Signer as IdentifyAccount>::AccountId; - -impl pallet_assets::Config for Test { - type Event = Event; - type Balance = OctopusAssetBalance; - type AssetId = OctopusAssetId; - type Currency = Balances; - type ForceOrigin = frame_system::EnsureRoot; - type AssetAccountDeposit = ConstU128<10>; - type AssetDeposit = AssetDeposit; - type MetadataDepositBase = MetadataDepositBase; - type MetadataDepositPerByte = MetadataDepositPerByte; - type ApprovalDeposit = ApprovalDeposit; - type StringLimit = StringLimit; - type Freezer = (); - type Extra = (); - type WeightInfo = (); -} diff --git a/pallets/tipping/benchmarking/src/lib.rs b/pallets/tipping/src/benchmarking.rs similarity index 63% rename from pallets/tipping/benchmarking/src/lib.rs rename to pallets/tipping/src/benchmarking.rs index ee312e5..a3829a0 100644 --- a/pallets/tipping/benchmarking/src/lib.rs +++ b/pallets/tipping/src/benchmarking.rs @@ -1,42 +1,28 @@ -#![cfg_attr(not(feature = "std"), no_std)] +#![cfg(feature = "runtime-benchmarks")] -mod mock; +use super::*; -use frame_benchmarking::{account, benchmarks, whitelisted_caller}; +#[allow(unused)] +use crate::{Config, Pallet as Tipping, TippingInterface}; +use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; use frame_support::{sp_runtime::SaturatedConversion, traits::Currency}; use frame_system::RawOrigin; -use pallet_server::{Config as ServerConfig, Pallet as Server}; -use pallet_tipping::{ - Call, Config as TippingConfig, Pallet as Tipping, References, TipsBalanceInfo, -}; use sp_std::vec; const SEED: u32 = 0; -pub struct Pallet(Tipping); - -pub trait Config: TippingConfig + ServerConfig {} - benchmarks! { send_tip { // Initial account let caller: T::AccountId = whitelisted_caller(); + let server_id: T::AccountId = account("server_account", 0, SEED); // Default balance let balance = 1000000000000000000000u128.saturated_into(); let amount = 1000000000000000u128.saturated_into(); // Caller initial balance - let _ = ::Currency::deposit_creating(&caller, balance); - - // Generate server id - let server_id = b"0".to_vec(); - - // Register server id - let server_account: T::AccountId = account("server_account", 0, SEED); - let server_origin = ::Origin::from(RawOrigin::Signed(server_account)); - let server_api_url = b"https://api.dev.myriad.social".to_vec(); - let _ = Server::::register(server_origin, server_api_url); + let _ = ::Currency::deposit_creating(&caller, balance); // Send tip let reference_id = b"people_id".to_vec(); @@ -63,22 +49,14 @@ benchmarks! { let tipping_amount = 10000000000000000000u128.saturated_into(); // Tipping_account_id, account_1, and account_2 initial balance - let _ = ::Currency::deposit_creating(&account_1, balance); - let _ = ::Currency::deposit_creating(&account_2, balance); - let _ = ::Currency::deposit_creating(&tipping_account_id, balance); - - // Generate Server Id - let server_id = b"0".to_vec(); - - // Register Server - let server_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); - let server_api_url = b"https://api.dev.myriad.social".to_vec(); - let _ = Server::::register(server_origin, server_api_url); + let _ = ::Currency::deposit_creating(&account_1, balance); + let _ = ::Currency::deposit_creating(&account_2, balance); + let _ = ::Currency::deposit_creating(&tipping_account_id, balance); // Send Tip by account_1 let account_1_origin = ::Origin::from(RawOrigin::Signed(account_1)); let tips_balance_info = TipsBalanceInfo::new( - &server_id, + &caller, b"people", b"people_id", b"native" @@ -88,7 +66,7 @@ benchmarks! { // Send Tip by account_2 let account_2_origin = ::Origin::from(RawOrigin::Signed(account_2)); let tips_balance_info = TipsBalanceInfo::new( - &server_id, + &caller, b"user", b"user_id", b"native" @@ -96,36 +74,30 @@ benchmarks! { let _ = Tipping::::send_tip(account_2_origin, tips_balance_info, tipping_amount); // Claim reference data + let server_id = caller.clone(); let trx_fee = 10000000000000u128.saturated_into(); let references = References::new(b"people", &[b"people_id".to_vec()]); let main_references = References::new(b"user", &[b"user_id".to_vec()]); let ft_identifiers = vec![b"native".to_vec()]; - }: _(RawOrigin::Signed(caller), server_id, references, main_references, ft_identifiers, account_3, trx_fee) + }: _(RawOrigin::Signed(caller), server_id, references, main_references, ft_identifiers, +account_3, trx_fee) claim_tip { // Initial account let caller: T::AccountId = whitelisted_caller(); let account_1: T::AccountId = account("account", 0, SEED); let account_2: T::AccountId = account("account", 2, SEED); - let server_account: T::AccountId = account("server_account", 0, SEED); + let server_id: T::AccountId = account("server_account", 0, SEED); let tipping_account_id: T::AccountId = Tipping::::tipping_account_id(); // Default balance let balance = 1000000000000000000000u128.saturated_into(); let tipping_amount = 10000000000000000000u128.saturated_into(); - let _ = ::Currency::deposit_creating(&caller, balance); - let _ = ::Currency::deposit_creating(&account_1, balance); - let _ = ::Currency::deposit_creating(&account_2, balance); - let _ = ::Currency::deposit_creating(&tipping_account_id, balance); - - // Generate Server Id - let server_id = b"0".to_vec(); - - // Register Server - let server_origin = ::Origin::from(RawOrigin::Signed(server_account)); - let server_api_url = b"https://api.dev.myriad.social".to_vec(); - let _ = Server::::register(server_origin.clone(), server_api_url); + let _ = ::Currency::deposit_creating(&caller, balance); + let _ = ::Currency::deposit_creating(&account_1, balance); + let _ = ::Currency::deposit_creating(&account_2, balance); + let _ = ::Currency::deposit_creating(&tipping_account_id, balance); // Send Tip let account_1_origin = ::Origin::from(RawOrigin::Signed(account_1)); @@ -148,6 +120,7 @@ benchmarks! { let _ = Tipping::::send_tip(account_2_origin, tips_balance_info_user, tipping_amount); // Claim Reference + let server_origin = ::Origin::from(RawOrigin::Signed(server_id.clone())); let tx_fee = 10000000000000u128.saturated_into(); let _ = Tipping::::claim_reference( server_origin, @@ -158,5 +131,7 @@ benchmarks! { caller.clone(), tx_fee, ); - }: _(RawOrigin::Signed(caller), server_id, b"user".to_vec(), b"user_id".to_vec(), vec![b"native".to_vec()]) -} + }: _(RawOrigin::Signed(caller), server_id, b"user".to_vec(), b"user_id".to_vec(), +vec![b"native".to_vec()]) } + +impl_benchmark_test_suite! {Server, crate::mock::ExternalityBuilder::build(), crate::mock::Test} diff --git a/pallets/tipping/src/functions.rs b/pallets/tipping/src/functions.rs index 2b4e268..b93fce8 100644 --- a/pallets/tipping/src/functions.rs +++ b/pallets/tipping/src/functions.rs @@ -16,12 +16,12 @@ impl Pallet { PALLET_ID.into_account() } - pub fn can_update_balance(tips_balance_key: &TipsBalanceKey) -> bool { + pub fn can_update_balance(tips_balance_key: &TipsBalanceKeyOf) -> bool { TipsBalanceByReference::::contains_key(tips_balance_key) } pub fn can_pay_fee( - tips_balance_key: &TipsBalanceKey, + tips_balance_key: &TipsBalanceKeyOf, tx_fee: &BalanceOf, ) -> Result<(), Error> { if tx_fee == &Zero::zero() { @@ -45,7 +45,7 @@ impl Pallet { } pub fn can_claim_tip( - tips_balance_key: &TipsBalanceKey, + tips_balance_key: &TipsBalanceKeyOf, receiver: &AccountIdOf, ) -> Option> { if let Some(tips_balance) = Self::tips_balance_by_reference(tips_balance_key) { @@ -67,28 +67,6 @@ impl Pallet { None } - pub fn do_server_exist( - server_id: &[u8], - sender: Option<&T::AccountId>, - ) -> Result<(), Error> { - let server_id = String::from_utf8(server_id.to_vec()) - .map_err(|_| Error::::WrongFormat)? - .parse::() - .map_err(|_| Error::::WrongFormat)?; - - let server = T::Server::get_by_id(server_id).ok_or(Error::::ServerNotRegister)?; - - if sender.is_none() { - return Ok(()) - } - - if sender.unwrap() != server.get_owner() { - return Err(Error::::Unauthorized) - } - - Ok(()) - } - pub fn do_store_tips_balance( tips_balance: &TipsBalanceOf, set_empty: bool, @@ -163,7 +141,7 @@ impl Pallet { } pub fn do_store_tips_balances( - server_id: &[u8], + server_id: &AccountIdOf, references: &References, main_references: &References, ft_identifiers: &[FtIdentifier], @@ -180,6 +158,7 @@ impl Pallet { let reference_ids = references.get_reference_ids(); for reference_id in reference_ids { + let server_id = server_id.clone(); let tips_balance_key = (server_id, reference_type, reference_id, ft_identifier); if let Some(tips_balance) = Self::tips_balance_by_reference(&tips_balance_key) { let amount = *tips_balance.get_amount(); diff --git a/pallets/tipping/src/impl_tipping.rs b/pallets/tipping/src/impl_tipping.rs index 225e1f2..75f0c0d 100644 --- a/pallets/tipping/src/impl_tipping.rs +++ b/pallets/tipping/src/impl_tipping.rs @@ -5,10 +5,10 @@ use sp_std::vec::Vec; impl TippingInterface for Pallet { type Error = DispatchError; - type TipsBalanceInfo = TipsBalanceInfo; - type TipsBalanceKey = TipsBalanceKey; + type TipsBalanceInfo = TipsBalanceInfoOf; + type TipsBalanceKey = TipsBalanceKeyOf; type Balance = BalanceOf; - type ServerId = ServerId; + type ServerId = ServerIdOf; type References = References; type ReferenceType = ReferenceType; type ReferenceId = ReferenceId; @@ -24,12 +24,10 @@ impl TippingInterface for Pallet { amount: &Self::Balance, ) -> Result { let receiver = Self::tipping_account_id(); - let server_id = tips_balance_info.get_server_id(); let tip_amount = *amount; let ft_identifier = tips_balance_info.get_ft_identifier(); let tips_balance = TipsBalance::new(tips_balance_info, amount); - Self::do_server_exist(server_id, None)?; Self::do_transfer(ft_identifier, sender, &receiver, tip_amount)?; Self::do_store_tips_balance(&tips_balance, false, None); @@ -92,8 +90,6 @@ impl TippingInterface for Pallet { return Err(DispatchError::BadOrigin) } - Self::do_server_exist(server_id, Some(receiver))?; - let sender = Self::tipping_account_id(); let ref_id = ref_ids[0].clone(); let tips_balance_key = (server_id.clone(), ref_type, ref_id, b"native".to_vec()); diff --git a/pallets/tipping/src/lib.rs b/pallets/tipping/src/lib.rs index 4eea480..2d612d3 100644 --- a/pallets/tipping/src/lib.rs +++ b/pallets/tipping/src/lib.rs @@ -1,13 +1,12 @@ #![cfg_attr(not(feature = "std"), no_std)] +mod benchmarking; #[cfg(test)] mod mock; #[cfg(test)] mod tests; -pub use frame_support::traits::StorageVersion; pub use pallet::*; -pub use pallet_server::interface::{ServerInfo, ServerProvider}; pub use scale_info::{prelude::string::*, TypeInfo}; pub mod functions; @@ -21,8 +20,10 @@ pub use crate::interface::TippingInterface; pub use types::*; pub use weights::WeightInfo; +pub use frame_support::traits::StorageVersion; + /// The current storage version. -const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); +const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); #[frame_support::pallet] pub mod pallet { @@ -46,7 +47,6 @@ pub mod pallet { AssetId = AssetId, Balance = AssetBalance, >; - type Server: ServerProvider; type WeightInfo: WeightInfo; } @@ -61,7 +61,7 @@ pub mod pallet { pub(super) type TipsBalanceByReference = StorageNMap< _, ( - NMapKey, + NMapKey>, NMapKey, NMapKey, NMapKey, @@ -73,7 +73,7 @@ pub mod pallet { #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { /// Send tip success. [who, pot, (data, balance)] - SendTip(T::AccountId, T::AccountId, (TipsBalanceKey, BalanceOf)), + SendTip(T::AccountId, T::AccountId, (TipsBalanceKeyOf, BalanceOf)), /// Claim tip success [pot, (succeed, failed)] ClaimTip(T::AccountId, (AccountBalancesOf, Option>)), /// Claim reference success. [Vec] @@ -101,7 +101,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::send_tip())] pub fn send_tip( origin: OriginFor, - tips_balance_info: TipsBalanceInfo, + tips_balance_info: TipsBalanceInfoOf, amount: BalanceOf, ) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; @@ -115,7 +115,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::claim_tip())] pub fn claim_tip( origin: OriginFor, - server_id: ServerId, + server_id: ServerIdOf, reference_type: ReferenceType, reference_id: ReferenceId, ft_identifiers: Vec, @@ -140,7 +140,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::claim_reference())] pub fn claim_reference( origin: OriginFor, - server_id: ServerId, + server_id: ServerIdOf, references: References, main_references: References, ft_identifiers: Vec, @@ -148,6 +148,9 @@ pub mod pallet { tx_fee: BalanceOf, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; + + ensure!(who == server_id, Error::::Unauthorized); + let mut ft_identifiers = ft_identifiers; ft_identifiers.sort_unstable(); diff --git a/pallets/tipping/src/migrations.rs b/pallets/tipping/src/migrations.rs index 9976f7e..84464d5 100644 --- a/pallets/tipping/src/migrations.rs +++ b/pallets/tipping/src/migrations.rs @@ -1,5 +1,11 @@ -use crate::{Config, Pallet, TipsBalance, TipsBalanceByReference, TipsBalanceOf}; -use frame_support::{traits::Get, weights::Weight}; +use crate::{ + AccountIdOf, BalanceOf, Config, Pallet, TipsBalance, + TipsBalanceByReference as NewTipsBalanceByReference, TipsBalanceInfo, +}; +use frame_support::{ + generate_storage_alias, pallet_prelude::*, traits::Get, weights::Weight, Blake2_128Concat, +}; +use sp_std::vec::Vec; pub fn migrate() -> Weight { use frame_support::traits::StorageVersion; @@ -12,6 +18,11 @@ pub fn migrate() -> Weight { version = StorageVersion::new(1); } + if version == 1 { + weight = weight.saturating_add(version::v2::migrate::()); + version = StorageVersion::new(2); + } + version.put::>(); weight } @@ -22,36 +33,113 @@ mod version { pub mod v1 { use super::*; + pub fn migrate() -> Weight { + // TipsBalanceByReference::::translate_values(|tips_balance: TipsBalanceOf| { + // if tips_balance.get_server_id() == b"myriad" { + // weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); + + // let amount = *tips_balance.get_amount(); + // let new_tips_balance_info = + // tips_balance.get_tips_balance_info().clone().set_server_id(b"0"); + + // let mut new_tips_balance = TipsBalance::new(&new_tips_balance_info, &amount); + // let new_key = new_tips_balance.key(); + + // // Handle duplicate + // if let Some(tips_balance) = TipsBalanceByReference::::get(&new_key) { + // new_tips_balance.add_amount(*tips_balance.get_amount()); + // } + + // if let Some(account_id) = new_tips_balance.get_account_id().clone() { + // new_tips_balance.set_account_id(&account_id); + // } + + // TipsBalanceByReference::::insert(&new_key, new_tips_balance); + + // return None + // } + + // Some(tips_balance) + // }); + + T::DbWeight::get().writes(1) + } + } + + pub mod v2 { + use super::*; + pub fn migrate() -> Weight { let mut weight = T::DbWeight::get().writes(1); - TipsBalanceByReference::::translate_values(|tips_balance: TipsBalanceOf| { - if tips_balance.get_server_id() == b"myriad" { + pub type TipsBalanceOf = TipsBalance, AccountIdOf, Vec>; + pub type ServerOf = Server>; + + #[derive(Encode, Decode, Clone, Debug)] + pub struct Server { + id: u64, + owner: AccountId, + api_url: Vec, + } + impl Server { + pub fn get_owner(&self) -> &AccountId { + &self.owner + } + } + + generate_storage_alias!( + Server, + ServerById => Map<(Blake2_128Concat, u64), ServerOf> + ); + + generate_storage_alias!( + Tipping, + TipsBalanceByReference => NMap< + ((Vec, Vec, Vec, Vec), Blake2_128Concat), + TipsBalanceOf + > + ); + + if let Some(server) = ServerById::::get(0) { + let server_id = server.get_owner(); + + TipsBalanceByReference::::translate_values(|tips_balance: TipsBalanceOf| { weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); let amount = *tips_balance.get_amount(); - let new_tips_balance_info = - tips_balance.get_tips_balance_info().clone().set_server_id(b"0"); + let account_id = tips_balance.get_account_id(); + let tips_balance_info = tips_balance.get_tips_balance_info(); - let mut new_tips_balance = TipsBalance::new(&new_tips_balance_info, &amount); - let new_key = new_tips_balance.key(); + let old_server_id = tips_balance_info.get_server_id(); + let reference_type = tips_balance_info.get_reference_type(); + let reference_id = tips_balance_info.get_reference_id(); + let ft_identifier = tips_balance_info.get_ft_identifier(); - // Handle duplicate - if let Some(tips_balance) = TipsBalanceByReference::::get(&new_key) { - new_tips_balance.add_amount(*tips_balance.get_amount()); - } + let new_tips_balance_info = TipsBalanceInfo::new( + server_id, + reference_type, + reference_id, + ft_identifier, + ); + + let mut new_tips_balance = TipsBalance::new(&new_tips_balance_info, &amount); - if let Some(account_id) = new_tips_balance.get_account_id().clone() { - new_tips_balance.set_account_id(&account_id); + if let Some(account_id) = account_id { + new_tips_balance.set_account_id(account_id); } - TipsBalanceByReference::::insert(&new_key, new_tips_balance); + if old_server_id == b"0" { + NewTipsBalanceByReference::::insert( + new_tips_balance.key(), + new_tips_balance, + ); - return None - } + return None + } - Some(tips_balance) - }); + Some(tips_balance) + }); + } weight } diff --git a/pallets/tipping/src/mock.rs b/pallets/tipping/src/mock.rs index d99fbd7..5cda901 100644 --- a/pallets/tipping/src/mock.rs +++ b/pallets/tipping/src/mock.rs @@ -27,7 +27,6 @@ construct_runtime!( System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, Tipping: pallet_tipping::{Pallet, Call, Storage, Event}, - Server: pallet_server::{Pallet, Call, Storage, Event}, Assets: pallet_assets::{Pallet, Call, Storage, Event}, } ); @@ -90,16 +89,10 @@ impl pallet_tipping::Config for Test { type Call = Call; type Event = Event; type Currency = Balances; - type Server = Server; type Assets = Assets; type WeightInfo = (); } -impl pallet_server::Config for Test { - type Event = Event; - type WeightInfo = (); -} - pub type OctopusAssetId = u32; pub type OctopusAssetBalance = u128; diff --git a/pallets/tipping/src/tests.rs b/pallets/tipping/src/tests.rs index 38b94a3..e15444c 100644 --- a/pallets/tipping/src/tests.rs +++ b/pallets/tipping/src/tests.rs @@ -4,20 +4,16 @@ use frame_support::{assert_noop, assert_ok, dispatch::DispatchError, sp_runtime: #[test] fn send_tip_myria_works() { ::default().existential_deposit(2).build().execute_with(|| { - assert_ok!(Server::register( - Origin::signed(account_key("alice")), - b"https://api.dev.myriad.social".to_vec(), - )); - - let server_id = b"0"; - let tips_balance_info = TipsBalanceInfo::new(server_id, b"people", b"people_id", b"native"); + let server_id = account_key("alice"); + let tips_balance_info = + TipsBalanceInfo::new(&server_id, b"people", b"people_id", b"native"); let tips_balance = TipsBalance::new(&tips_balance_info, &1); assert_ok!(Tipping::send_tip(Origin::signed(account_key("bob")), tips_balance_info, 1)); assert_eq!( Tipping::tips_balance_by_reference(( - server_id.to_vec(), + &server_id, b"people".to_vec(), b"people_id".to_vec(), b"native".to_vec() @@ -32,21 +28,15 @@ fn send_tip_myria_works() { #[test] fn send_tip_assets_works() { ::default().existential_deposit(2).build().execute_with(|| { - assert_ok!(Server::register( - Origin::signed(account_key("alice")), - b"https://api.dev.myriad.social".to_vec(), - )); - - let server_id = b"0"; - let tips_balance_info = - TipsBalanceInfo::new(server_id, b"people", b"people_id", "1".as_bytes()); + let server_id = account_key("alice"); + let tips_balance_info = TipsBalanceInfo::new(&server_id, b"people", b"people_id", b"1"); let tips_balance = TipsBalance::new(&tips_balance_info, &1); assert_ok!(Tipping::send_tip(Origin::signed(account_key("bob")), tips_balance_info, 1)); assert_eq!( Tipping::tips_balance_by_reference(( - server_id.to_vec(), + &server_id, b"people".to_vec(), b"people_id".to_vec(), "1".as_bytes().to_vec() @@ -61,29 +51,22 @@ fn send_tip_assets_works() { #[test] fn claim_reference_works() { ::default().existential_deposit(2).build().execute_with(|| { - assert_ok!(Server::register( - Origin::signed(account_key("alice")), - b"https://api.dev.myriad.social".to_vec(), - )); - - let server_id = b"0"; + let server_id = account_key("alice"); let tips_balance_info_0 = - TipsBalanceInfo::new(server_id, b"people", b"people_id", b"native"); - let tips_balance_info_1 = - TipsBalanceInfo::new(server_id, b"people", b"people_id", "1".as_bytes()); - let tips_balance_info_2 = - TipsBalanceInfo::new(server_id, b"people", b"people_id", "2".as_bytes()); + TipsBalanceInfo::new(&server_id, b"people", b"people_id", b"native"); + let tips_balance_info_1 = TipsBalanceInfo::new(&server_id, b"people", b"people_id", b"1"); + let tips_balance_info_2 = TipsBalanceInfo::new(&server_id, b"people", b"people_id", b"2"); let mut tips_balance_0 = TipsBalance::new(&tips_balance_info_0, &1); let mut tips_balance_1 = TipsBalance::new(&tips_balance_info_1, &1); let mut tips_balance_2 = TipsBalance::new(&tips_balance_info_2, &2); let main_tips_balance_info_0 = - TipsBalanceInfo::new(server_id, b"user", b"user_id", b"native"); + TipsBalanceInfo::new(&server_id, b"user", b"user_id", b"native"); - let main_tips_balance_info_1 = TipsBalanceInfo::new(server_id, b"user", b"user_id", b"1"); + let main_tips_balance_info_1 = TipsBalanceInfo::new(&server_id, b"user", b"user_id", b"1"); - let main_tips_balance_info_2 = TipsBalanceInfo::new(server_id, b"user", b"user_id", b"2"); + let main_tips_balance_info_2 = TipsBalanceInfo::new(&server_id, b"user", b"user_id", b"2"); let mut main_tips_balance_0 = TipsBalance::new(&main_tips_balance_info_0, &1); let mut main_tips_balance_1 = TipsBalance::new(&main_tips_balance_info_1, &1); @@ -101,7 +84,7 @@ fn claim_reference_works() { assert_ok!(Tipping::claim_reference( Origin::signed(account_key("alice")), - server_id.to_vec(), + server_id, References::new(b"people", &[b"people_id".to_vec()]), References::new(b"user", &[b"user_id".to_vec()]), vec![b"native".to_vec(), b"1".to_vec(), b"2".to_vec()], @@ -118,7 +101,7 @@ fn claim_reference_works() { assert_eq!( Tipping::tips_balance_by_reference(( - server_id.to_vec(), + server_id, b"people".to_vec(), b"people_id".to_vec(), b"native".to_vec() @@ -128,7 +111,7 @@ fn claim_reference_works() { assert_eq!( Tipping::tips_balance_by_reference(( - server_id.to_vec(), + server_id, b"people".to_vec(), b"people_id".to_vec(), b"1".to_vec() @@ -138,7 +121,7 @@ fn claim_reference_works() { assert_eq!( Tipping::tips_balance_by_reference(( - server_id.to_vec(), + server_id, b"people".to_vec(), b"people_id".to_vec(), b"2".to_vec() @@ -148,7 +131,7 @@ fn claim_reference_works() { assert_eq!( Tipping::tips_balance_by_reference(( - server_id.to_vec(), + server_id, b"user".to_vec(), b"user_id".to_vec(), b"native".to_vec() @@ -158,7 +141,7 @@ fn claim_reference_works() { assert_eq!( Tipping::tips_balance_by_reference(( - server_id.to_vec(), + server_id, b"user".to_vec(), b"user_id".to_vec(), b"1".to_vec() @@ -168,7 +151,7 @@ fn claim_reference_works() { assert_eq!( Tipping::tips_balance_by_reference(( - server_id.to_vec(), + server_id, b"user".to_vec(), b"user_id".to_vec(), b"2".to_vec() @@ -183,21 +166,14 @@ fn claim_reference_works() { #[test] pub fn claim_tip_works() { ::default().existential_deposit(2).build().execute_with(|| { - assert_ok!(Server::register( - Origin::signed(account_key("alice")), - b"https://api.dev.myriad.social".to_vec(), - )); - - let server_id = b"0"; + let server_id = account_key("alice"); let tips_balance_info_0 = - TipsBalanceInfo::new(server_id, b"people", b"people_id", b"native"); - let tips_balance_info_1 = - TipsBalanceInfo::new(server_id, b"people", b"people_id", "1".as_bytes()); - let tips_balance_info_2 = - TipsBalanceInfo::new(server_id, b"people", b"people_id", "2".as_bytes()); + TipsBalanceInfo::new(&server_id, b"people", b"people_id", b"native"); + let tips_balance_info_1 = TipsBalanceInfo::new(&server_id, b"people", b"people_id", b"1"); + let tips_balance_info_2 = TipsBalanceInfo::new(&server_id, b"people", b"people_id", b"2"); let main_tips_balance_info_0 = - TipsBalanceInfo::new(server_id, b"user", b"user_id", b"native"); + TipsBalanceInfo::new(&server_id, b"user", b"user_id", b"native"); assert_ok!(Tipping::send_tip(Origin::signed(account_key("bob")), tips_balance_info_0, 1)); assert_ok!(Tipping::send_tip(Origin::signed(account_key("bob")), tips_balance_info_1, 1)); @@ -210,7 +186,7 @@ pub fn claim_tip_works() { assert_ok!(Tipping::claim_reference( Origin::signed(account_key("alice")), - server_id.to_vec(), + server_id, References::new(b"people", &[b"people_id".to_vec()]), References::new(b"user", &[b"user_id".to_vec()]), vec![b"native".to_vec(), b"1".to_vec(), b"2".to_vec()], @@ -220,7 +196,7 @@ pub fn claim_tip_works() { assert_ok!(Tipping::claim_tip( Origin::signed(account_key("john")), - server_id.to_vec(), + server_id, b"user".to_vec(), b"user_id".to_vec(), vec![b"native".to_vec(), b"1".to_vec(), b"2".to_vec()] @@ -234,104 +210,27 @@ pub fn claim_tip_works() { } #[test] -fn cant_send_tip_myria_when_server_not_register() { - ::default().existential_deposit(2).build().execute_with(|| { - let tips_balance_info = TipsBalanceInfo::new(b"0", b"people", b"people_id", b"native"); - - assert_noop!( - Tipping::send_tip(Origin::signed(account_key("alice")), tips_balance_info, 1), - Error::::ServerNotRegister - ); - }) -} - -#[test] -fn cant_send_tip_myria_when_server_id_is_wrong_format() { +fn cant_claim_reference() { ::default().existential_deposit(2).build().execute_with(|| { - let tips_balance_info = TipsBalanceInfo::new(b"myriad", b"people", b"people_id", b"native"); - - assert_noop!( - Tipping::send_tip(Origin::signed(account_key("alice")), tips_balance_info, 1), - Error::::WrongFormat - ); - }) -} + let server_id = account_key("alice"); -#[test] -fn cant_claim_reference_when_server_not_registered() { - ::default().existential_deposit(2).build().execute_with(|| { assert_noop!( Tipping::claim_reference( Origin::signed(account_key("alice")), - b"1".to_vec(), + account_key("bob"), References::new(b"people", &[b"people_id".to_vec()]), References::new(b"user", &[b"user_id".to_vec()]), vec![b"native".to_vec()], account_key("john"), 1, ), - Error::::ServerNotRegister, - ); - }) -} - -#[test] -fn cant_claim_reference_when_server_id_is_wrong_format() { - ::default().existential_deposit(2).build().execute_with(|| { - assert_noop!( - Tipping::claim_reference( - Origin::signed(account_key("alice")), - b"1".to_vec(), - References::new(b"people", &[b"people_id".to_vec()]), - References::new(b"user", &[b"user_id".to_vec()]), - vec![b"native".to_vec()], - account_key("john"), - 1, - ), - Error::::ServerNotRegister, - ); - }) -} - -#[test] -fn cant_claim_reference_when_not_as_server_owner() { - ::default().existential_deposit(2).build().execute_with(|| { - assert_ok!(Server::register( - Origin::signed(account_key("alice")), - b"https://api.dev.myriad.social".to_vec(), - )); - - let server_id = b"0".to_vec(); - - assert_noop!( - Tipping::claim_reference( - Origin::signed(account_key("john")), - server_id, - References::new(b"people", &[b"people_id".to_vec()]), - References::new(b"user", &[b"user_id".to_vec()]), - vec![b"native".to_vec()], - account_key("alice"), - 1, - ), Error::::Unauthorized, ); - }) -} - -#[test] -fn cant_claim_reference() { - ::default().existential_deposit(2).build().execute_with(|| { - assert_ok!(Server::register( - Origin::signed(account_key("alice")), - b"https://api.dev.myriad.social".to_vec(), - )); - - let server_id = b"0"; assert_noop!( Tipping::claim_reference( Origin::signed(account_key("alice")), - server_id.to_vec(), + server_id, References::new(b"people", &[b"people_id".to_vec()]), References::new(b"user", &[b"user_id".to_vec()]), vec![b"native".to_vec()], @@ -344,7 +243,7 @@ fn cant_claim_reference() { assert_noop!( Tipping::claim_reference( Origin::signed(account_key("alice")), - server_id.to_vec(), + server_id, References::new(b"people", &[b"people_id".to_vec()]), References::new(b"user", &[b"user_id".to_vec()]), vec![b"native".to_vec()], @@ -357,7 +256,7 @@ fn cant_claim_reference() { assert_noop!( Tipping::claim_reference( Origin::signed(account_key("alice")), - server_id.to_vec(), + server_id, References::new(b"people", &[b"people_id".to_vec()]), References::new(b"user", &[b"user_id".to_vec(), b"user_idd".to_vec()]), vec![b"native".to_vec()], @@ -370,7 +269,7 @@ fn cant_claim_reference() { assert_noop!( Tipping::claim_reference( Origin::signed(account_key("alice")), - server_id.to_vec(), + server_id, References::new(b"people", &[b"people_id".to_vec()]), References::new(b"user", &[b"user_id".to_vec()]), vec![b"native".to_vec()], @@ -381,7 +280,7 @@ fn cant_claim_reference() { ); let main_tips_balance_info = - TipsBalanceInfo::new(server_id, b"user", b"user_id", b"native"); + TipsBalanceInfo::new(&server_id, b"user", b"user_id", b"native"); assert_ok!(Tipping::send_tip( Origin::signed(account_key("bob")), @@ -392,7 +291,7 @@ fn cant_claim_reference() { assert_noop!( Tipping::claim_reference( Origin::signed(account_key("alice")), - server_id.to_vec(), + server_id, References::new(b"people", &[b"people_id".to_vec()]), References::new(b"user", &[b"user_id".to_vec()]), vec![b"native".to_vec()], @@ -411,7 +310,7 @@ fn cant_claim_reference() { assert_noop!( Tipping::claim_reference( Origin::signed(account_key("alice")), - server_id.to_vec(), + server_id, References::new(b"people", &[b"people_id".to_vec()]), References::new(b"user", &[b"user_id".to_vec()]), vec![b"native".to_vec()], @@ -426,13 +325,9 @@ fn cant_claim_reference() { #[test] fn call_event_should_work() { ::default().existential_deposit(2).build().execute_with(|| { - assert_ok!(Server::register( - Origin::signed(account_key("alice")), - b"https://api.dev.myriad.social".to_vec(), - )); - - let server_id = b"0"; - let tips_balance_info = TipsBalanceInfo::new(server_id, b"people", b"people_id", b"native"); + let server_id = account_key("alice"); + let tips_balance_info = + TipsBalanceInfo::new(&server_id, b"people", b"people_id", b"native"); let tips_balance_key = tips_balance_info.key(); assert_ok!(Tipping::send_tip(Origin::signed(account_key("bob")), tips_balance_info, 1)); @@ -446,7 +341,7 @@ fn call_event_should_work() { ))); let main_tips_balance_info = - TipsBalanceInfo::new(server_id, b"user", b"user_id", b"native"); + TipsBalanceInfo::new(&server_id, b"user", b"user_id", b"native"); assert_ok!(Tipping::send_tip( Origin::signed(account_key("bob")), @@ -456,7 +351,7 @@ fn call_event_should_work() { assert_ok!(Tipping::claim_reference( Origin::signed(account_key("alice")), - server_id.to_vec(), + server_id, References::new(b"people", &[b"people_id".to_vec()]), References::new(b"user", &[b"user_id".to_vec()]), vec![b"native".to_vec()], @@ -473,7 +368,7 @@ fn call_event_should_work() { ]))); let main_tips_balance_info = - TipsBalanceInfo::new(server_id, b"user", b"user_id", b"native"); + TipsBalanceInfo::new(&server_id, b"user", b"user_id", b"native"); assert_ok!(Tipping::send_tip( Origin::signed(account_key("bob")), @@ -483,7 +378,7 @@ fn call_event_should_work() { assert_ok!(Tipping::claim_tip( Origin::signed(account_key("john")), - server_id.to_vec(), + server_id, b"user".to_vec(), b"user_id".to_vec(), vec![b"native".to_vec()], diff --git a/pallets/tipping/src/types.rs b/pallets/tipping/src/types.rs index 128d840..af7a82a 100644 --- a/pallets/tipping/src/types.rs +++ b/pallets/tipping/src/types.rs @@ -4,13 +4,12 @@ use frame_support::{pallet_prelude::*, sp_runtime::traits::Saturating, traits::C use scale_info::TypeInfo; use sp_std::vec::Vec; -pub type ServerId = Vec; pub type FtIdentifier = Vec; pub type ReferenceId = Vec; pub type ReferenceType = Vec; -pub type TipsBalanceKey = (ServerId, ReferenceType, ReferenceId, FtIdentifier); -pub type TipsBalanceTuppleOf = (TipsBalanceKey, BalanceOf); +pub type TipsBalanceKey = (ServerId, ReferenceType, ReferenceId, FtIdentifier); +pub type TipsBalanceTuppleOf = (TipsBalanceKeyOf, BalanceOf); pub type AccountBalancesOf = Vec<(FtIdentifier, AccountIdOf, BalanceOf)>; pub type AccountBalancesTuppleOf = (AccountBalancesOf, Option>); @@ -19,22 +18,26 @@ pub type AssetId = u32; pub type AssetBalance = u128; pub type AccountIdOf = ::AccountId; +pub type ServerIdOf = AccountIdOf; pub type CurrencyOf = ::Currency; pub type BalanceOf = as Currency>>::Balance; -pub type TipsBalanceOf = TipsBalance, AccountIdOf>; +pub type TipsBalanceOf = TipsBalance, AccountIdOf, ServerIdOf>; +pub type TipsBalanceInfoOf = TipsBalanceInfo>; +pub type TipsBalanceKeyOf = TipsBalanceKey>; #[derive(Encode, Decode, Clone, Default, RuntimeDebug, PartialEq, Eq, TypeInfo)] -pub struct TipsBalance { - tips_balance_info: TipsBalanceInfo, +pub struct TipsBalance { + tips_balance_info: TipsBalanceInfo, account_id: Option, amount: Balance, } -impl TipsBalance +impl TipsBalance where Balance: Clone + Saturating, AccountId: Clone, + ServerId: Clone, { - pub fn new(tips_balance_info: &TipsBalanceInfo, amount: &Balance) -> Self { + pub fn new(tips_balance_info: &TipsBalanceInfo, amount: &Balance) -> Self { Self { tips_balance_info: tips_balance_info.clone(), account_id: None, @@ -42,11 +45,11 @@ where } } - pub fn key(&self) -> TipsBalanceKey { + pub fn key(&self) -> TipsBalanceKey { self.tips_balance_info.key() } - pub fn get_tips_balance_info(&self) -> &TipsBalanceInfo { + pub fn get_tips_balance_info(&self) -> &TipsBalanceInfo { &self.tips_balance_info } @@ -54,7 +57,7 @@ where &self.amount } - pub fn get_server_id(&self) -> &Vec { + pub fn get_server_id(&self) -> &ServerId { self.tips_balance_info.get_server_id() } @@ -74,7 +77,7 @@ where &self.account_id } - pub fn set_tips_balance_info(&mut self, tips_balance_info: &TipsBalanceInfo) { + pub fn set_tips_balance_info(&mut self, tips_balance_info: &TipsBalanceInfo) { self.tips_balance_info = tips_balance_info.clone(); } @@ -92,28 +95,28 @@ where } #[derive(Encode, Decode, Clone, Default, RuntimeDebug, PartialEq, Eq, TypeInfo)] -pub struct TipsBalanceInfo { - server_id: Vec, +pub struct TipsBalanceInfo { + server_id: ServerId, reference_type: Vec, reference_id: Vec, ft_identifier: Vec, } -impl TipsBalanceInfo { +impl TipsBalanceInfo { pub fn new( - server_id: &[u8], + server_id: &ServerId, reference_type: &[u8], reference_id: &[u8], ft_identifier: &[u8], ) -> Self { Self { - server_id: server_id.to_vec(), + server_id: server_id.clone(), reference_type: reference_type.to_vec(), reference_id: reference_id.to_vec(), ft_identifier: ft_identifier.to_vec(), } } - pub fn key(&self) -> TipsBalanceKey { + pub fn key(&self) -> TipsBalanceKey { ( self.server_id.clone(), self.reference_type.clone(), @@ -130,7 +133,7 @@ impl TipsBalanceInfo { &self.reference_type } - pub fn get_server_id(&self) -> &Vec { + pub fn get_server_id(&self) -> &ServerId { &self.server_id } @@ -138,8 +141,8 @@ impl TipsBalanceInfo { &self.ft_identifier } - pub fn set_server_id(mut self, server_id: &[u8]) -> Self { - self.server_id = server_id.to_vec(); + pub fn set_server_id(mut self, server_id: &ServerId) -> Self { + self.server_id = server_id.clone(); self } @@ -170,15 +173,3 @@ impl References { &self.reference_ids } } - -#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo)] -pub enum Status { - OnProgress, - Success, - Failed, -} -impl Default for Status { - fn default() -> Self { - Status::OnProgress - } -} diff --git a/pallets/tipping/src/weights.rs b/pallets/tipping/src/weights.rs index fb33c19..4d61f2b 100644 --- a/pallets/tipping/src/weights.rs +++ b/pallets/tipping/src/weights.rs @@ -1,7 +1,7 @@ //! Autogenerated weights for pallet_tipping //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-09-02, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-09-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -35,26 +35,24 @@ pub trait WeightInfo { /// Weights for pallet_tipping using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Server ServerById (r:1 w:0) // Storage: System Account (r:1 w:0) // Storage: Tipping TipsBalanceByReference (r:1 w:1) fn send_tip() -> Weight { - 79_200_000_u64 - .saturating_add(T::DbWeight::get().reads(3_u64)) + 122_100_000_u64 + .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Server ServerById (r:1 w:0) // Storage: Tipping TipsBalanceByReference (r:2 w:2) // Storage: System Account (r:1 w:1) fn claim_reference() -> Weight { - 127_600_000_u64 - .saturating_add(T::DbWeight::get().reads(4_u64)) + 165_100_000_u64 + .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: Tipping TipsBalanceByReference (r:1 w:1) // Storage: System Account (r:1 w:1) fn claim_tip() -> Weight { - 93_800_000_u64 + 107_400_000_u64 .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -62,26 +60,24 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Server ServerById (r:1 w:0) // Storage: System Account (r:1 w:0) // Storage: Tipping TipsBalanceByReference (r:1 w:1) fn send_tip() -> Weight { - 79_200_000_u64 - .saturating_add(RocksDbWeight::get().reads(3_u64)) + 122_100_000_u64 + .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Server ServerById (r:1 w:0) // Storage: Tipping TipsBalanceByReference (r:2 w:2) // Storage: System Account (r:1 w:1) fn claim_reference() -> Weight { - 127_600_000_u64 - .saturating_add(RocksDbWeight::get().reads(4_u64)) + 165_100_000_u64 + .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: Tipping TipsBalanceByReference (r:1 w:1) // Storage: System Account (r:1 w:1) fn claim_tip() -> Weight { - 93_800_000_u64 + 107_400_000_u64 .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 2a5cea6..10ba66e 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'myriad-runtime' -version = '2.1.8' +version = '2.1.9' edition = '2021' license = 'AGPL-3.0' authors = ['Myriad Dev Team '] @@ -73,7 +73,6 @@ pallet-octopus-upward-messages = { git = 'https://github.com/octopus-network/oct # Local Pallet pallet-server = { path = '../pallets/server', default-features = false } pallet-tipping = { path = '../pallets/tipping', default-features = false } -pallet-tipping-benchmarking = { path = '../pallets/tipping/benchmarking', default-features = false, optional = true } [features] default = ['std'] @@ -152,5 +151,4 @@ runtime-benchmarks = [ # Local Pallet 'pallet-server/runtime-benchmarks', 'pallet-tipping/runtime-benchmarks', - 'pallet-tipping-benchmarking', ] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 33313b5..2864d61 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -125,7 +125,7 @@ mod benches { define_benchmarks!( [frame_benchmarking, BaselineBench::] [frame_system, SystemBench::] - [pallet_tipping, TippingBench::] + [pallet_tipping, Tipping] [pallet_server, Server] ); } @@ -188,7 +188,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 2018, + spec_version: 2019, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -702,7 +702,6 @@ impl pallet_tipping::Config for Runtime { type Event = Event; type Currency = Balances; type Assets = OctopusAssets; - type Server = Server; type WeightInfo = (); } @@ -935,7 +934,6 @@ impl_runtime_apis! { use frame_benchmarking::{baseline, Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; - use pallet_tipping_benchmarking::Pallet as TippingBench; use baseline::Pallet as BaselineBench; let mut list = Vec::::new(); @@ -953,11 +951,9 @@ impl_runtime_apis! { use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch, TrackedStorageKey}; use frame_system_benchmarking::Pallet as SystemBench; - use pallet_tipping_benchmarking::Pallet as TippingBench; use baseline::Pallet as BaselineBench; impl frame_system_benchmarking::Config for Runtime {} - impl pallet_tipping_benchmarking::Config for Runtime {} impl baseline::Config for Runtime {} let whitelist: Vec = vec![