Browse Source

runtime: Upgrade recurring reward module.

Shamil Gadelshin 4 years ago
parent
commit
d8bc65997a

File diff suppressed because it is too large
+ 910 - 5797
Cargo.lock


+ 20 - 20
Cargo.toml

@@ -1,26 +1,26 @@
 [workspace]
 members = [
-	"runtime",
-	"runtime-modules/proposals/engine",
-	"runtime-modules/proposals/codex",
-	"runtime-modules/proposals/discussion",
-	"runtime-modules/common",
-	"runtime-modules/content-working-group",
-	"runtime-modules/forum",
-	"runtime-modules/governance",
-	"runtime-modules/hiring",
-	"runtime-modules/membership",
-	"runtime-modules/memo",
+#	"runtime",
+#	"runtime-modules/proposals/engine",
+#	"runtime-modules/proposals/codex",
+#	"runtime-modules/proposals/discussion",
+#	"runtime-modules/common",
+#	"runtime-modules/content-working-group",
+#	"runtime-modules/forum",
+#	"runtime-modules/governance",
+#	"runtime-modules/hiring",
+#	"runtime-modules/membership",
+#	"runtime-modules/memo",
 	"runtime-modules/recurring-reward",
-	"runtime-modules/service-discovery",
-	"runtime-modules/stake",
-	"runtime-modules/storage",
-#	"runtime-modules/token-minting",
-	"runtime-modules/versioned-store",
-	"runtime-modules/versioned-store-permissions",
-	"runtime-modules/working-group",
-	"node",
-	"utils/chain-spec-builder/"
+#	"runtime-modules/service-discovery",
+#	"runtime-modules/stake",
+#	"runtime-modules/storage",
+	"runtime-modules/token-minting",
+#	"runtime-modules/versioned-store",
+#	"runtime-modules/versioned-store-permissions",
+#	"runtime-modules/working-group",
+#	"node",
+#	"utils/chain-spec-builder/"
 ]
 
 [profile.release]

+ 17 - 39
runtime-modules/recurring-reward/Cargo.toml

@@ -1,56 +1,34 @@
 [package]
-name = 'substrate-recurring-reward-module'
-version = '1.0.1'
+name = 'pallet-recurring-reward'
+version = '3.0.0'
 authors = ['Joystream contributors']
 edition = '2018'
 
 [dependencies]
