This commit is contained in:
Gav
2018-01-19 10:49:23 +01:00
parent 81cd156d2a
commit 63809d9e0c
11 changed files with 87 additions and 87 deletions
@@ -1,5 +1,5 @@
use runtime_support::Vec;
use storagevec::StorageVec;
use storable::StorageVec;
use primitives::SessionKey;
struct AuthorityStorageVec {}
@@ -1,7 +1,6 @@
use runtime_support::Vec;
use keyedvec::KeyedVec;
use storage::Storage;
use storagevec::StorageVec;
use storable::{kill, Storable, StorageVec};
use primitives::{AccountID, SessionKey, BlockNumber};
use runtime::{system, staking, consensus};
@@ -38,7 +37,7 @@ pub fn set_validators(new: &[AccountID]) {
/// The number of blocks in each session.
pub fn length() -> BlockNumber {
Storage::into(b"ses\0bps")
Storable::lookup_default(b"ses\0bps")
}
/// Hook to be called prior to transaction processing.
@@ -62,11 +61,13 @@ pub fn post_transactions() {
/// Move onto next session: register the new authority set.
fn next_session() {
// TODO: Call set_authorities() with any new authorities.
validators().iter().enumerate().for_each(|(i, v)| {
let k = v.to_keyed_vec(b"ses\0nxt\0");
if let Some(n) = Storage::try_into(&k) {
if let Some(n) = Storable::lookup(&k) {
consensus::set_authority(i as u32, &n);
kill(&k);
}
})
});
}
// TODO: tests
@@ -1,5 +1,5 @@
use keyedvec::KeyedVec;
use storage::Storage;
use storable::Storable;
use primitives::{BlockNumber, Balance, AccountID};
use runtime::{system, session};
@@ -10,7 +10,7 @@ use runtime::{system, session};
/// The length of a staking era in sessions.
pub fn lockup_eras() -> BlockNumber {
Storage::into(b"sta\0lpe")
Storable::lookup_default(b"sta\0lpe")
}
/// The length of a staking era in blocks.
@@ -20,12 +20,12 @@ pub fn era_length() -> BlockNumber {
/// The length of a staking era in sessions.
pub fn sessions_per_era() -> BlockNumber {
Storage::into(b"sta\0spe")
Storable::lookup_default(b"sta\0spe")
}
/// The current era index.
pub fn current_era() -> BlockNumber {
Storage::into(b"sta\0era")
Storable::lookup_default(b"sta\0era")
}
/// The current era index.
@@ -35,7 +35,7 @@ pub fn set_current_era(new: BlockNumber) {
/// The block number at which the era length last changed.
pub fn last_era_length_change() -> BlockNumber {
Storage::into(b"sta\0lec")
Storable::lookup_default(b"sta\0lec")
}
/// Set a new era length. Won't kick in until the next era change (at current length).
@@ -51,7 +51,7 @@ fn next_era() {
set_current_era(current_era() + 1);
// Enact era length change.
let next_spe: u64 = Storage::into(b"sta\0nse");
let next_spe: u64 = Storable::lookup_default(b"sta\0nse");
if next_spe > 0 && next_spe != sessions_per_era() {
next_spe.store(b"sta\0spe");
system::block_number().store(b"sta\0lec");
@@ -63,16 +63,16 @@ fn next_era() {
/// The balance of a given account.
pub fn balance_inactive(who: &AccountID) -> Balance {
Storage::into(&who.to_keyed_vec(b"sta\0bal\0"))
Storable::lookup_default(&who.to_keyed_vec(b"sta\0bal\0"))
}
/// Transfer some unlocked staking balance to another staker.
pub fn transfer_inactive(transactor: &AccountID, dest: &AccountID, value: Balance) {
let from_key = transactor.to_keyed_vec(b"sta\0bal\0");
let from_balance: Balance = Storage::into(&from_key);
let from_balance: Balance = Storable::lookup_default(&from_key);
assert!(from_balance >= value);
let to_key = dest.to_keyed_vec(b"sta\0bal\0");
let to_balance: Balance = Storage::into(&to_key);
let to_balance: Balance = Storable::lookup_default(&to_key);
assert!(to_balance + value > to_balance); // no overflow
(from_balance - value).store(&from_key);
(to_balance + value).store(&to_key);
@@ -1,6 +1,6 @@
use primitives::{Block, BlockNumber, Hash, UncheckedTransaction, TxOrder, Hashable};
use runtime_support::{Vec, swap};
use storage::Storage;
use storable::Storable;
use keyedvec::KeyedVec;
use environment::with_env;
use runtime::session;
@@ -12,7 +12,7 @@ pub fn block_number() -> BlockNumber {
/// Get the block hash of a given block (uses storage).
pub fn block_hash(number: BlockNumber) -> Hash {
Storage::into(&number.to_keyed_vec(b"sys\0old\0"))
Storable::lookup_default(&number.to_keyed_vec(b"sys\0old\0"))
}
/// Deposits a log and ensures it matches the blocks log data.
@@ -69,7 +69,7 @@ pub fn execute_transaction(utx: &UncheckedTransaction) {
// check nonce
let nonce_key = tx.signed.to_keyed_vec(b"sys\0non\0");
let expected_nonce: TxOrder = Storage::into(&nonce_key);
let expected_nonce: TxOrder = Storable::lookup_default(&nonce_key);
assert!(tx.nonce == expected_nonce, "All transactions should have the correct nonce");
// increment nonce in storage
@@ -1,8 +1,8 @@
use primitives::Timestamp;
use storage::Storage;
use storable::Storable;
pub fn get() -> Timestamp {
Storage::into(b"tim\0val")
Storable::lookup_default(b"tim\0val")
}
pub fn set(now: Timestamp) {