mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 12:11:09 +00:00
Extract well known keys into a single place (#764)
* Extract well known keys into a single place * Fixes.
This commit is contained in:
committed by
Gav Wood
parent
7fa337afbc
commit
e7d1933d25
@@ -48,19 +48,15 @@ use runtime_support::storage::StorageValue;
|
||||
use runtime_support::storage::unhashed::StorageVec;
|
||||
use primitives::traits::{MaybeSerializeDebug, OnFinalise, Member};
|
||||
use primitives::bft::MisbehaviorReport;
|
||||
use substrate_primitives::storage::well_known_keys;
|
||||
use system::{ensure_signed, ensure_inherent};
|
||||
|
||||
pub const AUTHORITY_AT: &'static [u8] = b":auth:";
|
||||
pub const AUTHORITY_COUNT: &'static [u8] = b":auth:len";
|
||||
|
||||
struct AuthorityStorageVec<S: codec::Codec + Default>(rstd::marker::PhantomData<S>);
|
||||
impl<S: codec::Codec + Default> StorageVec for AuthorityStorageVec<S> {
|
||||
type Item = S;
|
||||
const PREFIX: &'static [u8] = AUTHORITY_AT;
|
||||
const PREFIX: &'static [u8] = well_known_keys::AUTHORITY_PREFIX;
|
||||
}
|
||||
|
||||
pub const CODE: &'static [u8] = b":code";
|
||||
|
||||
pub type KeyValue = (Vec<u8>, Vec<u8>);
|
||||
|
||||
pub trait OnOfflineValidator {
|
||||
@@ -142,7 +138,7 @@ impl<T: Trait> Module<T> {
|
||||
|
||||
/// Set the new code.
|
||||
fn set_code(new: Vec<u8>) -> Result {
|
||||
storage::unhashed::put_raw(CODE, &new);
|
||||
storage::unhashed::put_raw(well_known_keys::CODE, &new);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -175,7 +171,7 @@ impl<T: Trait> Module<T> {
|
||||
for validator_index in offline_val_indices.into_iter() {
|
||||
T::OnOfflineValidator::on_offline_validator(validator_index as usize);
|
||||
}
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -253,10 +249,10 @@ impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
use codec::{Encode, KeyedVec};
|
||||
let auth_count = self.authorities.len() as u32;
|
||||
let mut r: primitives::StorageMap = self.authorities.into_iter().enumerate().map(|(i, v)|
|
||||
((i as u32).to_keyed_vec(AUTHORITY_AT), v.encode())
|
||||
((i as u32).to_keyed_vec(well_known_keys::AUTHORITY_PREFIX), v.encode())
|
||||
).collect();
|
||||
r.insert(AUTHORITY_COUNT.to_vec(), auth_count.encode());
|
||||
r.insert(CODE.to_vec(), self.code);
|
||||
r.insert(well_known_keys::AUTHORITY_COUNT.to_vec(), auth_count.encode());
|
||||
r.insert(well_known_keys::CODE.to_vec(), self.code);
|
||||
Ok(r.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ extern crate safe_mix;
|
||||
use rstd::prelude::*;
|
||||
use primitives::traits::{self, CheckEqual, SimpleArithmetic, SimpleBitOps, Zero, One, Bounded,
|
||||
Hash, Member, MaybeDisplay, EnsureOrigin, Digest as DigestT, As};
|
||||
use substrate_primitives::storage::well_known_keys;
|
||||
use runtime_support::{storage, StorageValue, StorageMap, Parameter};
|
||||
use safe_mix::TripletMix;
|
||||
|
||||
@@ -57,11 +58,6 @@ use runtime_io::{twox_128, TestExternalities, Blake2Hasher, RlpCodec};
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use substrate_primitives::ChangesTrieConfiguration;
|
||||
|
||||
/// Current extrinsic index (u32) is stored under this key.
|
||||
pub const EXTRINSIC_INDEX: &'static [u8] = b":extrinsic_index";
|
||||
/// Changes trie configuration is stored under this key.
|
||||
pub const CHANGES_TRIE_CONFIG: &'static [u8] = b":changes_trie";
|
||||
|
||||
/// Compute the extrinsics root of a list of extrinsics.
|
||||
pub fn extrinsics_root<H: Hash, E: codec::Encode>(extrinsics: &[E]) -> H::Output {
|
||||
extrinsics_data_root::<H>(extrinsics.iter().map(codec::Encode::encode).collect())
|
||||
@@ -244,13 +240,13 @@ pub fn ensure_inherent<OuterOrigin, AccountId>(o: OuterOrigin) -> Result<(), &'s
|
||||
impl<T: Trait> Module<T> {
|
||||
/// Gets the index of extrinsic that is currenty executing.
|
||||
pub fn extrinsic_index() -> Option<u32> {
|
||||
storage::unhashed::get(EXTRINSIC_INDEX)
|
||||
storage::unhashed::get(well_known_keys::EXTRINSIC_INDEX)
|
||||
}
|
||||
|
||||
/// Start the execution of a particular block.
|
||||
pub fn initialise(number: &T::BlockNumber, parent_hash: &T::Hash, txs_root: &T::Hash) {
|
||||
// populate environment.
|
||||
storage::unhashed::put(EXTRINSIC_INDEX, &0u32);
|
||||
storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &0u32);
|
||||
<Number<T>>::put(number);
|
||||
<ParentHash<T>>::put(parent_hash);
|
||||
<BlockHash<T>>::insert(*number - One::one(), parent_hash);
|
||||
@@ -334,7 +330,7 @@ impl<T: Trait> Module<T> {
|
||||
/// Sets the index of extrinsic that is currenty executing.
|
||||
#[cfg(any(feature = "std", test))]
|
||||
pub fn set_extrinsic_index(extrinsic_index: u32) {
|
||||
storage::unhashed::put(EXTRINSIC_INDEX, &extrinsic_index)
|
||||
storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &extrinsic_index)
|
||||
}
|
||||
|
||||
/// Set the parent hash number to something in particular. Can be used as an alternative to
|
||||
@@ -370,13 +366,13 @@ impl<T: Trait> Module<T> {
|
||||
}.into());
|
||||
|
||||
let next_extrinsic_index = Self::extrinsic_index().unwrap_or_default() + 1u32;
|
||||
storage::unhashed::put(EXTRINSIC_INDEX, &next_extrinsic_index);
|
||||
storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &next_extrinsic_index);
|
||||
}
|
||||
|
||||
/// To be called immediately after `note_applied_extrinsic` of the last extrinsic of the block
|
||||
/// has been called.
|
||||
pub fn note_finished_extrinsics() {
|
||||
let extrinsic_index: u32 = storage::unhashed::take(EXTRINSIC_INDEX).unwrap_or_default();
|
||||
let extrinsic_index: u32 = storage::unhashed::take(well_known_keys::EXTRINSIC_INDEX).unwrap_or_default();
|
||||
<ExtrinsicCount<T>>::put(extrinsic_index);
|
||||
}
|
||||
|
||||
@@ -422,11 +418,11 @@ impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
Self::hash(<RandomSeed<T>>::key()).to_vec() => [0u8; 32].encode()
|
||||
];
|
||||
|
||||
storage.insert(EXTRINSIC_INDEX.to_vec(), 0u32.encode());
|
||||
storage.insert(well_known_keys::EXTRINSIC_INDEX.to_vec(), 0u32.encode());
|
||||
|
||||
if let Some(changes_trie_config) = self.changes_trie_config {
|
||||
storage.insert(
|
||||
CHANGES_TRIE_CONFIG.to_vec(),
|
||||
well_known_keys::CHANGES_TRIE_CONFIG.to_vec(),
|
||||
changes_trie_config.encode());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user