Parcourir la source

Upgrade pallet token-mint to the latest Substrate version.

Shamil Gadelshin il y a 4 ans
Parent
commit
bc0dd14a19

Fichier diff supprimé car celui-ci est trop grand
+ 644 - 37
Cargo.lock


+ 1 - 1
Cargo.toml

@@ -15,7 +15,7 @@ members = [
 	"runtime-modules/service-discovery",
 	"runtime-modules/stake",
 	"runtime-modules/storage",
-	"runtime-modules/token-minting",
+#	"runtime-modules/token-minting",
 	"runtime-modules/versioned-store",
 	"runtime-modules/versioned-store-permissions",
 	"runtime-modules/working-group",

+ 15 - 34
runtime-modules/token-minting/Cargo.toml

@@ -1,50 +1,31 @@
 [package]
-name = 'substrate-token-mint-module'
-version = '1.0.1'
+name = 'pallet-token-mint'
+version = '3.0.0'
 authors = ['Joystream contributors']
 edition = '2018'
 
 [dependencies]
-hex-literal = '0.1.0'
-serde = { version = '1.0.101', optional = true}
-serde_derive = { version = '1.0.101', 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'
+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'}
 
 [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',
 ]

+ 29 - 15
runtime-modules/token-minting/src/lib.rs

@@ -10,9 +10,11 @@
 use rstd::prelude::*;
 
 use codec::{Codec, Decode, Encode};
-use runtime_primitives::traits::{MaybeSerialize, Member, One, SimpleArithmetic, Zero};
-use srml_support::traits::Currency;
-use srml_support::{decl_module, decl_storage, ensure, Parameter};
+use frame_support::storage::IterableStorageMap;
+use frame_support::traits::Currency;
+use frame_support::{decl_module, decl_storage, ensure, Parameter};
+use sp_arithmetic::traits::{BaseArithmetic, One, Zero};
+use sp_runtime::traits::{MaybeSerialize, Member};
 
 mod mint;
 mod mock;
@@ -27,7 +29,7 @@ pub trait Trait: system::Trait {
     /// The type used as a mint identifier.
     type MintId: Parameter
         + Member
-        + SimpleArithmetic
+        + BaseArithmetic
         + Codec
         + Default
         + Copy
@@ -107,13 +109,13 @@ pub enum Adjustment<Balance: Zero, BlockNumber> {
 decl_storage! {
     trait Store for Module<T: Trait> as TokenMint {
         /// Mints
-        pub Mints get(mints) : linked_map T::MintId => Mint<BalanceOf<T>, T::BlockNumber>;
+        pub Mints get(fn mints) : map hasher(blake2_128_concat) T::MintId => Mint<BalanceOf<T>, T::BlockNumber>;
 
         /// The number of mints created.
-        pub MintsCreated get(mints_created): T::MintId;
+        pub MintsCreated get(fn mints_created): T::MintId;
     }
 }
-
+// pub Account: map hasher(blake2_128_concat) T::AccountId => AccountData<T::Balance>;
 decl_module! {
     pub struct Module<T: Trait> for enum Call where origin: T::Origin {
         fn on_finalize(now: T::BlockNumber) {
@@ -125,7 +127,7 @@ decl_module! {
 impl<T: Trait> Module<T> {
     fn update_mints(now: T::BlockNumber) {
         // Are we reading value from storage twice?
-        for (mint_id, ref mut mint) in <Mints<T>>::enumerate() {
+        for (mint_id, ref mut mint) in <Mints<T>>::iter() {
             if mint.maybe_do_capacity_adjustment(now) {
                 <Mints<T>>::insert(&mint_id, mint);
             }
@@ -199,7 +201,10 @@ impl<T: Trait> Module<T> {
             return Ok(());
         }
 
-        ensure!(<Mints<T>>::exists(&mint_id), TransferError::MintNotFound);
+        ensure!(
+            <Mints<T>>::contains_key(&mint_id),
+            TransferError::MintNotFound
+        );
 
         let mut mint = Self::mints(&mint_id);
 
@@ -219,7 +224,10 @@ impl<T: Trait> Module<T> {
         mint_id: T::MintId,
         capacity: BalanceOf<T>,
     ) -> Result<(), GeneralError> {
-        ensure!(<Mints<T>>::exists(&mint_id), GeneralError::MintNotFound);
+        ensure!(
+            <Mints<T>>::contains_key(&mint_id),
+            GeneralError::MintNotFound
+        );
 
         <Mints<T>>::mutate(&mint_id, |mint| {
             mint.set_capacity(capacity);
@@ -237,11 +245,11 @@ impl<T: Trait> Module<T> {
         capacity_to_transfer: BalanceOf<T>,
     ) -> Result<(), CapacityTransferError> {
         ensure!(
-            <Mints<T>>::exists(&source),
+            <Mints<T>>::contains_key(&source),
             CapacityTransferError::SourceMintNotFound
         );
         ensure!(
-            <Mints<T>>::exists(&destination),
+            <Mints<T>>::contains_key(&destination),
             CapacityTransferError::DestinationMintNotFound
         );
 
@@ -256,7 +264,10 @@ impl<T: Trait> Module<T> {
 
     /// Returns a mint's capacity if it exists, error otherwise.
     pub fn get_mint_capacity(mint_id: T::MintId) -> Result<BalanceOf<T>, GeneralError> {
-        ensure!(<Mints<T>>::exists(&mint_id), GeneralError::MintNotFound);
+        ensure!(
+            <Mints<T>>::contains_key(&mint_id),
+            GeneralError::MintNotFound
+        );
         let mint = Self::mints(&mint_id);
 
         Ok(mint.capacity())
@@ -266,7 +277,10 @@ impl<T: Trait> Module<T> {
     pub fn get_mint_next_adjustment(
         mint_id: T::MintId,
     ) -> Result<Option<NextAdjustment<BalanceOf<T>, T::BlockNumber>>, GeneralError> {
-        ensure!(<Mints<T>>::exists(&mint_id), GeneralError::MintNotFound);
+        ensure!(
+            <Mints<T>>::contains_key(&mint_id),
+            GeneralError::MintNotFound
+        );
 
         let mint = Self::mints(&mint_id);
 
@@ -275,6 +289,6 @@ impl<T: Trait> Module<T> {
 
     /// Returns true if a mint exists.
     pub fn mint_exists(mint_id: T::MintId) -> bool {
-        <Mints<T>>::exists(&mint_id)
+        <Mints<T>>::contains_key(&mint_id)
     }
 }

+ 6 - 6
runtime-modules/token-minting/src/mint.rs

@@ -1,6 +1,6 @@
 use codec::{Decode, Encode};
-use runtime_primitives::traits::{SimpleArithmetic, Zero};
-use srml_support::ensure;
+use frame_support::ensure;
+use sp_arithmetic::traits::{BaseArithmetic, Zero};
 
 #[derive(Encode, Decode, Copy, Clone, Debug, Eq, PartialEq)]
 pub enum AdjustCapacityBy<Balance: Zero> {
@@ -30,8 +30,8 @@ pub struct NextAdjustment<Balance: Zero, BlockNumber> {
 // We want Default trait on TokenMint so we can use it as value in StorageMap without needing to wrap it in an Option
 pub struct Mint<Balance, BlockNumber>
 where
-    Balance: Copy + SimpleArithmetic + Zero,
-    BlockNumber: Copy + SimpleArithmetic,
+    Balance: Copy + BaseArithmetic + Zero,
+    BlockNumber: Copy + BaseArithmetic,
 {
     capacity: Balance,
 
@@ -51,8 +51,8 @@ pub enum MintingError {
 
 impl<Balance, BlockNumber> Mint<Balance, BlockNumber>
 where
-    Balance: Copy + SimpleArithmetic + Zero,
-    BlockNumber: Copy + SimpleArithmetic,
+    Balance: Copy + BaseArithmetic + Zero,
+    BlockNumber: Copy + BaseArithmetic,
 {
     pub fn new(
         initial_capacity: Balance,

+ 16 - 22
runtime-modules/token-minting/src/mock.rs

@@ -2,16 +2,15 @@
 
 use crate::*;
 
-use primitives::H256;
-
 use crate::{Module, Trait};
 use balances;
-use runtime_primitives::{
+use frame_support::{impl_outer_origin, parameter_types};
+use sp_core::H256;
+use sp_runtime::{
     testing::Header,
     traits::{BlakeTwo256, IdentityLookup},
     Perbill,
 };
-use srml_support::{impl_outer_origin, parameter_types};
 
 impl_outer_origin! {
     pub enum Origin for Test {}
@@ -29,10 +28,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;
@@ -41,35 +41,29 @@ 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! {
     pub const ExistentialDeposit: u32 = 0;
-    pub const TransferFee: u32 = 0;
-    pub const CreationFee: u32 = 0;
-    pub const TransactionBaseFee: u32 = 1;
-    pub const TransactionByteFee: u32 = 0;
-    pub const InitialMembersBalance: u64 = 2000;
 }
 
 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 {
@@ -77,7 +71,7 @@ impl Trait for Test {
     type MintId = u64;
 }
 
-pub fn build_test_externalities() -> runtime_io::TestExternalities {
+pub fn build_test_externalities() -> sp_io::TestExternalities {
     let t = system::GenesisConfig::default()
         .build_storage::<Test>()
         .unwrap();

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff