mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-25 22:17:58 +00:00
Name more consistently with std.
This commit is contained in:
@@ -31,12 +31,12 @@ pub type Bondage = u64;
|
||||
|
||||
/// The length of the bonding duration in eras.
|
||||
pub fn bonding_duration() -> BlockNumber {
|
||||
storage::get_default(BONDING_DURATION)
|
||||
storage::get_or_default(BONDING_DURATION)
|
||||
}
|
||||
|
||||
/// The length of a staking era in sessions.
|
||||
pub fn validator_count() -> usize {
|
||||
storage::get_default::<u32>(VALIDATOR_COUNT) as usize
|
||||
storage::get_or_default::<u32>(VALIDATOR_COUNT) as usize
|
||||
}
|
||||
|
||||
/// The length of a staking era in blocks.
|
||||
@@ -46,27 +46,27 @@ pub fn era_length() -> BlockNumber {
|
||||
|
||||
/// The length of a staking era in sessions.
|
||||
pub fn sessions_per_era() -> BlockNumber {
|
||||
storage::get_default(SESSIONS_PER_ERA)
|
||||
storage::get_or_default(SESSIONS_PER_ERA)
|
||||
}
|
||||
|
||||
/// The current era index.
|
||||
pub fn current_era() -> BlockNumber {
|
||||
storage::get_default(CURRENT_ERA)
|
||||
storage::get_or_default(CURRENT_ERA)
|
||||
}
|
||||
|
||||
/// The block number at which the era length last changed.
|
||||
pub fn last_era_length_change() -> BlockNumber {
|
||||
storage::get_default(LAST_ERA_LENGTH_CHANGE)
|
||||
storage::get_or_default(LAST_ERA_LENGTH_CHANGE)
|
||||
}
|
||||
|
||||
/// The balance of a given account.
|
||||
pub fn balance(who: &AccountID) -> Balance {
|
||||
storage::get_default(&who.to_keyed_vec(BALANCE_OF))
|
||||
storage::get_or_default(&who.to_keyed_vec(BALANCE_OF))
|
||||
}
|
||||
|
||||
/// The liquidity-state of a given account.
|
||||
pub fn bondage(who: &AccountID) -> Bondage {
|
||||
storage::get_default(&who.to_keyed_vec(BONDAGE_OF))
|
||||
storage::get_or_default(&who.to_keyed_vec(BONDAGE_OF))
|
||||
}
|
||||
|
||||
// Each identity's stake may be in one of three bondage states, given by an integer:
|
||||
@@ -81,10 +81,10 @@ pub mod public {
|
||||
/// Transfer some unlocked staking balance to another staker.
|
||||
pub fn transfer(transactor: &AccountID, dest: &AccountID, value: Balance) {
|
||||
let from_key = transactor.to_keyed_vec(BALANCE_OF);
|
||||
let from_balance = storage::get_default::<Balance>(&from_key);
|
||||
let from_balance = storage::get_or_default::<Balance>(&from_key);
|
||||
assert!(from_balance >= value);
|
||||
let to_key = dest.to_keyed_vec(BALANCE_OF);
|
||||
let to_balance: Balance = storage::get_default(&to_key);
|
||||
let to_balance: Balance = storage::get_or_default(&to_key);
|
||||
assert!(bondage(transactor) <= bondage(dest));
|
||||
assert!(to_balance + value > to_balance); // no overflow
|
||||
storage::put(&from_key, &(from_balance - value));
|
||||
@@ -176,7 +176,7 @@ fn new_era() {
|
||||
storage::put(CURRENT_ERA, &(current_era() + 1));
|
||||
|
||||
// Enact era length change.
|
||||
let next_spe: u64 = storage::get_default(NEXT_SESSIONS_PER_ERA);
|
||||
let next_spe: u64 = storage::get_or_default(NEXT_SESSIONS_PER_ERA);
|
||||
if next_spe > 0 && next_spe != sessions_per_era() {
|
||||
storage::put(SESSIONS_PER_ERA, &next_spe);
|
||||
storage::put(LAST_ERA_LENGTH_CHANGE, &system::block_number());
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn block_number() -> BlockNumber {
|
||||
|
||||
/// Get the block hash of a given block (uses storage).
|
||||
pub fn block_hash(number: BlockNumber) -> Hash {
|
||||
storage::get_default(&number.to_keyed_vec(BLOCK_HASH_AT))
|
||||
storage::get_or_default(&number.to_keyed_vec(BLOCK_HASH_AT))
|
||||
}
|
||||
|
||||
pub mod privileged {
|
||||
@@ -102,7 +102,7 @@ pub mod internal {
|
||||
|
||||
// check nonce
|
||||
let nonce_key = tx.signed.to_keyed_vec(b"sys:non:");
|
||||
let expected_nonce: TxOrder = storage::get_default(&nonce_key);
|
||||
let expected_nonce: TxOrder = storage::get_or_default(&nonce_key);
|
||||
assert!(tx.nonce == expected_nonce, "All transactions should have the correct nonce");
|
||||
|
||||
// increment nonce in storage
|
||||
|
||||
@@ -23,7 +23,7 @@ pub type Timestamp = u64;
|
||||
|
||||
/// Get the current time.
|
||||
pub fn get() -> Timestamp {
|
||||
storage::get_default(CURRENT_TIMESTAMP)
|
||||
storage::get_or_default(CURRENT_TIMESTAMP)
|
||||
}
|
||||
|
||||
pub mod public {
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn get<T: Slicable + Sized>(key: &[u8]) -> Option<T> {
|
||||
|
||||
/// Return the value of the item in storage under `key`, or the type's default if there is no
|
||||
/// explicit entry.
|
||||
pub fn get_default<T: Slicable + Sized + Default>(key: &[u8]) -> T {
|
||||
pub fn get_or_default<T: Slicable + Sized + Default>(key: &[u8]) -> T {
|
||||
get(key).unwrap_or_else(Default::default)
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ pub trait StorageVec {
|
||||
}
|
||||
|
||||
fn item(index: u32) -> Self::Item {
|
||||
get_default(&index.to_keyed_vec(Self::PREFIX))
|
||||
get_or_default(&index.to_keyed_vec(Self::PREFIX))
|
||||
}
|
||||
|
||||
fn set_count(count: u32) {
|
||||
@@ -138,7 +138,7 @@ pub trait StorageVec {
|
||||
}
|
||||
|
||||
fn count() -> u32 {
|
||||
get_default(&b"len".to_keyed_vec(Self::PREFIX))
|
||||
get_or_default(&b"len".to_keyed_vec(Self::PREFIX))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user