forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from PureStake/crystalin-restore-pallets
Restore pallets (WIP)
- Loading branch information
Showing
4 changed files
with
609 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[package] | ||
authors = ['PureStake'] | ||
edition = '2018' | ||
name = 'mb-core' | ||
version = '0.1.0' | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } | ||
safe-mix = { default-features = false, version = '1.0.0' } | ||
serde = { version = "1.0.102", features = ["derive"] } | ||
|
||
# primitives | ||
sp-core = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
sp-io = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
sp-runtime = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
sp-std = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
sp-staking = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
|
||
# frame dependencies | ||
frame-support = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
system = { package = 'frame-system', git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
pallet-balances = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
pallet-staking = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
|
||
[features] | ||
default = ['std'] | ||
std = [ | ||
"sp-std/std", | ||
"sp-staking/std", | ||
'codec/std', | ||
'frame-support/std', | ||
'safe-mix/std', | ||
'system/std', | ||
'pallet-staking/std', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
use sp_std::prelude::*; | ||
|
||
use frame_support::{decl_module, decl_storage, decl_event}; | ||
use frame_support::dispatch::{DispatchResult}; | ||
use frame_support::traits::{OnUnbalanced,Currency,LockableCurrency,Imbalance}; | ||
use system::{ensure_root,RawOrigin}; | ||
use sp_runtime::{traits::{EnsureOrigin,CheckedAdd,CheckedSub}}; | ||
|
||
type BalanceOf<T> = | ||
<<T as Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance; | ||
|
||
type NegativeImbalanceOf<T> = | ||
<<T as Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::NegativeImbalance; | ||
|
||
type PositiveImbalanceOf<T> = | ||
<<T as Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::PositiveImbalance; | ||
|
||
pub trait Trait: system::Trait + pallet_balances::Trait { | ||
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>; | ||
type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>; | ||
} | ||
|
||
decl_storage! { | ||
trait Store for Module<T: Trait> as MoonbeamModule { | ||
Treasury get(treasury): BalanceOf<T>; | ||
GenesisAccounts get(genesis_accounts): Vec<T::AccountId>; | ||
} | ||
add_extra_genesis { | ||
config(treasury): BalanceOf<T>; | ||
config(genesis_accounts): Vec<T::AccountId>; | ||
build(|config: &GenesisConfig<T>| { | ||
<Treasury<T>>::put(config.treasury); | ||
let _ = <GenesisAccounts<T>>::append(config.genesis_accounts.clone()); | ||
}); | ||
} | ||
} | ||
|
||
decl_event!( | ||
pub enum Event<T> | ||
where | ||
AccountId = <T as system::Trait>::AccountId, | ||
BalanceOf = BalanceOf<T>, | ||
{ | ||
Absorbed(BalanceOf, BalanceOf), | ||
Rewarded(BalanceOf, BalanceOf), | ||
TreasuryTransferOk(AccountId, BalanceOf, BalanceOf), | ||
} | ||
); | ||
|
||
decl_module! { | ||
pub struct Module<T: Trait> for enum Call where origin: T::Origin { | ||
|
||
fn deposit_event() = default; | ||
|
||
// TODO work in progress mint from pot | ||
fn mint( | ||
origin, _to: T::AccountId, _ammount: BalanceOf<T> | ||
) -> DispatchResult { | ||
let _caller = ensure_root(origin); | ||
Ok(()) | ||
} | ||
|
||
} | ||
} | ||
|
||
pub struct Collective<AccountId>(AccountId); | ||
impl< | ||
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, | ||
AccountId | ||
> EnsureOrigin<O> for Collective<AccountId> { | ||
type Success = (); | ||
fn try_origin(_o: O) -> Result<Self::Success, O> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
// https://substrate.dev/rustdocs/pre-v2.0-3e65111/pallet_staking/trait.Trait.html#associatedtype.RewardRemainder | ||
pub struct RewardRemainder<T>(T); | ||
impl<T: Trait> OnUnbalanced<NegativeImbalanceOf<T>> for RewardRemainder<T> | ||
{ | ||
fn on_nonzero_unbalanced(_amount: NegativeImbalanceOf<T>) { | ||
// TODO Tokens have been minted and are unused for validator-reward. | ||
let _a = 1; | ||
} | ||
} | ||
|
||
// NegativeImbalance: | ||
// Some balance has been subtracted somewhere, needs to be added somewhere else. | ||
pub struct Absorb<T>(T); | ||
impl<T: Trait> OnUnbalanced<NegativeImbalanceOf<T>> for Absorb<T> | ||
{ | ||
fn on_nonzero_unbalanced(amount: NegativeImbalanceOf<T>) { | ||
let raw_amount = amount.peek(); | ||
let treasury = <Treasury<T>>::get(); | ||
if let Some(next_treasury) = treasury.checked_add(&raw_amount) { | ||
<Treasury<T>>::put(next_treasury); | ||
} else { | ||
// TODO | ||
} | ||
<Module<T>>::deposit_event( | ||
RawEvent::Absorbed( | ||
raw_amount, | ||
<Treasury<T>>::get() | ||
) | ||
); | ||
} | ||
} | ||
|
||
// PositiveImbalance: | ||
// Some balance has been added somewhere, needs to be subtracted somewhere else. | ||
pub struct Reward<T>(T); | ||
impl<T: Trait> OnUnbalanced<PositiveImbalanceOf<T>> for Reward<T> | ||
{ | ||
fn on_nonzero_unbalanced(amount: PositiveImbalanceOf<T>) { | ||
let raw_amount = amount.peek(); | ||
let treasury = <Treasury<T>>::get(); | ||
if let Some(next_treasury) = treasury.checked_sub(&raw_amount) { | ||
<Treasury<T>>::put(next_treasury); | ||
} else { | ||
// TODO | ||
} | ||
<Module<T>>::deposit_event( | ||
RawEvent::Rewarded( | ||
raw_amount, | ||
<Treasury<T>>::get() | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[package] | ||
authors = ['PureStake'] | ||
edition = '2018' | ||
name = 'mb-session' | ||
version = '0.1.0' | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } | ||
safe-mix = { default-features = false, version = '1.0.0' } | ||
serde = { version = "1.0.102", features = ["derive"] } | ||
|
||
# primitives | ||
sp-core = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
sp-io = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
sp-runtime = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
sp-std = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
sp-session = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
sp-staking = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
node-primitives = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
|
||
# frame dependencies | ||
frame-support = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
system = { package = 'frame-system', git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
pallet-balances = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
pallet-session = { features = ["historical"], git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
pallet-authorship = { git = 'https://github.com/paritytech/substrate.git', rev = '992aea815a753da256a9c0bff053df408532df02', default-features = false } | ||
|
||
[features] | ||
default = ['std'] | ||
std = [ | ||
"sp-std/std", | ||
"sp-staking/std", | ||
'codec/std', | ||
'frame-support/std', | ||
'safe-mix/std', | ||
"sp-session/std", | ||
'system/std', | ||
"pallet-session/std", | ||
"pallet-authorship/std", | ||
] |
Oops, something went wrong.