Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a83059a
Completely rework dispatch mechanism into something modular.
gavofyork Mar 13, 2018
82a178d
Council vote tests.
gavofyork Mar 13, 2018
1d28d9a
Fix tests.
gavofyork Mar 13, 2018
69c88c3
whitespace.
gavofyork Mar 13, 2018
b12a708
Fix demo runtime tests.
gavofyork Mar 14, 2018
e48e86d
Merge branch 'gav-demo' into gav-dispatch
gavofyork Mar 14, 2018
8e3cc51
Fix up tests.
gavofyork Mar 14, 2018
53e2fdf
Merge branch 'gav-demo' into gav-dispatch
gavofyork Mar 14, 2018
27ecd6f
Merge branch 'master' into gav-dispatch
gavofyork Mar 14, 2018
5eca74a
Remove dead code.
gavofyork Mar 14, 2018
7cece3b
Merge branch 'master' into gav-dispatch
gavofyork Mar 14, 2018
8c2396d
Timestamp uses new storage API.
gavofyork Mar 14, 2018
6b6c240
Move over system module to new API.
gavofyork Mar 14, 2018
a79dab2
Much nicer storage API, moved over staking module.
gavofyork Mar 15, 2018
1fd6b3e
More refactoring.
gavofyork Mar 15, 2018
51b4a8c
Democracy uses new storage API.
gavofyork Mar 15, 2018
8ada9f7
Council uses new RPC.
gavofyork Mar 16, 2018
c4f5f42
Fix more tests.
gavofyork Mar 16, 2018
d11f5ca
Use match for Id
gavofyork Mar 16, 2018
faa0a44
Use match for Id
gavofyork Mar 16, 2018
7912de1
Make PrivPass better protected.
gavofyork Mar 19, 2018
aac3899
Address other grumbles.
gavofyork Mar 19, 2018
26519c6
Give PrivPass a private member.
gavofyork Mar 19, 2018
9f32ea7
Testing PrivPass.
gavofyork Mar 19, 2018
8966951
Add docs.
gavofyork Mar 19, 2018
91d5e75
Merge branch 'gav-dispatch' into gav-storage-revamp
gavofyork Mar 19, 2018
7ee81e6
Recompile binaries after merge.
gavofyork Mar 19, 2018
33215e4
Merge branch 'master' into gav-storage-revamp
gavofyork Mar 19, 2018
cf9659e
Remove duplicated code.
gavofyork Mar 19, 2018
b8c0832
New binaries.
gavofyork Mar 19, 2018
57a9a79
Docs
gavofyork Mar 19, 2018
59c7a1a
Docs
gavofyork Mar 19, 2018
6f8f456
avoid use of (arguably) confusing terminology.
gavofyork Mar 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove duplicated code.
  • Loading branch information
gavofyork committed Mar 19, 2018
commit cf9659e4db34df18472c76fae454e26e44bd24d3
114 changes: 0 additions & 114 deletions demo/runtime/src/runtime/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,120 +217,6 @@ impl privileged::Dispatch for democracy::PrivPass {
}
}

pub struct PublicPass<'a> (&'a AccountId);

const NOBODY: AccountId = [0u8; 32];

impl<'a> PublicPass<'a> {
pub fn new(transactor: &AccountId) -> PublicPass {
let b = free_balance(&transactor);
let transaction_fee = transaction_fee();
assert!(b >= transaction_fee, "attempt to transact without enough funds to pay fee");
internal::set_free_balance(&transactor, b - transaction_fee);
PublicPass(transactor)
}

#[cfg(test)]
pub fn test(signed: &AccountId) -> PublicPass {
PublicPass(signed)
}

#[cfg(test)]
pub fn nobody() -> PublicPass<'static> {
PublicPass(&NOBODY)
}

/// Create a smart-contract account.
pub fn create(self, code: &[u8], value: Balance) {
// commit anything that made it this far to storage
if let Some(commit) = private::effect_create(self.0, code, value, private::DirectExt) {
private::commit_state(commit);
}
}
}

impl<'a> ops::Deref for PublicPass<'a> {
type Target = AccountId;
fn deref(&self) -> &AccountId {
self.0
}
}

impl_dispatch! {
pub mod public;
fn transfer(dest: AccountId, value: Balance) = 0;
fn stake() = 1;
fn unstake() = 2;
}

impl<'a> public::Dispatch for PublicPass<'a> {
/// Transfer some unlocked staking balance to another staker.
/// TODO: probably want to state gas-limit and gas-price.
fn transfer(self, dest: AccountId, value: Balance) {
// commit anything that made it this far to storage
if let Some(commit) = private::effect_transfer(&self, &dest, value, private::DirectExt) {
private::commit_state(commit);
}
}

/// Declare the desire to stake for the transactor.
///
/// Effects will be felt at the beginning of the next era.
fn stake(self) {
let mut intentions = IntentionStorageVec::items();
// can't be in the list twice.
assert!(intentions.iter().find(|&t| *t == *self).is_none(), "Cannot stake if already staked.");
intentions.push(self.clone());
IntentionStorageVec::set_items(&intentions);
storage::put(&self.to_keyed_vec(BONDAGE_OF), &u64::max_value());
}

/// Retract the desire to stake for the transactor.
///
/// Effects will be felt at the beginning of the next era.
fn unstake(self) {
let mut intentions = IntentionStorageVec::items();
if let Some(position) = intentions.iter().position(|&t| t == *self) {
intentions.swap_remove(position);
} else {
panic!("Cannot unstake if not already staked.");
}
IntentionStorageVec::set_items(&intentions);
storage::put(&self.to_keyed_vec(BONDAGE_OF), &(current_era() + bonding_duration()));
}
}

impl_dispatch! {
pub mod privileged;
fn set_sessions_per_era(new: BlockNumber) = 0;
fn set_bonding_duration(new: BlockNumber) = 1;
fn set_validator_count(new: u32) = 2;
fn force_new_era() = 3;
}

impl privileged::Dispatch for democracy::PrivPass {
/// Set the number of sessions in an era.
fn set_sessions_per_era(self, new: BlockNumber) {
storage::put(NEXT_SESSIONS_PER_ERA, &new);
}

/// The length of the bonding duration in eras.
fn set_bonding_duration(self, new: BlockNumber) {
storage::put(BONDING_DURATION, &new);
}

/// The length of a staking era in sessions.
fn set_validator_count(self, new: u32) {
storage::put(VALIDATOR_COUNT, &new);
}

/// Force there to be a new era. This also forces a new session immediately after.
fn force_new_era(self) {
new_era();
session::internal::rotate_session();
}
}

// Each identity's stake may be in one of three bondage states, given by an integer:
// - n | n <= CurrentEra::get(): inactive: free to be transferred.
// - ~0: active: currently representing a validator.
Expand Down