mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
Split out substrate-primitives from polkadot-primitives.
Bottom half minus tests builds.
This commit is contained in:
Generated
+35
-10
@@ -376,18 +376,14 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "polkadot-runtime-std"
|
||||
name = "polkadot-primitives"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ed25519 0.1.0",
|
||||
"environmental 0.1.0",
|
||||
"pwasm-alloc 0.1.0",
|
||||
"pwasm-libc 0.1.0",
|
||||
"rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-state-machine 0.1.0",
|
||||
"triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -518,16 +514,18 @@ dependencies = [
|
||||
name = "runtime-polkadot"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"polkadot-runtime-std 0.1.0",
|
||||
"polkadot-primitives 0.1.0",
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-runtime-io 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "runtime-test"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"polkadot-runtime-std 0.1.0",
|
||||
"substrate-runtime-io 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -603,6 +601,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
[[package]]
|
||||
name = "substrate-codec"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"substrate-runtime-std 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-primitives"
|
||||
@@ -616,10 +617,34 @@ dependencies = [
|
||||
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uint 0.1.2 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-runtime-io"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ed25519 0.1.0",
|
||||
"environmental 0.1.0",
|
||||
"pwasm-alloc 0.1.0",
|
||||
"pwasm-libc 0.1.0",
|
||||
"rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"substrate-state-machine 0.1.0",
|
||||
"triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-runtime-std"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-state-machine"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -8,9 +8,11 @@ crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
substrate-codec = { path = "../../codec", version = "0.1", default-features = false }
|
||||
polkadot-runtime-std = { path = "../../runtime-std", version = "0.1", default-features = false }
|
||||
substrate-runtime-std = { path = "../../runtime-std", version = "0.1", default-features = false }
|
||||
substrate-runtime-io = { path = "../../runtime-io", version = "0.1", default-features = false }
|
||||
substrate-primitives = { path = "../../primitives", version = "0.1", default-features = false }
|
||||
polkadot-primitives = { path = "../../polkadot-primitives", version = "0.1", default-features = false }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
std = ["substrate-codec/std", "polkadot-runtime-std/std", "substrate-primitives/std"]
|
||||
std = ["substrate-codec/std", "substrate-runtime-io/std", "substrate-runtime-std/std", "substrate-primitives/std", "polkadot-primitives/std"]
|
||||
|
||||
@@ -19,7 +19,10 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate polkadot_runtime_std as runtime_std;
|
||||
extern crate substrate_runtime_std as rstd;
|
||||
|
||||
#[macro_use]
|
||||
extern crate substrate_runtime_io as runtime_io;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
extern crate rustc_hex;
|
||||
@@ -28,7 +31,8 @@ extern crate rustc_hex;
|
||||
extern crate log;
|
||||
|
||||
extern crate substrate_codec as codec;
|
||||
extern crate substrate_primitives as primitives;
|
||||
extern crate substrate_primitives;
|
||||
extern crate polkadot_primitives;
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
@@ -38,20 +42,15 @@ extern crate hex_literal;
|
||||
pub mod support;
|
||||
pub mod runtime;
|
||||
|
||||
use runtime_std::prelude::*;
|
||||
use rstd::prelude::*;
|
||||
use codec::Slicable;
|
||||
use primitives::relay::{Header, Block, UncheckedTransaction};
|
||||
use polkadot_primitives::{Header, Block, UncheckedTransaction};
|
||||
|
||||
/// Type definitions and helpers for transactions.
|
||||
pub mod transaction {
|
||||
pub use primitives::relay::{Transaction, UncheckedTransaction};
|
||||
use primitives::relay::Signature;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::ops;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use core::ops;
|
||||
use rstd::ops;
|
||||
use polkadot_primitives::Signature;
|
||||
pub use polkadot_primitives::{Transaction, UncheckedTransaction};
|
||||
|
||||
/// A type-safe indicator that a transaction has been checked.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
@@ -78,7 +77,7 @@ pub mod transaction {
|
||||
/// On failure, return the transaction back.
|
||||
pub fn check(tx: UncheckedTransaction) -> Result<CheckedTransaction, UncheckedTransaction> {
|
||||
let msg = ::codec::Slicable::to_vec(&tx.transaction);
|
||||
if ::runtime_std::ed25519_verify(&tx.signature.0, &msg, &tx.transaction.signed) {
|
||||
if ::runtime_io::ed25519_verify(&tx.signature.0, &msg, &tx.transaction.signed) {
|
||||
Ok(CheckedTransaction(tx))
|
||||
} else {
|
||||
Err(tx)
|
||||
@@ -110,7 +109,7 @@ pub fn finalise_block(mut input: &[u8]) -> Vec<u8> {
|
||||
|
||||
/// Run whatever tests we have.
|
||||
pub fn run_tests(mut input: &[u8]) -> Vec<u8> {
|
||||
use runtime_std::print;
|
||||
use runtime_io::print;
|
||||
|
||||
print("run_tests...");
|
||||
let block = Block::from_slice(&mut input).unwrap();
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
//! Conensus module for runtime; manages the authority set ready for the native code.
|
||||
|
||||
use runtime_std::prelude::*;
|
||||
use rstd::prelude::*;
|
||||
use support::storage::unhashed::StorageVec;
|
||||
use primitives::relay::SessionKey;
|
||||
use polkadot_primitives::SessionKey;
|
||||
|
||||
struct AuthorityStorageVec {}
|
||||
impl StorageVec for AuthorityStorageVec {
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
//! Tool for creating the genesis block.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use runtime_std::twox_128;
|
||||
use runtime_io::twox_128;
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use support::Hashable;
|
||||
use primitives::relay::{Number as BlockNumber, Block, AccountId};
|
||||
use polkadot_primitives::{BlockNumber, Block, AccountId};
|
||||
use runtime::staking::Balance;
|
||||
|
||||
/// Configuration of a general Polkadot genesis block.
|
||||
|
||||
@@ -25,10 +25,10 @@
|
||||
//! At the end of the era, all validators approvals are tallied and if there are sufficient to pass
|
||||
//! the proposal then it is enacted. All items in storage concerning the proposal are reset.
|
||||
|
||||
use runtime_std::prelude::*;
|
||||
use rstd::prelude::*;
|
||||
use codec::KeyedVec;
|
||||
use support::storage;
|
||||
use primitives::relay::{Proposal, AccountId, Hash, BlockNumber};
|
||||
use polkadot_primitives::{Proposal, AccountId, Hash, BlockNumber};
|
||||
use runtime::{staking, system, session};
|
||||
|
||||
const APPROVALS_REQUIRED: &[u8] = b"gov:apr";
|
||||
@@ -94,7 +94,7 @@ pub mod privileged {
|
||||
|
||||
pub mod internal {
|
||||
use super::*;
|
||||
use primitives::relay::{Proposal, InternalFunction};
|
||||
use polkadot_primitives::Proposal;
|
||||
|
||||
/// Current era is ending; we should finish up any proposals.
|
||||
pub fn end_of_an_era() {
|
||||
@@ -112,29 +112,29 @@ pub mod internal {
|
||||
}
|
||||
|
||||
fn enact_proposal(proposal: Proposal) {
|
||||
match proposal.function {
|
||||
InternalFunction::SystemSetCode(code) => {
|
||||
match proposal {
|
||||
Proposal::SystemSetCode(code) => {
|
||||
system::privileged::set_code(&code);
|
||||
}
|
||||
InternalFunction::SessionSetLength(value) => {
|
||||
Proposal::SessionSetLength(value) => {
|
||||
session::privileged::set_length(value);
|
||||
}
|
||||
InternalFunction::SessionForceNewSession => {
|
||||
Proposal::SessionForceNewSession => {
|
||||
session::privileged::force_new_session();
|
||||
}
|
||||
InternalFunction::StakingSetSessionsPerEra(value) => {
|
||||
Proposal::StakingSetSessionsPerEra(value) => {
|
||||
staking::privileged::set_sessions_per_era(value);
|
||||
}
|
||||
InternalFunction::StakingSetBondingDuration(value) => {
|
||||
Proposal::StakingSetBondingDuration(value) => {
|
||||
staking::privileged::set_bonding_duration(value);
|
||||
}
|
||||
InternalFunction::StakingSetValidatorCount(value) => {
|
||||
Proposal::StakingSetValidatorCount(value) => {
|
||||
staking::privileged::set_validator_count(value);
|
||||
}
|
||||
InternalFunction::StakingForceNewEra => {
|
||||
Proposal::StakingForceNewEra => {
|
||||
staking::privileged::force_new_era()
|
||||
}
|
||||
InternalFunction::GovernanceSetApprovalPpmRequired(value) => {
|
||||
Proposal::GovernanceSetApprovalPpmRequired(value) => {
|
||||
self::privileged::set_approval_ppm_required(value);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ pub mod internal {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use runtime_std::{with_externalities, twox_128, TestExternalities};
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use support::{one, two, with_env};
|
||||
use primitives::relay::{AccountId, InternalFunction};
|
||||
@@ -190,7 +190,7 @@ mod tests {
|
||||
// Block 1: Make proposal. Approve it. Era length changes.
|
||||
with_env(|e| e.block_number = 1);
|
||||
public::propose(&one, &Proposal {
|
||||
function: InternalFunction::StakingSetSessionsPerEra(2),
|
||||
function: Proposal::StakingSetSessionsPerEra(2),
|
||||
});
|
||||
public::approve(&two, 1);
|
||||
staking::internal::check_new_era();
|
||||
@@ -215,7 +215,7 @@ mod tests {
|
||||
// Block 1: Make proposal. Fail it.
|
||||
with_env(|e| e.block_number = 1);
|
||||
public::propose(&one, &Proposal {
|
||||
function: InternalFunction::StakingSetSessionsPerEra(2),
|
||||
function: Proposal::StakingSetSessionsPerEra(2),
|
||||
});
|
||||
staking::internal::check_new_era();
|
||||
assert_eq!(staking::era_length(), 1);
|
||||
@@ -223,7 +223,7 @@ mod tests {
|
||||
// Block 2: Make proposal. Approve it. It should change era length.
|
||||
with_env(|e| e.block_number = 2);
|
||||
public::propose(&one, &Proposal {
|
||||
function: InternalFunction::StakingSetSessionsPerEra(2),
|
||||
function: Proposal::StakingSetSessionsPerEra(2),
|
||||
});
|
||||
public::approve(&two, 2);
|
||||
staking::internal::check_new_era();
|
||||
@@ -248,7 +248,7 @@ mod tests {
|
||||
// Block 1: Make proposal. Will have only 1 vote. No change.
|
||||
with_env(|e| e.block_number = 1);
|
||||
public::propose(&one, &Proposal {
|
||||
function: InternalFunction::StakingSetSessionsPerEra(2),
|
||||
function: Proposal::StakingSetSessionsPerEra(2),
|
||||
});
|
||||
staking::internal::check_new_era();
|
||||
assert_eq!(staking::era_length(), 1);
|
||||
@@ -273,7 +273,7 @@ mod tests {
|
||||
// Block 1: Make proposal. Will have only 1 vote. No change.
|
||||
with_env(|e| e.block_number = 1);
|
||||
public::propose(&one, &Proposal {
|
||||
function: InternalFunction::StakingSetSessionsPerEra(2),
|
||||
function: Proposal::StakingSetSessionsPerEra(2),
|
||||
});
|
||||
public::approve(&two, 0);
|
||||
staking::internal::check_new_era();
|
||||
@@ -299,7 +299,7 @@ mod tests {
|
||||
// Block 1: Make proposal. Will have only 1 vote. No change.
|
||||
with_env(|e| e.block_number = 1);
|
||||
public::propose(&one, &Proposal {
|
||||
function: InternalFunction::StakingSetSessionsPerEra(2),
|
||||
function: Proposal::StakingSetSessionsPerEra(2),
|
||||
});
|
||||
public::approve(&two, 1);
|
||||
public::approve(&two, 1);
|
||||
@@ -326,10 +326,10 @@ mod tests {
|
||||
// Block 1: Make proposal. Will have only 1 vote. No change.
|
||||
with_env(|e| e.block_number = 1);
|
||||
public::propose(&one, &Proposal {
|
||||
function: InternalFunction::StakingSetSessionsPerEra(2),
|
||||
function: Proposal::StakingSetSessionsPerEra(2),
|
||||
});
|
||||
public::propose(&two, &Proposal {
|
||||
function: InternalFunction::StakingSetSessionsPerEra(2),
|
||||
function: Proposal::StakingSetSessionsPerEra(2),
|
||||
});
|
||||
staking::internal::check_new_era();
|
||||
assert_eq!(staking::era_length(), 1);
|
||||
@@ -378,7 +378,7 @@ mod tests {
|
||||
// Block 1: Make proposal. Will have only 1 vote. No change.
|
||||
with_env(|e| e.block_number = 1);
|
||||
public::propose(&one, &Proposal {
|
||||
function: InternalFunction::StakingSetSessionsPerEra(2),
|
||||
function: Proposal::StakingSetSessionsPerEra(2),
|
||||
});
|
||||
public::approve(&four, 1);
|
||||
staking::internal::check_new_era();
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
//! Main parachains logic. For now this is just the determination of which validators do what.
|
||||
|
||||
use runtime_std::prelude::*;
|
||||
use runtime_std::mem;
|
||||
use rstd::prelude::*;
|
||||
use runtime_io::mem;
|
||||
use codec::{Slicable, Joiner};
|
||||
use support::{Hashable, with_env, storage};
|
||||
use runtime::session;
|
||||
@@ -96,7 +96,7 @@ pub fn calculate_duty_roster() -> DutyRoster {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use runtime_std::{with_externalities, twox_128, TestExternalities};
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use support::{one, two, with_env};
|
||||
use runtime::{consensus, session};
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
//! Session manager: is told the validators and allows them to manage their session keys for the
|
||||
//! consensus module.
|
||||
|
||||
use runtime_std::prelude::*;
|
||||
use rstd::prelude::*;
|
||||
use codec::KeyedVec;
|
||||
use support::{storage, StorageVec};
|
||||
use primitives::relay::{AccountId, SessionKey, BlockNumber};
|
||||
use polkadot_primitives::{AccountId, SessionKey, BlockNumber};
|
||||
use runtime::{system, staking, consensus};
|
||||
|
||||
const SESSION_LENGTH: &[u8] = b"ses:len";
|
||||
@@ -137,7 +137,7 @@ mod tests {
|
||||
use super::public::*;
|
||||
use super::privileged::*;
|
||||
use super::internal::*;
|
||||
use runtime_std::{with_externalities, twox_128, TestExternalities};
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use support::{one, two, with_env};
|
||||
use primitives::relay::AccountId;
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
//! Staking manager: Handles balances and periodically determines the best set of validators.
|
||||
|
||||
use runtime_std::prelude::*;
|
||||
use runtime_std::cell::RefCell;
|
||||
use runtime_std::print;
|
||||
use rstd::prelude::*;
|
||||
use runtime_io::cell::RefCell;
|
||||
use runtime_io::print;
|
||||
use codec::KeyedVec;
|
||||
use support::{storage, StorageVec};
|
||||
use primitives::relay::{BlockNumber, AccountId};
|
||||
use polkadot_primitives::{BlockNumber, AccountId};
|
||||
use runtime::{system, session, governance};
|
||||
|
||||
/// The balance of an account.
|
||||
@@ -213,7 +213,7 @@ mod tests {
|
||||
use super::public::*;
|
||||
use super::privileged::*;
|
||||
|
||||
use runtime_std::{with_externalities, twox_128, TestExternalities};
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use support::{one, two, with_env};
|
||||
use primitives::relay::AccountId;
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
//! System manager: Handles all of the top-level stuff; executing block/transaction, setting code
|
||||
//! and depositing logs.
|
||||
|
||||
use runtime_std::prelude::*;
|
||||
use runtime_std::{mem, storage_root, enumerated_trie_root};
|
||||
use rstd::prelude::*;
|
||||
use runtime_io::{mem, storage_root, enumerated_trie_root};
|
||||
use codec::{KeyedVec, Slicable};
|
||||
use support::{Hashable, storage, with_env};
|
||||
use primitives::relay::{AccountId, Hash, TxOrder, BlockNumber, Block, Header, UncheckedTransaction,
|
||||
Function, Log};
|
||||
use polkadot_primitives::{AccountId, Hash, TxOrder, BlockNumber, Block, Header,
|
||||
UncheckedTransaction, Function, Log};
|
||||
use runtime::{staking, session};
|
||||
|
||||
const NONCE_OF: &[u8] = b"sys:non:";
|
||||
@@ -218,7 +218,7 @@ mod tests {
|
||||
use super::*;
|
||||
use super::internal::*;
|
||||
|
||||
use runtime_std::{with_externalities, twox_128, TestExternalities};
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{Joiner, KeyedVec, Slicable};
|
||||
use support::{StaticHexInto, HexDisplay, one, two};
|
||||
use primitives::relay::{Header, Digest, UncheckedTransaction, Transaction, Function};
|
||||
|
||||
@@ -41,7 +41,7 @@ mod tests {
|
||||
use super::*;
|
||||
use super::public::*;
|
||||
|
||||
use runtime_std::{with_externalities, twox_128, TestExternalities};
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use runtime::timestamp;
|
||||
use codec::{Joiner, KeyedVec};
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
//! Environment API: Allows certain information to be accessed throughout the runtime.
|
||||
|
||||
use runtime_std::boxed::Box;
|
||||
use runtime_std::mem;
|
||||
use runtime_std::cell::RefCell;
|
||||
use runtime_std::rc::Rc;
|
||||
use runtime_io::boxed::Box;
|
||||
use runtime_io::mem;
|
||||
use runtime_io::cell::RefCell;
|
||||
use runtime_io::rc::Rc;
|
||||
|
||||
use primitives::relay::{BlockNumber, Digest, Hash};
|
||||
use polkadot_primitives::{BlockNumber, Digest, Hash};
|
||||
|
||||
#[derive(Default)]
|
||||
/// The information that can be accessed globally.
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! Hashable trait.
|
||||
|
||||
use codec::Slicable;
|
||||
use runtime_std::{blake2_256, twox_128, twox_256};
|
||||
use runtime_io::{blake2_256, twox_128, twox_256};
|
||||
|
||||
pub trait Hashable: Sized {
|
||||
fn blake2_256(&self) -> [u8; 32];
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
|
||||
//! Stuff to do with the runtime's storage.
|
||||
|
||||
use runtime_std::prelude::*;
|
||||
use runtime_std::{self, twox_128};
|
||||
use rstd::prelude::*;
|
||||
use runtime_io::{self, twox_128};
|
||||
use codec::{Slicable, KeyedVec};
|
||||
|
||||
// TODO: consider using blake256 to avoid possible preimage attack.
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `None` if there is no explicit entry.
|
||||
pub fn get<T: Slicable + Sized>(key: &[u8]) -> Option<T> {
|
||||
let raw = runtime_std::storage(&twox_128(key)[..]);
|
||||
let raw = runtime_io::storage(&twox_128(key)[..]);
|
||||
Slicable::from_slice(&mut &raw[..])
|
||||
}
|
||||
|
||||
@@ -48,12 +48,12 @@ pub fn get_or_else<T: Slicable + Sized, F: FnOnce() -> T>(key: &[u8], default_va
|
||||
|
||||
/// Please `value` in storage under `key`.
|
||||
pub fn put<T: Slicable>(key: &[u8], value: &T) {
|
||||
value.as_slice_then(|slice| runtime_std::set_storage(&twox_128(key)[..], slice));
|
||||
value.as_slice_then(|slice| runtime_io::set_storage(&twox_128(key)[..], slice));
|
||||
}
|
||||
|
||||
/// Please `value` in storage under `key`.
|
||||
pub fn place<T: Slicable>(key: &[u8], value: T) {
|
||||
value.as_slice_then(|slice| runtime_std::set_storage(&twox_128(key)[..], slice));
|
||||
value.as_slice_then(|slice| runtime_io::set_storage(&twox_128(key)[..], slice));
|
||||
}
|
||||
|
||||
/// Remove `key` from storage, returning its value if it had an explicit entry or `None` otherwise.
|
||||
@@ -86,22 +86,22 @@ pub fn take_or_else<T: Slicable + Sized, F: FnOnce() -> T>(key: &[u8], default_v
|
||||
/// Check to see if `key` has an explicit entry in storage.
|
||||
pub fn exists(key: &[u8]) -> bool {
|
||||
let mut x = [0u8; 1];
|
||||
runtime_std::read_storage(&twox_128(key)[..], &mut x[..], 0) >= 1
|
||||
runtime_io::read_storage(&twox_128(key)[..], &mut x[..], 0) >= 1
|
||||
}
|
||||
|
||||
/// Ensure `key` has no explicit entry in storage.
|
||||
pub fn kill(key: &[u8]) {
|
||||
runtime_std::set_storage(&twox_128(key)[..], b"");
|
||||
runtime_io::set_storage(&twox_128(key)[..], b"");
|
||||
}
|
||||
|
||||
/// Get a Vec of bytes from storage.
|
||||
pub fn get_raw(key: &[u8]) -> Vec<u8> {
|
||||
runtime_std::storage(&twox_128(key)[..])
|
||||
runtime_io::storage(&twox_128(key)[..])
|
||||
}
|
||||
|
||||
/// Put a raw byte slice into storage.
|
||||
pub fn put_raw(key: &[u8], value: &[u8]) {
|
||||
runtime_std::set_storage(&twox_128(key)[..], value)
|
||||
runtime_io::set_storage(&twox_128(key)[..], value)
|
||||
}
|
||||
|
||||
/// A trait to conveniently store a vector of storable data.
|
||||
@@ -142,11 +142,11 @@ pub trait StorageVec {
|
||||
}
|
||||
|
||||
pub mod unhashed {
|
||||
use super::{runtime_std, Slicable, KeyedVec, Vec};
|
||||
use super::{runtime_io, Slicable, KeyedVec, Vec};
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `None` if there is no explicit entry.
|
||||
pub fn get<T: Slicable + Sized>(key: &[u8]) -> Option<T> {
|
||||
let raw = runtime_std::storage(key);
|
||||
let raw = runtime_io::storage(key);
|
||||
T::from_slice(&mut &raw[..])
|
||||
}
|
||||
|
||||
@@ -170,12 +170,12 @@ pub mod unhashed {
|
||||
|
||||
/// Please `value` in storage under `key`.
|
||||
pub fn put<T: Slicable>(key: &[u8], value: &T) {
|
||||
value.as_slice_then(|slice| runtime_std::set_storage(key, slice));
|
||||
value.as_slice_then(|slice| runtime_io::set_storage(key, slice));
|
||||
}
|
||||
|
||||
/// Please `value` in storage under `key`.
|
||||
pub fn place<T: Slicable>(key: &[u8], value: T) {
|
||||
value.as_slice_then(|slice| runtime_std::set_storage(key, slice));
|
||||
value.as_slice_then(|slice| runtime_io::set_storage(key, slice));
|
||||
}
|
||||
|
||||
/// Remove `key` from storage, returning its value if it had an explicit entry or `None` otherwise.
|
||||
@@ -208,22 +208,22 @@ pub mod unhashed {
|
||||
/// Check to see if `key` has an explicit entry in storage.
|
||||
pub fn exists(key: &[u8]) -> bool {
|
||||
let mut x = [0u8; 1];
|
||||
runtime_std::read_storage(key, &mut x[..], 0) >= 1
|
||||
runtime_io::read_storage(key, &mut x[..], 0) >= 1
|
||||
}
|
||||
|
||||
/// Ensure `key` has no explicit entry in storage.
|
||||
pub fn kill(key: &[u8]) {
|
||||
runtime_std::set_storage(key, b"");
|
||||
runtime_io::set_storage(key, b"");
|
||||
}
|
||||
|
||||
/// Get a Vec of bytes from storage.
|
||||
pub fn get_raw(key: &[u8]) -> Vec<u8> {
|
||||
runtime_std::storage(key)
|
||||
runtime_io::storage(key)
|
||||
}
|
||||
|
||||
/// Put a raw byte slice into storage.
|
||||
pub fn put_raw(key: &[u8], value: &[u8]) {
|
||||
runtime_std::set_storage(key, value)
|
||||
runtime_io::set_storage(key, value)
|
||||
}
|
||||
|
||||
/// A trait to conveniently store a vector of storable data.
|
||||
@@ -269,7 +269,7 @@ mod tests {
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
use support::HexDisplay;
|
||||
use runtime_std::{storage, twox_128, TestExternalities, with_externalities};
|
||||
use runtime_io::{storage, twox_128, TestExternalities, with_externalities};
|
||||
|
||||
#[test]
|
||||
fn integers_can_be_stored() {
|
||||
@@ -310,7 +310,7 @@ mod tests {
|
||||
fn vecs_can_be_retrieved() {
|
||||
let mut t = TestExternalities { storage: HashMap::new(), };
|
||||
with_externalities(&mut t, || {
|
||||
runtime_std::set_storage(&twox_128(b":test"), b"\x0b\0\0\0Hello world");
|
||||
runtime_io::set_storage(&twox_128(b":test"), b"\x0b\0\0\0Hello world");
|
||||
let x = b"Hello world".to_vec();
|
||||
println!("Hex: {}", HexDisplay::from(&storage(&twox_128(b":test"))));
|
||||
let y = get::<Vec<u8>>(b":test").unwrap();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Testing helpers.
|
||||
|
||||
use primitives::relay::AccountId;
|
||||
use polkadot_primitives::AccountId;
|
||||
use super::statichex::StaticHexInto;
|
||||
|
||||
#[macro_export]
|
||||
|
||||
@@ -7,4 +7,4 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
polkadot-runtime-std = { path = "../../runtime-std", version = "0.1", default_features = false }
|
||||
substrate-runtime-io = { path = "../../runtime-io", version = "0.1", default_features = false }
|
||||
|
||||
@@ -7,8 +7,8 @@ extern crate alloc;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
#[macro_use]
|
||||
extern crate polkadot_runtime_std as runtime_std;
|
||||
use runtime_std::{
|
||||
extern crate substrate_runtime_io as runtime_io;
|
||||
use runtime_io::{
|
||||
set_storage, storage, print, blake2_256,
|
||||
twox_128, twox_256, ed25519_verify, enumerated_trie_root
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user