-hex-literal = '0.1.0'
-serde = { version = '1.0', optional = true }
-serde_derive = { version = '1.0', optional = true }
-rstd = { package = 'sr-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-runtime-primitives = { package = 'sr-primitives', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-srml-support = { package = 'srml-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-srml-support-procedural = { package = 'srml-support-procedural', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-system = { package = 'srml-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-balances = { package = 'srml-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-codec = { package = 'parity-scale-codec', version = '1.0.0', default-features = false, features = ['derive'] }
-# https://users.rust-lang.org/t/failure-derive-compilation-error/39062
-quote = '<=1.0.2'
-
-[dependencies.timestamp]
-default_features = false
-git = 'https://github.com/paritytech/substrate.git'
-package = 'srml-timestamp'
-rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
-
-[dependencies.runtime-io]
-default_features = false
-git = 'https://github.com/paritytech/substrate.git'
-package = 'sr-io'
-rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
-
-[dependencies.minting]
-default_features = false
-package = 'substrate-token-mint-module'
-path = '../token-minting'
+codec = { package = 'parity-scale-codec', version = '1.3.1', default-features = false, features = ['derive'] }
+rstd = { package = 'sp-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+system = { package = 'frame-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+timestamp = { package = 'sp-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+minting = { package = 'pallet-token-mint', default-features = false, path = '../token-minting'}
 
 [dev-dependencies]
-runtime-io = { package = 'sr-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-primitives = { package = 'substrate-primitives', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
+sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+
 
 [features]
 default = ['std']
 std = [
-	'serde',
-	'serde_derive',
 	'codec/std',
 	'rstd/std',
-	'runtime-io/std',
-	'runtime-primitives/std',
-	'srml-support/std',
+	'sp-arithmetic/std',
+	'sp-runtime/std',
+	'frame-support/std',
 	'system/std',
-  	'balances/std',
 	'timestamp/std',
 	'minting/std',
 ]

+ 19 - 15
runtime-modules/recurring-reward/src/lib.rs

@@ -7,11 +7,13 @@
 
 // Ensure we're `no_std` when compiling for Wasm.
 #![cfg_attr(not(feature = "std"), no_std)]
-use rstd::prelude::*;
 
 use codec::{Codec, Decode, Encode};
-use runtime_primitives::traits::{MaybeSerialize, Member, One, SimpleArithmetic, Zero};
-use srml_support::{decl_module, decl_storage, ensure, Parameter};
+use frame_support::storage::IterableStorageMap;
+use frame_support::{decl_module, decl_storage, ensure, Parameter};
+use rstd::prelude::*;
+use sp_arithmetic::traits::{BaseArithmetic, One, Zero};
+use sp_runtime::traits::{MaybeSerialize, Member};
 
 use minting::{self, BalanceOf};
 
@@ -24,7 +26,7 @@ pub trait Trait: system::Trait + minting::Trait {
     /// Type of identifier for recipients.
     type RecipientId: Parameter
         + Member
-        + SimpleArithmetic
+        + BaseArithmetic
         + Codec
         + Default
         + Copy
@@ -34,7 +36,7 @@ pub trait Trait: system::Trait + minting::Trait {
     /// Type for identifier for relationship representing that a recipient recieves recurring reward from a token mint
     type RewardRelationshipId: Parameter
         + Member
-        + SimpleArithmetic
+        + BaseArithmetic
         + Codec
         + Default
         + Copy
@@ -142,13 +144,15 @@ impl<AccountId: Clone, Balance: Clone, BlockNumber: Clone, MintId: Clone, Recipi
 
 decl_storage! {
     trait Store for Module<T: Trait> as RecurringReward {
-        Recipients get(recipients): linked_map T::RecipientId => Recipient<BalanceOf<T>>;
+        Recipients get(fn recipients): map hasher(blake2_128_concat)
+            T::RecipientId => Recipient<BalanceOf<T>>;
 
-        RecipientsCreated get(recipients_created): T::RecipientId;
+        RecipientsCreated get(fn recipients_created): T::RecipientId;
 
-        pub RewardRelationships get(reward_relationships): linked_map T::RewardRelationshipId => RewardRelationship<T::AccountId, BalanceOf<T>, T::BlockNumber, T::MintId, T::RecipientId>;
+        pub RewardRelationships get(fn reward_relationships): map hasher(blake2_128_concat)
+            T::RewardRelationshipId => RewardRelationship<T::AccountId, BalanceOf<T>, T::BlockNumber, T::MintId, T::RecipientId>;
 
-        RewardRelationshipsCreated get(reward_relationships_created): T::RewardRelationshipId;
+        RewardRelationshipsCreated get(fn reward_relationships_created): T::RewardRelationshipId;
     }
 }
 
@@ -192,7 +196,7 @@ impl<T: Trait> Module<T> {
             RewardsError::RewardSourceNotFound
         );
         ensure!(
-            <Recipients<T>>::exists(recipient),
+            <Recipients<T>>::contains_key(recipient),
             RewardsError::RecipientNotFound
         );
         ensure!(
@@ -220,7 +224,7 @@ impl<T: Trait> Module<T> {
 
     /// Removes a relationship from RewardRelashionships and its recipient.
     pub fn remove_reward_relationship(id: T::RewardRelationshipId) {
-        if <RewardRelationships<T>>::exists(&id) {
+        if <RewardRelationships<T>>::contains_key(&id) {
             <Recipients<T>>::remove(<RewardRelationships<T>>::take(&id).recipient);
         }
     }
@@ -282,7 +286,7 @@ impl<T: Trait> Module<T> {
         new_payout_interval: Option<Option<T::BlockNumber>>,
     ) -> Result<(), RewardsError> {
         ensure!(
-            <RewardRelationships<T>>::exists(&id),
+            <RewardRelationships<T>>::contains_key(&id),
             RewardsError::RewardRelationshipNotFound
         );
 
@@ -320,8 +324,8 @@ impl<T: Trait> Module<T> {
     Otherwise, analogous steps for failure.
     */
     fn do_payouts(now: T::BlockNumber) {
-        for (relationship_id, ref mut relationship) in <RewardRelationships<T>>::enumerate() {
-            assert!(<Recipients<T>>::exists(&relationship.recipient));
+        for (relationship_id, ref mut relationship) in <RewardRelationships<T>>::iter() {
+            assert!(<Recipients<T>>::contains_key(&relationship.recipient));
 
             let mut recipient = Self::recipients(relationship.recipient);
 
@@ -394,7 +398,7 @@ impl<T: Trait> Module<T> {
         RewardRelationship<T::AccountId, BalanceOf<T>, T::BlockNumber, T::MintId, T::RecipientId>,
         (),
     > {
-        ensure!(RewardRelationships::<T>::exists(id), ());
+        ensure!(RewardRelationships::<T>::contains_key(id), ());
 
         let relationship = RewardRelationships::<T>::get(id);
 

+ 16 - 18
runtime-modules/recurring-reward/src/mock/mod.rs

@@ -1,18 +1,16 @@
 #![cfg(test)]
 
-// use crate::*;
 use crate::{Module, Trait};
 
-use primitives::H256;
-
 use balances;
+use frame_support::{impl_outer_origin, parameter_types};
 use minting;
-use runtime_primitives::{
+use sp_core::H256;
+use sp_runtime::{
     testing::Header,
     traits::{BlakeTwo256, IdentityLookup},
     Perbill,
 };
-use srml_support::{impl_outer_origin, parameter_types};
 
 mod status_handler;
 pub use status_handler::MockStatusHandler;
@@ -33,10 +31,11 @@ parameter_types! {
 }
 
 impl system::Trait for Test {
+    type BaseCallFilter = ();
     type Origin = Origin;
+    type Call = ();
     type Index = u64;
     type BlockNumber = u64;
-    type Call = ();
     type Hash = H256;
     type Hashing = BlakeTwo256;
     type AccountId = u64;
@@ -45,9 +44,17 @@ impl system::Trait for Test {
     type Event = ();
     type BlockHashCount = BlockHashCount;
     type MaximumBlockWeight = MaximumBlockWeight;
+    type DbWeight = ();
+    type BlockExecutionWeight = ();
+    type ExtrinsicBaseWeight = ();
+    type MaximumExtrinsicWeight = ();
     type MaximumBlockLength = MaximumBlockLength;
     type AvailableBlockRatio = AvailableBlockRatio;
     type Version = ();
+    type ModuleToIndex = ();
+    type AccountData = balances::AccountData<u64>;
+    type OnNewAccount = ();
+    type OnKilledAccount = ();
 }
 
 parameter_types! {
@@ -60,20 +67,11 @@ parameter_types! {
 }
 
 impl balances::Trait for Test {
-    /// The type for recording an account's balance.
     type Balance = u64;
-    /// What to do if an account's free balance gets zeroed.
-    type OnFreeBalanceZero = ();
-    /// What to do if a new account is created.
-    type OnNewAccount = ();
-    /// The ubiquitous event type.
-    type Event = ();
-
     type DustRemoval = ();
-    type TransferPayment = ();
+    type Event = ();
     type ExistentialDeposit = ExistentialDeposit;
-    type TransferFee = TransferFee;
-    type CreationFee = CreationFee;
+    type AccountStore = System;
 }
 
 impl Trait for Test {
@@ -87,7 +85,7 @@ impl minting::Trait for Test {
     type MintId = u64;
 }
 
-pub fn build_test_externalities() -> runtime_io::TestExternalities {
+pub fn build_test_externalities() -> sp_io::TestExternalities {
     MockStatusHandler::reset();
 
     let t = system::GenesisConfig::default()

+ 4 - 4
runtime-modules/recurring-reward/src/tests.rs

@@ -2,7 +2,7 @@
 
 use super::*;
 use crate::mock::*;
-use srml_support::traits::Currency;
+use frame_support::traits::Currency;
 
 fn create_new_mint_with_capacity(capacity: u64) -> u64 {
     let mint_id = Minting::add_mint(capacity, None).ok().unwrap();
@@ -15,9 +15,9 @@ fn create_new_mint_with_capacity(capacity: u64) -> u64 {
 fn adding_recipients() {
     build_test_externalities().execute_with(|| {
         let next_id = Rewards::recipients_created();
-        assert!(!<Recipients<Test>>::exists(&next_id));
+        assert!(!<Recipients<Test>>::contains_key(&next_id));
         let recipient_id = Rewards::add_recipient();
-        assert!(<Recipients<Test>>::exists(&next_id));
+        assert!(<Recipients<Test>>::contains_key(&next_id));
         assert_eq!(recipient_id, next_id);
         assert_eq!(Rewards::recipients_created(), next_id + 1);
     });
@@ -49,7 +49,7 @@ fn adding_relationships() {
             Rewards::reward_relationships_created(),
             next_relationship_id + 1
         );
-        assert!(<RewardRelationships<Test>>::exists(&relationship_id));
+        assert!(<RewardRelationships<Test>>::contains_key(&relationship_id));
         let relationship = Rewards::reward_relationships(&relationship_id);
         assert_eq!(relationship.next_payment_at_block, Some(next_payment_at));
         assert_eq!(relationship.amount_per_payout, payout);

Some files were not shown because too many files changed in this diff