Browse Source

council: add set_council_mint_capacity() and spend_from_council_mint()

Mokhtar Naamani 5 years ago
parent
commit
d4c1c944ec

+ 17 - 7
runtime-modules/governance/src/council.rs

@@ -34,8 +34,8 @@ decl_storage! {
         pub TermEndsAt get(term_ends_at) config() : T::BlockNumber = T::BlockNumber::from(1);
 
         /// The mint that funds council member rewards and spending proposals budget.
-        pub Mint get(mint) build(|_config: &GenesisConfig<T>| {
-            <Module<T>>::initialize_mint()
+        pub CouncilMint get(council_mint) build(|_config: &GenesisConfig<T>| {
+            <Module<T>>::create_new_council_mint()
         }): <T as minting::Trait>::MintId;
     }
 }
@@ -68,9 +68,11 @@ impl<T: Trait> Module<T> {
     }
 
     // Initializes a new mint
-    pub fn initialize_mint() -> T::MintId {
-        <minting::Module<T>>::add_mint(minting::BalanceOf::<T>::zero(), None)
-            .expect("Failed to create a mint for the council")
+    pub fn create_new_council_mint() -> T::MintId {
+        let mint_id = <minting::Module<T>>::add_mint(minting::BalanceOf::<T>::zero(), None)
+            .expect("Failed to create a mint for the council");
+        CouncilMint::<T>::put(mint_id);
+        mint_id
     }
 }
 
@@ -131,11 +133,19 @@ decl_module! {
             <TermEndsAt<T>>::put(ends_at);
         }
 
-        fn set_mint_capacity(origin, new_capacity: minting::BalanceOf<T>) {
+        /// Sets the capacity of the the council mint
+        fn set_council_mint_capacity(origin, new_capacity: minting::BalanceOf<T>) {
             ensure_root(origin)?;
-            let mint_id = Self::mint();
+            let mint_id = Self::council_mint();
             minting::Module::<T>::set_mint_capacity(mint_id, new_capacity)?;
         }
+
+        /// Attempts to mint and transfer amount to destination account
+        fn spend_from_council_mint(origin, amount: minting::BalanceOf<T>, destination: T::AccountId) {
+            ensure_root(origin)?;
+            let mint_id = Self::council_mint();
+            minting::Module::<T>::transfer_tokens(mint_id, amount, &destination)?;
+        }
     }
 }
 

+ 9 - 0
runtime-modules/token-minting/src/lib.rs

@@ -82,6 +82,15 @@ impl From<GeneralError> for &'static str {
     }
 }
 
+impl From<TransferError> for &'static str {
+    fn from(err: TransferError) -> &'static str {
+        match err {
+            TransferError::MintNotFound => "MintNotFound",
+            TransferError::NotEnoughCapacity => "NotEnoughCapacity",
+        }
+    }
+}
+
 #[derive(Encode, Decode, Copy, Clone, Debug, Eq, PartialEq)]
 pub enum Adjustment<Balance: Zero, BlockNumber> {
     // First adjustment will be after AdjustOnInterval.block_interval

+ 1 - 1
runtime/src/migration.rs

@@ -15,7 +15,7 @@ impl<T: Trait> Module<T> {
         // ...
 
         // Create the Council mint
-        governance::council::Module::<T>::initialize_mint();
+        governance::council::Module::<T>::create_new_council_mint();
 
         Self::deposit_event(RawEvent::Migrated(
             <system::Module<T>>::block_number(),