mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-08 15:58:02 +00:00
Introduce toy runtime for testing inside substrate. (#66)
* Introduce simple blockchain runtime for substrate tests. * Remove bad files. * Add needed wasm binaries. * Refactoring. - Repot files in test-runtime. - Rename troublesome `Joiner::join` to `Joiner::and`. - Rework `Slicable` to dedup code. * More fixes and refactoring * Rebuild substrate test wasm. * Fix merge errors. * Rename the disasterously named `to_vec` to `encode`. Also rename `as_slice_then` to `with_encoded`. * Tests for toy runtime. * Fix doc nit
This commit is contained in:
@@ -3,4 +3,5 @@
|
||||
*.swp
|
||||
polkadot/runtime/wasm/target/
|
||||
substrate/executor/wasm/target/
|
||||
substrate/test-runtime/wasm/target/
|
||||
**/._*
|
||||
|
||||
Generated
+30
@@ -1023,6 +1023,7 @@ dependencies = [
|
||||
"substrate-executor 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-runtime-io 0.1.0",
|
||||
"substrate-runtime-support 0.1.0",
|
||||
"substrate-state-machine 0.1.0",
|
||||
"triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@@ -1052,6 +1053,7 @@ dependencies = [
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-runtime-io 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"substrate-runtime-support 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1386,8 +1388,10 @@ dependencies = [
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-executor 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-runtime-support 0.1.0",
|
||||
"substrate-serializer 0.1.0",
|
||||
"substrate-state-machine 0.1.0",
|
||||
"substrate-test-runtime 0.1.0",
|
||||
"triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@@ -1507,6 +1511,19 @@ dependencies = [
|
||||
"rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-runtime-support"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"environmental 0.1.0",
|
||||
"hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-runtime-io 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"substrate-state-machine 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-serializer"
|
||||
version = "0.1.0"
|
||||
@@ -1528,6 +1545,19 @@ dependencies = [
|
||||
"triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-test-runtime"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-runtime-io 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"substrate-runtime-support 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -31,12 +31,15 @@ members = [
|
||||
"substrate/rpc",
|
||||
"substrate/runtime-io",
|
||||
"substrate/runtime-std",
|
||||
"substrate/runtime-support",
|
||||
"substrate/serializer",
|
||||
"substrate/state-machine",
|
||||
"substrate/test-runtime",
|
||||
]
|
||||
exclude = [
|
||||
"substrate/executor/wasm",
|
||||
"polkadot/runtime/wasm",
|
||||
"substrate/executor/wasm",
|
||||
"substrate/pwasm-alloc",
|
||||
"substrate/pwasm-libc",
|
||||
"substrate/test-runtime/wasm",
|
||||
]
|
||||
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
cd substrate/executor/wasm && ./build.sh && cd ../../..
|
||||
cd substrate/test-runtime/wasm && ./build.sh && cd ../../..
|
||||
cd polkadot/runtime/wasm && ./build.sh && cd ../../..
|
||||
@@ -39,11 +39,11 @@ extern crate error_chain;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
mod genesis;
|
||||
pub mod error;
|
||||
|
||||
use codec::Slicable;
|
||||
use polkadot_runtime::genesismap::{additional_storage_with_genesis, GenesisConfig};
|
||||
use client::genesis;
|
||||
|
||||
/// Parse command line arguments and start the node.
|
||||
///
|
||||
@@ -83,7 +83,7 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
storage = genesis_config.genesis_map();
|
||||
let block = genesis::construct_genesis_block(&storage);
|
||||
storage.extend(additional_storage_with_genesis(&block));
|
||||
(primitives::block::Header::decode(&mut block.header.to_vec().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
|
||||
(primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
|
||||
};
|
||||
let client = client::new_in_mem(executor, prepare_genesis)?;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ triehash = { version = "0.1" }
|
||||
ed25519 = { path = "../../substrate/ed25519" }
|
||||
substrate-codec = { path = "../../substrate/codec" }
|
||||
substrate-runtime-io = { path = "../../substrate/runtime-io" }
|
||||
substrate-runtime-support = { path = "../../substrate/runtime-support" }
|
||||
substrate-state-machine = { path = "../../substrate/state-machine" }
|
||||
substrate-executor = { path = "../../substrate/executor" }
|
||||
substrate-primitives = { path = "../../substrate/primitives" }
|
||||
|
||||
@@ -26,9 +26,9 @@ extern crate substrate_primitives as primitives;
|
||||
extern crate polkadot_primitives as polkadot_primitives;
|
||||
extern crate ed25519;
|
||||
extern crate triehash;
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
extern crate hex_literal;
|
||||
|
||||
#[cfg(test)] extern crate substrate_runtime_support as runtime_support;
|
||||
#[cfg(test)] #[macro_use] extern crate hex_literal;
|
||||
|
||||
use polkadot_runtime as runtime;
|
||||
use substrate_executor::error::{Error, ErrorKind};
|
||||
@@ -62,7 +62,7 @@ mod tests {
|
||||
use super::*;
|
||||
use substrate_executor::WasmExecutor;
|
||||
use codec::{KeyedVec, Slicable, Joiner};
|
||||
use polkadot_runtime::support::{one, two, Hashable};
|
||||
use runtime_support::{one, two, Hashable};
|
||||
use polkadot_runtime::runtime::staking::balance;
|
||||
use state_machine::{CodeExecutor, TestExternalities};
|
||||
use primitives::twox_128;
|
||||
@@ -87,7 +87,7 @@ mod tests {
|
||||
function: Function::StakingTransfer(two(), 69),
|
||||
};
|
||||
let signature = secret_for(&transaction.signed).unwrap()
|
||||
.sign(&transaction.to_vec());
|
||||
.sign(&transaction.encode());
|
||||
|
||||
UncheckedTransaction { transaction, signature }
|
||||
}
|
||||
@@ -99,7 +99,7 @@ mod tests {
|
||||
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0]
|
||||
], };
|
||||
|
||||
let r = executor().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx()));
|
||||
let r = executor().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
|
||||
assert!(r.is_err());
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ mod tests {
|
||||
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0]
|
||||
], };
|
||||
|
||||
let r = executor().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx()));
|
||||
let r = executor().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
|
||||
assert!(r.is_err());
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ mod tests {
|
||||
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
|
||||
], };
|
||||
|
||||
let r = executor().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx()));
|
||||
let r = executor().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
|
||||
assert!(r.is_ok());
|
||||
|
||||
runtime_io::with_externalities(&mut t, || {
|
||||
@@ -141,7 +141,7 @@ mod tests {
|
||||
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
|
||||
], };
|
||||
|
||||
let r = executor().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx()));
|
||||
let r = executor().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
|
||||
assert!(r.is_ok());
|
||||
|
||||
runtime_io::with_externalities(&mut t, || {
|
||||
@@ -156,20 +156,20 @@ mod tests {
|
||||
let three = [3u8; 32];
|
||||
|
||||
TestExternalities { storage: map![
|
||||
twox_128(&0u64.to_keyed_vec(b"sys:old:")).to_vec() => [69u8; 32].to_vec(),
|
||||
twox_128(b"gov:apr").to_vec() => vec![].join(&667u32),
|
||||
twox_128(b"ses:len").to_vec() => vec![].join(&2u64),
|
||||
twox_128(b"ses:val:len").to_vec() => vec![].join(&3u32),
|
||||
twox_128(&0u64.to_keyed_vec(b"sys:old:")).to_vec() => [69u8; 32].encode(),
|
||||
twox_128(b"gov:apr").to_vec() => vec![].and(&667u32),
|
||||
twox_128(b"ses:len").to_vec() => vec![].and(&2u64),
|
||||
twox_128(b"ses:val:len").to_vec() => vec![].and(&3u32),
|
||||
twox_128(&0u32.to_keyed_vec(b"ses:val:")).to_vec() => one.to_vec(),
|
||||
twox_128(&1u32.to_keyed_vec(b"ses:val:")).to_vec() => two.to_vec(),
|
||||
twox_128(&2u32.to_keyed_vec(b"ses:val:")).to_vec() => three.to_vec(),
|
||||
twox_128(b"sta:wil:len").to_vec() => vec![].join(&3u32),
|
||||
twox_128(b"sta:wil:len").to_vec() => vec![].and(&3u32),
|
||||
twox_128(&0u32.to_keyed_vec(b"sta:wil:")).to_vec() => one.to_vec(),
|
||||
twox_128(&1u32.to_keyed_vec(b"sta:wil:")).to_vec() => two.to_vec(),
|
||||
twox_128(&2u32.to_keyed_vec(b"sta:wil:")).to_vec() => three.to_vec(),
|
||||
twox_128(b"sta:spe").to_vec() => vec![].join(&2u64),
|
||||
twox_128(b"sta:vac").to_vec() => vec![].join(&3u64),
|
||||
twox_128(b"sta:era").to_vec() => vec![].join(&0u64),
|
||||
twox_128(b"sta:spe").to_vec() => vec![].and(&2u64),
|
||||
twox_128(b"sta:vac").to_vec() => vec![].and(&3u64),
|
||||
twox_128(b"sta:era").to_vec() => vec![].and(&0u64),
|
||||
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
|
||||
], }
|
||||
}
|
||||
@@ -187,12 +187,12 @@ mod tests {
|
||||
|
||||
let transactions = txs.into_iter().map(|transaction| {
|
||||
let signature = secret_for(&transaction.signed).unwrap()
|
||||
.sign(&transaction.to_vec());
|
||||
.sign(&transaction.encode());
|
||||
|
||||
UncheckedTransaction { transaction, signature }
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
let transaction_root = ordered_trie_root(transactions.iter().map(Slicable::to_vec)).0.into();
|
||||
let transaction_root = ordered_trie_root(transactions.iter().map(Slicable::encode)).0.into();
|
||||
|
||||
let header = Header {
|
||||
parent_hash,
|
||||
@@ -203,7 +203,7 @@ mod tests {
|
||||
};
|
||||
let hash = header.blake2_256();
|
||||
|
||||
(Block { header, transactions }.to_vec(), hash.into())
|
||||
(Block { header, transactions }.encode(), hash.into())
|
||||
}
|
||||
|
||||
fn block1() -> (Vec<u8>, Hash) {
|
||||
@@ -285,7 +285,7 @@ mod tests {
|
||||
], };
|
||||
|
||||
let foreign_code = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm");
|
||||
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx()));
|
||||
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
|
||||
assert!(r.is_err());
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ mod tests {
|
||||
], };
|
||||
|
||||
let foreign_code = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm");
|
||||
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx()));
|
||||
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
|
||||
assert!(r.is_ok());
|
||||
|
||||
runtime_io::with_externalities(&mut t, || {
|
||||
|
||||
@@ -42,8 +42,8 @@ impl Slicable for Log {
|
||||
Vec::<u8>::decode(input).map(Log)
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.as_slice_then(f)
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.using_encoded(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +62,8 @@ impl Slicable for Digest {
|
||||
Vec::<Log>::decode(input).map(|logs| Digest { logs })
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.logs.as_slice_then(f)
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.logs.using_encoded(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,18 +86,14 @@ impl Slicable for Block {
|
||||
Some(Block { header, transactions })
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
v.extend(self.header.to_vec());
|
||||
v.extend(self.transactions.to_vec());
|
||||
v.extend(self.header.encode());
|
||||
v.extend(self.transactions.encode());
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(self.to_vec().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
/// A relay chain block header.
|
||||
@@ -144,21 +140,17 @@ impl Slicable for Header {
|
||||
})
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
self.parent_hash.as_slice_then(|s| v.extend(s));
|
||||
self.number.as_slice_then(|s| v.extend(s));
|
||||
self.state_root.as_slice_then(|s| v.extend(s));
|
||||
self.transaction_root.as_slice_then(|s| v.extend(s));
|
||||
self.digest.as_slice_then(|s| v.extend(s));
|
||||
self.parent_hash.using_encoded(|s| v.extend(s));
|
||||
self.number.using_encoded(|s| v.extend(s));
|
||||
self.state_root.using_encoded(|s| v.extend(s));
|
||||
self.transaction_root.using_encoded(|s| v.extend(s));
|
||||
self.digest.using_encoded(|s| v.extend(s));
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(self.to_vec().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -189,7 +181,7 @@ mod tests {
|
||||
}
|
||||
}"#);
|
||||
|
||||
let v = header.to_vec();
|
||||
let v = header.encode();
|
||||
assert_eq!(Header::decode(&mut &v[..]).unwrap(), header);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ impl Slicable for Id {
|
||||
u32::decode(input).map(Id)
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.as_slice_then(f)
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.using_encoded(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,21 +66,21 @@ impl Slicable for Chain {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
match *self {
|
||||
Chain::Relay => { 0u8.as_slice_then(|s| v.extend(s)); }
|
||||
Chain::Relay => { 0u8.using_encoded(|s| v.extend(s)); }
|
||||
Chain::Parachain(id) => {
|
||||
1u8.as_slice_then(|s| v.extend(s));
|
||||
id.as_slice_then(|s| v.extend(s));
|
||||
1u8.using_encoded(|s| v.extend(s));
|
||||
id.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
}
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(&self.to_vec().as_slice())
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(&self.encode().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,17 +105,17 @@ impl Slicable for DutyRoster {
|
||||
})
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
v.extend(self.validator_duty.to_vec());
|
||||
v.extend(self.guarantor_duty.to_vec());
|
||||
v.extend(self.validator_duty.encode());
|
||||
v.extend(self.guarantor_duty.encode());
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(&self.to_vec().as_slice())
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(&self.encode().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,8 +204,8 @@ impl Slicable for Activity {
|
||||
Vec::<u8>::decode(input).map(Activity)
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.as_slice_then(f)
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.using_encoded(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,47 +113,43 @@ impl Slicable for Proposal {
|
||||
Some(function)
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
match *self {
|
||||
Proposal::SystemSetCode(ref data) => {
|
||||
(InternalFunctionId::SystemSetCode as u8).as_slice_then(|s| v.extend(s));
|
||||
data.as_slice_then(|s| v.extend(s));
|
||||
(InternalFunctionId::SystemSetCode as u8).using_encoded(|s| v.extend(s));
|
||||
data.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Proposal::SessionSetLength(ref data) => {
|
||||
(InternalFunctionId::SessionSetLength as u8).as_slice_then(|s| v.extend(s));
|
||||
data.as_slice_then(|s| v.extend(s));
|
||||
(InternalFunctionId::SessionSetLength as u8).using_encoded(|s| v.extend(s));
|
||||
data.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Proposal::SessionForceNewSession => {
|
||||
(InternalFunctionId::SessionForceNewSession as u8).as_slice_then(|s| v.extend(s));
|
||||
(InternalFunctionId::SessionForceNewSession as u8).using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Proposal::StakingSetSessionsPerEra(ref data) => {
|
||||
(InternalFunctionId::StakingSetSessionsPerEra as u8).as_slice_then(|s| v.extend(s));
|
||||
data.as_slice_then(|s| v.extend(s));
|
||||
(InternalFunctionId::StakingSetSessionsPerEra as u8).using_encoded(|s| v.extend(s));
|
||||
data.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Proposal::StakingSetBondingDuration(ref data) => {
|
||||
(InternalFunctionId::StakingSetBondingDuration as u8).as_slice_then(|s| v.extend(s));
|
||||
data.as_slice_then(|s| v.extend(s));
|
||||
(InternalFunctionId::StakingSetBondingDuration as u8).using_encoded(|s| v.extend(s));
|
||||
data.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Proposal::StakingSetValidatorCount(ref data) => {
|
||||
(InternalFunctionId::StakingSetValidatorCount as u8).as_slice_then(|s| v.extend(s));
|
||||
data.as_slice_then(|s| v.extend(s));
|
||||
(InternalFunctionId::StakingSetValidatorCount as u8).using_encoded(|s| v.extend(s));
|
||||
data.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Proposal::StakingForceNewEra => {
|
||||
(InternalFunctionId::StakingForceNewEra as u8).as_slice_then(|s| v.extend(s));
|
||||
(InternalFunctionId::StakingForceNewEra as u8).using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Proposal::GovernanceSetApprovalPpmRequired(ref data) => {
|
||||
(InternalFunctionId::GovernanceSetApprovalPpmRequired as u8).as_slice_then(|s| v.extend(s));
|
||||
data.as_slice_then(|s| v.extend(s));
|
||||
(InternalFunctionId::GovernanceSetApprovalPpmRequired as u8).using_encoded(|s| v.extend(s));
|
||||
data.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
}
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(self.to_vec().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -232,43 +228,43 @@ impl Slicable for Function {
|
||||
})
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
match *self {
|
||||
Function::TimestampSet(ref data) => {
|
||||
(FunctionId::TimestampSet as u8).as_slice_then(|s| v.extend(s));
|
||||
data.as_slice_then(|s| v.extend(s));
|
||||
(FunctionId::TimestampSet as u8).using_encoded(|s| v.extend(s));
|
||||
data.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Function::SessionSetKey(ref data) => {
|
||||
(FunctionId::SessionSetKey as u8).as_slice_then(|s| v.extend(s));
|
||||
data.as_slice_then(|s| v.extend(s));
|
||||
(FunctionId::SessionSetKey as u8).using_encoded(|s| v.extend(s));
|
||||
data.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Function::StakingStake => {
|
||||
(FunctionId::StakingStake as u8).as_slice_then(|s| v.extend(s));
|
||||
(FunctionId::StakingStake as u8).using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Function::StakingUnstake => {
|
||||
(FunctionId::StakingUnstake as u8).as_slice_then(|s| v.extend(s));
|
||||
(FunctionId::StakingUnstake as u8).using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Function::StakingTransfer(ref to, ref amount) => {
|
||||
(FunctionId::StakingTransfer as u8).as_slice_then(|s| v.extend(s));
|
||||
to.as_slice_then(|s| v.extend(s));
|
||||
amount.as_slice_then(|s| v.extend(s));
|
||||
(FunctionId::StakingTransfer as u8).using_encoded(|s| v.extend(s));
|
||||
to.using_encoded(|s| v.extend(s));
|
||||
amount.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Function::GovernancePropose(ref data) => {
|
||||
(FunctionId::GovernancePropose as u8).as_slice_then(|s| v.extend(s));
|
||||
data.as_slice_then(|s| v.extend(s));
|
||||
(FunctionId::GovernancePropose as u8).using_encoded(|s| v.extend(s));
|
||||
data.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
Function::GovernanceApprove(ref data) => {
|
||||
(FunctionId::GovernanceApprove as u8).as_slice_then(|s| v.extend(s));
|
||||
data.as_slice_then(|s| v.extend(s));
|
||||
(FunctionId::GovernanceApprove as u8).using_encoded(|s| v.extend(s));
|
||||
data.using_encoded(|s| v.extend(s));
|
||||
}
|
||||
}
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(self.to_vec().as_slice())
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(self.encode().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,19 +289,15 @@ impl Slicable for Transaction {
|
||||
})
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
self.signed.as_slice_then(|s| v.extend(s));
|
||||
self.nonce.as_slice_then(|s| v.extend(s));
|
||||
self.function.as_slice_then(|s| v.extend(s));
|
||||
self.signed.using_encoded(|s| v.extend(s));
|
||||
self.nonce.using_encoded(|s| v.extend(s));
|
||||
self.function.using_encoded(|s| v.extend(s));
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(self.to_vec().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl ::codec::NonTrivialSlicable for Transaction {}
|
||||
@@ -334,27 +326,23 @@ impl Slicable for UncheckedTransaction {
|
||||
})
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
// need to prefix with the total length as u32 to ensure it's binary comptible with
|
||||
// Vec<u8>. we'll make room for it here, then overwrite once we know the length.
|
||||
v.extend(&[0u8; 4]);
|
||||
|
||||
self.transaction.signed.as_slice_then(|s| v.extend(s));
|
||||
self.transaction.nonce.as_slice_then(|s| v.extend(s));
|
||||
self.transaction.function.as_slice_then(|s| v.extend(s));
|
||||
self.signature.as_slice_then(|s| v.extend(s));
|
||||
self.transaction.signed.using_encoded(|s| v.extend(s));
|
||||
self.transaction.nonce.using_encoded(|s| v.extend(s));
|
||||
self.transaction.function.using_encoded(|s| v.extend(s));
|
||||
self.signature.using_encoded(|s| v.extend(s));
|
||||
|
||||
let length = (v.len() - 4) as u32;
|
||||
length.as_slice_then(|s| v[0..4].copy_from_slice(s));
|
||||
length.using_encoded(|s| v[0..4].copy_from_slice(s));
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(self.to_vec().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl ::codec::NonTrivialSlicable for UncheckedTransaction {}
|
||||
@@ -396,7 +384,7 @@ mod tests {
|
||||
// df0f0200
|
||||
// 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
|
||||
let v = Slicable::to_vec(&tx);
|
||||
let v = Slicable::encode(&tx);
|
||||
println!("{}", HexDisplay::from(&v));
|
||||
assert_eq!(UncheckedTransaction::decode(&mut &v[..]).unwrap(), tx);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ log = { version = "0.3", optional = true }
|
||||
substrate-codec = { path = "../../substrate/codec" }
|
||||
substrate-runtime-std = { path = "../../substrate/runtime-std" }
|
||||
substrate-runtime-io = { path = "../../substrate/runtime-io" }
|
||||
substrate-runtime-support = { path = "../../substrate/runtime-support" }
|
||||
substrate-primitives = { path = "../../substrate/primitives" }
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
|
||||
@@ -19,6 +20,7 @@ std = [
|
||||
"substrate-codec/std",
|
||||
"substrate-runtime-std/std",
|
||||
"substrate-runtime-io/std",
|
||||
"substrate-runtime-support/std",
|
||||
"substrate-primitives/std",
|
||||
"polkadot-primitives/std",
|
||||
"log"
|
||||
|
||||
@@ -17,11 +17,12 @@
|
||||
//! Tool for creating the genesis block.
|
||||
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use polkadot_primitives::{BlockNumber, Block, AccountId};
|
||||
use std::collections::HashMap;
|
||||
use runtime_io::twox_128;
|
||||
use runtime_support::Hashable;
|
||||
use primitives::Block;
|
||||
use polkadot_primitives::{BlockNumber, AccountId};
|
||||
use runtime::staking::Balance;
|
||||
use support::Hashable;
|
||||
|
||||
/// Configuration of a general Polkadot genesis block.
|
||||
pub struct GenesisConfig {
|
||||
@@ -52,32 +53,32 @@ impl GenesisConfig {
|
||||
pub fn genesis_map(&self) -> HashMap<Vec<u8>, Vec<u8>> {
|
||||
let wasm_runtime = include_bytes!("../wasm/genesis.wasm").to_vec();
|
||||
vec![
|
||||
(&b"gov:apr"[..], vec![].join(&self.approval_ratio)),
|
||||
(&b"ses:len"[..], vec![].join(&self.session_length)),
|
||||
(&b"ses:val:len"[..], vec![].join(&(self.validators.len() as u32))),
|
||||
(&b"sta:wil:len"[..], vec![].join(&0u32)),
|
||||
(&b"sta:spe"[..], vec![].join(&self.sessions_per_era)),
|
||||
(&b"sta:vac"[..], vec![].join(&(self.validators.len() as u32))),
|
||||
(&b"sta:era"[..], vec![].join(&0u64)),
|
||||
(&b"gov:apr"[..], vec![].and(&self.approval_ratio)),
|
||||
(&b"ses:len"[..], vec![].and(&self.session_length)),
|
||||
(&b"ses:val:len"[..], vec![].and(&(self.validators.len() as u32))),
|
||||
(&b"sta:wil:len"[..], vec![].and(&0u32)),
|
||||
(&b"sta:spe"[..], vec![].and(&self.sessions_per_era)),
|
||||
(&b"sta:vac"[..], vec![].and(&(self.validators.len() as u32))),
|
||||
(&b"sta:era"[..], vec![].and(&0u64)),
|
||||
].into_iter()
|
||||
.map(|(k, v)| (k.into(), v))
|
||||
.chain(self.validators.iter()
|
||||
.enumerate()
|
||||
.map(|(i, account)| ((i as u32).to_keyed_vec(b"ses:val:"), vec![].join(account)))
|
||||
.map(|(i, account)| ((i as u32).to_keyed_vec(b"ses:val:"), vec![].and(account)))
|
||||
).chain(self.authorities.iter()
|
||||
.enumerate()
|
||||
.map(|(i, account)| ((i as u32).to_keyed_vec(b":auth:"), vec![].join(account)))
|
||||
.map(|(i, account)| ((i as u32).to_keyed_vec(b":auth:"), vec![].and(account)))
|
||||
).chain(self.balances.iter()
|
||||
.map(|&(account, balance)| (account.to_keyed_vec(b"sta:bal:"), vec![].join(&balance)))
|
||||
.map(|&(account, balance)| (account.to_keyed_vec(b"sta:bal:"), vec![].and(&balance)))
|
||||
)
|
||||
.map(|(k, v)| (twox_128(&k[..])[..].to_vec(), v.to_vec()))
|
||||
.chain(vec![
|
||||
(b":code"[..].into(), wasm_runtime),
|
||||
(b":auth:len"[..].into(), vec![].join(&(self.authorities.len() as u32))),
|
||||
(b":auth:len"[..].into(), vec![].and(&(self.authorities.len() as u32))),
|
||||
].into_iter())
|
||||
.chain(self.authorities.iter()
|
||||
.enumerate()
|
||||
.map(|(i, account)| ((i as u32).to_keyed_vec(b":auth:"), vec![].join(account)))
|
||||
.map(|(i, account)| ((i as u32).to_keyed_vec(b":auth:"), vec![].and(account)))
|
||||
)
|
||||
.collect()
|
||||
}
|
||||
@@ -86,6 +87,6 @@ impl GenesisConfig {
|
||||
pub fn additional_storage_with_genesis(genesis_block: &Block) -> HashMap<Vec<u8>, Vec<u8>> {
|
||||
use codec::Slicable;
|
||||
map![
|
||||
twox_128(&0u64.to_keyed_vec(b"sys:old:")).to_vec() => genesis_block.header.blake2_256().to_vec()
|
||||
twox_128(&0u64.to_keyed_vec(b"sys:old:")).to_vec() => genesis_block.header.blake2_256().encode()
|
||||
]
|
||||
}
|
||||
|
||||
@@ -19,28 +19,22 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
extern crate substrate_runtime_std as rstd;
|
||||
#[macro_use] extern crate substrate_runtime_io as runtime_io;
|
||||
extern crate substrate_runtime_support as runtime_support;
|
||||
|
||||
#[macro_use]
|
||||
extern crate substrate_runtime_io as runtime_io;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
extern crate rustc_hex;
|
||||
#[cfg(feature = "std")] extern crate rustc_hex;
|
||||
|
||||
extern crate substrate_codec as codec;
|
||||
extern crate substrate_primitives;
|
||||
#[cfg(feature = "std")] #[macro_use] extern crate substrate_primitives as primitives;
|
||||
extern crate polkadot_primitives;
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
extern crate hex_literal;
|
||||
#[cfg(test)] #[macro_use] extern crate hex_literal;
|
||||
|
||||
#[macro_use]
|
||||
pub mod support;
|
||||
pub mod environment;
|
||||
pub mod runtime;
|
||||
pub mod api;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub mod genesismap;
|
||||
#[cfg(feature = "std")] pub mod genesismap;
|
||||
|
||||
/// Type definitions and helpers for transactions.
|
||||
pub mod transaction {
|
||||
@@ -72,7 +66,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);
|
||||
let msg = ::codec::Slicable::encode(&tx.transaction);
|
||||
if ::runtime_io::ed25519_verify(&tx.signature.0, &msg, &tx.transaction.signed) {
|
||||
Ok(CheckedTransaction(tx))
|
||||
} else {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! Conensus module for runtime; manages the authority set ready for the native code.
|
||||
|
||||
use rstd::prelude::*;
|
||||
use support::storage::unhashed::StorageVec;
|
||||
use runtime_support::storage::unhashed::StorageVec;
|
||||
use polkadot_primitives::SessionKey;
|
||||
|
||||
struct AuthorityStorageVec {}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
use rstd::prelude::*;
|
||||
use codec::KeyedVec;
|
||||
use support::storage;
|
||||
use runtime_support::storage;
|
||||
use polkadot_primitives::{Proposal, AccountId, Hash, BlockNumber};
|
||||
use runtime::{staking, system, session};
|
||||
|
||||
@@ -147,7 +147,8 @@ mod tests {
|
||||
use super::*;
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use support::{one, two, with_env};
|
||||
use runtime_support::{one, two};
|
||||
use environment::with_env;
|
||||
use polkadot_primitives::{AccountId, Proposal};
|
||||
use runtime::{staking, session};
|
||||
|
||||
@@ -157,19 +158,19 @@ mod tests {
|
||||
let three = [3u8; 32];
|
||||
|
||||
TestExternalities { storage: map![
|
||||
twox_128(APPROVALS_REQUIRED).to_vec() => vec![].join(&667u32),
|
||||
twox_128(b"ses:len").to_vec() => vec![].join(&1u64),
|
||||
twox_128(b"ses:val:len").to_vec() => vec![].join(&3u32),
|
||||
twox_128(APPROVALS_REQUIRED).to_vec() => vec![].and(&667u32),
|
||||
twox_128(b"ses:len").to_vec() => vec![].and(&1u64),
|
||||
twox_128(b"ses:val:len").to_vec() => vec![].and(&3u32),
|
||||
twox_128(&0u32.to_keyed_vec(b"ses:val:")).to_vec() => one.to_vec(),
|
||||
twox_128(&1u32.to_keyed_vec(b"ses:val:")).to_vec() => two.to_vec(),
|
||||
twox_128(&2u32.to_keyed_vec(b"ses:val:")).to_vec() => three.to_vec(),
|
||||
twox_128(b"sta:wil:len").to_vec() => vec![].join(&3u32),
|
||||
twox_128(b"sta:wil:len").to_vec() => vec![].and(&3u32),
|
||||
twox_128(&0u32.to_keyed_vec(b"sta:wil:")).to_vec() => one.to_vec(),
|
||||
twox_128(&1u32.to_keyed_vec(b"sta:wil:")).to_vec() => two.to_vec(),
|
||||
twox_128(&2u32.to_keyed_vec(b"sta:wil:")).to_vec() => three.to_vec(),
|
||||
twox_128(b"sta:spe").to_vec() => vec![].join(&1u64),
|
||||
twox_128(b"sta:vac").to_vec() => vec![].join(&3u64),
|
||||
twox_128(b"sta:era").to_vec() => vec![].join(&1u64)
|
||||
twox_128(b"sta:spe").to_vec() => vec![].and(&1u64),
|
||||
twox_128(b"sta:vac").to_vec() => vec![].and(&3u64),
|
||||
twox_128(b"sta:era").to_vec() => vec![].and(&1u64)
|
||||
], }
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
|
||||
use rstd::prelude::*;
|
||||
use codec::{Slicable, Joiner};
|
||||
use runtime_support::{Hashable, storage};
|
||||
use environment::with_env;
|
||||
use runtime::session;
|
||||
use support::{Hashable, with_env, storage};
|
||||
use polkadot_primitives::parachain::{Id, Chain, DutyRoster};
|
||||
|
||||
const PARACHAIN_COUNT: &[u8] = b"par:cou";
|
||||
@@ -43,7 +44,7 @@ pub fn calculate_duty_roster() -> DutyRoster {
|
||||
let mut roles_gua = roles_val.clone();
|
||||
|
||||
let h = with_env(|e| e.parent_hash.clone());
|
||||
let mut seed = Vec::<u8>::new().join(&h).join(b"validator_role_pairs").blake2_256();
|
||||
let mut seed = Vec::<u8>::new().and(&h).and(b"validator_role_pairs").blake2_256();
|
||||
|
||||
// shuffle
|
||||
for i in 0..(validator_count - 1) {
|
||||
@@ -78,13 +79,13 @@ mod tests {
|
||||
use super::*;
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use support::{one, two, with_env};
|
||||
use runtime_support::{one, two};
|
||||
use runtime::{consensus, session};
|
||||
|
||||
fn simple_setup() -> TestExternalities {
|
||||
TestExternalities { storage: map![
|
||||
twox_128(b"ses:val:len").to_vec() => vec![].join(&8u32),
|
||||
twox_128(b"par:cou").to_vec() => vec![].join(&2u32)
|
||||
twox_128(b"ses:val:len").to_vec() => vec![].and(&8u32),
|
||||
twox_128(b"par:cou").to_vec() => vec![].and(&2u32)
|
||||
], }
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
use rstd::prelude::*;
|
||||
use codec::KeyedVec;
|
||||
use support::{storage, StorageVec};
|
||||
use runtime_support::{storage, StorageVec};
|
||||
use polkadot_primitives::{AccountId, SessionKey, BlockNumber};
|
||||
use runtime::{system, staking, consensus};
|
||||
|
||||
@@ -139,19 +139,20 @@ mod tests {
|
||||
use super::internal::*;
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use support::{one, two, with_env};
|
||||
use runtime_support::{one, two};
|
||||
use environment::with_env;
|
||||
use polkadot_primitives::AccountId;
|
||||
use runtime::{consensus, session};
|
||||
|
||||
fn simple_setup() -> TestExternalities {
|
||||
TestExternalities { storage: map![
|
||||
twox_128(SESSION_LENGTH).to_vec() => vec![].join(&2u64),
|
||||
twox_128(SESSION_LENGTH).to_vec() => vec![].and(&2u64),
|
||||
// the validators (10, 20, ...)
|
||||
twox_128(b"ses:val:len").to_vec() => vec![].join(&2u32),
|
||||
twox_128(b"ses:val:len").to_vec() => vec![].and(&2u32),
|
||||
twox_128(&0u32.to_keyed_vec(ValidatorStorageVec::PREFIX)).to_vec() => vec![10; 32],
|
||||
twox_128(&1u32.to_keyed_vec(ValidatorStorageVec::PREFIX)).to_vec() => vec![20; 32],
|
||||
// initial session keys (11, 21, ...)
|
||||
b":auth:len".to_vec() => vec![].join(&2u32),
|
||||
b":auth:len".to_vec() => vec![].and(&2u32),
|
||||
0u32.to_keyed_vec(b":auth:") => vec![11; 32],
|
||||
1u32.to_keyed_vec(b":auth:") => vec![21; 32]
|
||||
], }
|
||||
|
||||
@@ -20,7 +20,7 @@ use rstd::prelude::*;
|
||||
use rstd::cell::RefCell;
|
||||
use runtime_io::print;
|
||||
use codec::KeyedVec;
|
||||
use support::{storage, StorageVec};
|
||||
use runtime_support::{storage, StorageVec};
|
||||
use polkadot_primitives::{BlockNumber, AccountId};
|
||||
use runtime::{system, session, governance};
|
||||
|
||||
@@ -215,7 +215,8 @@ mod tests {
|
||||
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use support::{one, two, with_env};
|
||||
use runtime_support::{one, two};
|
||||
use environment::with_env;
|
||||
use polkadot_primitives::AccountId;
|
||||
use runtime::{staking, session};
|
||||
|
||||
@@ -227,17 +228,17 @@ mod tests {
|
||||
let four = [4u8; 32];
|
||||
|
||||
let mut t = TestExternalities { storage: map![
|
||||
twox_128(b"ses:len").to_vec() => vec![].join(&1u64),
|
||||
twox_128(b"ses:val:len").to_vec() => vec![].join(&2u32),
|
||||
twox_128(b"ses:len").to_vec() => vec![].and(&1u64),
|
||||
twox_128(b"ses:val:len").to_vec() => vec![].and(&2u32),
|
||||
twox_128(&0u32.to_keyed_vec(b"ses:val:")).to_vec() => vec![10; 32],
|
||||
twox_128(&1u32.to_keyed_vec(b"ses:val:")).to_vec() => vec![20; 32],
|
||||
twox_128(SESSIONS_PER_ERA).to_vec() => vec![].join(&2u64),
|
||||
twox_128(VALIDATOR_COUNT).to_vec() => vec![].join(&2u32),
|
||||
twox_128(BONDING_DURATION).to_vec() => vec![].join(&3u64),
|
||||
twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].join(&10u64),
|
||||
twox_128(&two.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].join(&20u64),
|
||||
twox_128(&three.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].join(&30u64),
|
||||
twox_128(&four.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].join(&40u64)
|
||||
twox_128(SESSIONS_PER_ERA).to_vec() => vec![].and(&2u64),
|
||||
twox_128(VALIDATOR_COUNT).to_vec() => vec![].and(&2u32),
|
||||
twox_128(BONDING_DURATION).to_vec() => vec![].and(&3u64),
|
||||
twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&10u64),
|
||||
twox_128(&two.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&20u64),
|
||||
twox_128(&three.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&30u64),
|
||||
twox_128(&four.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&40u64)
|
||||
], };
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
@@ -296,8 +297,8 @@ mod tests {
|
||||
#[test]
|
||||
fn staking_eras_work() {
|
||||
let mut t = TestExternalities { storage: map![
|
||||
twox_128(b"ses:len").to_vec() => vec![].join(&1u64),
|
||||
twox_128(SESSIONS_PER_ERA).to_vec() => vec![].join(&2u64)
|
||||
twox_128(b"ses:len").to_vec() => vec![].and(&1u64),
|
||||
twox_128(SESSIONS_PER_ERA).to_vec() => vec![].and(&2u64)
|
||||
], };
|
||||
with_externalities(&mut t, || {
|
||||
assert_eq!(era_length(), 2u64);
|
||||
@@ -363,7 +364,7 @@ mod tests {
|
||||
let two = two();
|
||||
|
||||
let mut t = TestExternalities { storage: map![
|
||||
twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].join(&42u64)
|
||||
twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&42u64)
|
||||
], };
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
@@ -378,7 +379,7 @@ mod tests {
|
||||
let two = two();
|
||||
|
||||
let mut t = TestExternalities { storage: map![
|
||||
twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].join(&111u64)
|
||||
twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&111u64)
|
||||
], };
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
@@ -395,7 +396,7 @@ mod tests {
|
||||
let two = two();
|
||||
|
||||
let mut t = TestExternalities { storage: map![
|
||||
twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].join(&111u64)
|
||||
twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&111u64)
|
||||
], };
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
|
||||
@@ -21,7 +21,8 @@ use rstd::prelude::*;
|
||||
use rstd::mem;
|
||||
use runtime_io::{print, storage_root, enumerated_trie_root};
|
||||
use codec::{KeyedVec, Slicable};
|
||||
use support::{Hashable, storage, with_env};
|
||||
use runtime_support::{Hashable, storage};
|
||||
use environment::with_env;
|
||||
use polkadot_primitives::{AccountId, Hash, TxOrder, BlockNumber, Block, Header,
|
||||
UncheckedTransaction, Function, Log};
|
||||
use runtime::{staking, session};
|
||||
@@ -184,7 +185,7 @@ fn initial_checks(block: &Block) {
|
||||
);
|
||||
|
||||
// check transaction trie root represents the transactions.
|
||||
let txs = block.transactions.iter().map(Slicable::to_vec).collect::<Vec<_>>();
|
||||
let txs = block.transactions.iter().map(Slicable::encode).collect::<Vec<_>>();
|
||||
let txs = txs.iter().map(Vec::as_slice).collect::<Vec<_>>();
|
||||
let txs_root = enumerated_trie_root(&txs).into();
|
||||
info_expect_equal_hash(&header.transaction_root, &txs_root);
|
||||
@@ -213,7 +214,7 @@ fn post_finalise(header: &Header) {
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
fn info_expect_equal_hash(given: &Hash, expected: &Hash) {
|
||||
use support::HexDisplay;
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
if given != expected {
|
||||
println!("Hash: given={}, expected={}", HexDisplay::from(&given.0), HexDisplay::from(&expected.0));
|
||||
}
|
||||
@@ -235,7 +236,9 @@ mod tests {
|
||||
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{Joiner, KeyedVec, Slicable};
|
||||
use support::{StaticHexInto, HexDisplay, one, two};
|
||||
use runtime_support::{one, two};
|
||||
use environment::with_env;
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
use polkadot_primitives::{Header, Digest, UncheckedTransaction, Transaction, Function};
|
||||
use runtime::staking;
|
||||
|
||||
@@ -254,7 +257,7 @@ mod tests {
|
||||
nonce: 0,
|
||||
function: Function::StakingTransfer(two, 69),
|
||||
},
|
||||
signature: "5f9832c5a4a39e2dd4a3a0c5b400e9836beb362cb8f7d845a8291a2ae6fe366612e080e4acd0b5a75c3d0b6ee69614a68fb63698c1e76bf1f2dcd8fa617ddf05".parse().unwrap(),
|
||||
signature: hex!("5f9832c5a4a39e2dd4a3a0c5b400e9836beb362cb8f7d845a8291a2ae6fe366612e080e4acd0b5a75c3d0b6ee69614a68fb63698c1e76bf1f2dcd8fa617ddf05").into(),
|
||||
};
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
@@ -270,20 +273,20 @@ mod tests {
|
||||
let three = [3u8; 32];
|
||||
|
||||
TestExternalities { storage: map![
|
||||
twox_128(&0u64.to_keyed_vec(b"sys:old:")).to_vec() => [69u8; 32].to_vec(),
|
||||
twox_128(b"gov:apr").to_vec() => vec![].join(&667u32),
|
||||
twox_128(b"ses:len").to_vec() => vec![].join(&2u64),
|
||||
twox_128(b"ses:val:len").to_vec() => vec![].join(&3u32),
|
||||
twox_128(&0u64.to_keyed_vec(b"sys:old:")).to_vec() => [69u8; 32].encode(),
|
||||
twox_128(b"gov:apr").to_vec() => vec![].and(&667u32),
|
||||
twox_128(b"ses:len").to_vec() => vec![].and(&2u64),
|
||||
twox_128(b"ses:val:len").to_vec() => vec![].and(&3u32),
|
||||
twox_128(&0u32.to_keyed_vec(b"ses:val:")).to_vec() => one.to_vec(),
|
||||
twox_128(&1u32.to_keyed_vec(b"ses:val:")).to_vec() => two.to_vec(),
|
||||
twox_128(&2u32.to_keyed_vec(b"ses:val:")).to_vec() => three.to_vec(),
|
||||
twox_128(b"sta:wil:len").to_vec() => vec![].join(&3u32),
|
||||
twox_128(b"sta:wil:len").to_vec() => vec![].and(&3u32),
|
||||
twox_128(&0u32.to_keyed_vec(b"sta:wil:")).to_vec() => one.to_vec(),
|
||||
twox_128(&1u32.to_keyed_vec(b"sta:wil:")).to_vec() => two.to_vec(),
|
||||
twox_128(&2u32.to_keyed_vec(b"sta:wil:")).to_vec() => three.to_vec(),
|
||||
twox_128(b"sta:spe").to_vec() => vec![].join(&2u64),
|
||||
twox_128(b"sta:vac").to_vec() => vec![].join(&3u64),
|
||||
twox_128(b"sta:era").to_vec() => vec![].join(&0u64),
|
||||
twox_128(b"sta:spe").to_vec() => vec![].and(&2u64),
|
||||
twox_128(b"sta:vac").to_vec() => vec![].and(&3u64),
|
||||
twox_128(b"sta:era").to_vec() => vec![].and(&0u64),
|
||||
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
|
||||
], }
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Timestamp manager: just handles the current timestamp.
|
||||
|
||||
use support::storage;
|
||||
use runtime_support::storage;
|
||||
|
||||
pub type Timestamp = u64;
|
||||
|
||||
@@ -48,7 +48,7 @@ mod tests {
|
||||
#[test]
|
||||
fn timestamp_works() {
|
||||
let mut t = TestExternalities { storage: map![
|
||||
twox_128(CURRENT_TIMESTAMP).to_vec() => vec![].join(&42u64)
|
||||
twox_128(CURRENT_TIMESTAMP).to_vec() => vec![].and(&42u64)
|
||||
], };
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
// Copyright 2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Interpret a static string of hex as a desired type.
|
||||
|
||||
use rustc_hex::FromHex;
|
||||
|
||||
/// Trait to allow conversion from a static hex string to an instance.
|
||||
pub trait StaticHexConversion: Sized {
|
||||
/// Convert the static str into Self. Use just like `From::from`.
|
||||
fn from_static_hex(hex: &'static str) -> Self;
|
||||
}
|
||||
|
||||
macro_rules! impl_sizes {
|
||||
( $( $t:expr ),* ) => { $(
|
||||
impl StaticHexConversion for [u8; $t] {
|
||||
fn from_static_hex(hex: &'static str) -> Self {
|
||||
let mut r = [0u8; $t];
|
||||
r.copy_from_slice(&FromHex::from_hex(hex).unwrap());
|
||||
r
|
||||
}
|
||||
}
|
||||
)* }
|
||||
}
|
||||
|
||||
impl StaticHexConversion for Vec<u8> {
|
||||
fn from_static_hex(hex: &'static str) -> Self {
|
||||
FromHex::from_hex(hex).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl_sizes!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
|
||||
33, 34, 35, 36, 37, 38, 39, 40, 451, 42, 43, 44, 45, 46, 47, 48,
|
||||
56, 64, 80, 96, 112, 128);
|
||||
|
||||
/// Trait to allow converting from itself (only implemented for a static str) into some useful
|
||||
/// type (which must implement `StaticHexConversion`).
|
||||
pub trait StaticHexInto {
|
||||
/// Convert self (i.e. a static str) into the appropriate type. Use just like `Into::into`.
|
||||
fn convert<T: StaticHexConversion>(self) -> T;
|
||||
}
|
||||
|
||||
impl StaticHexInto for &'static str {
|
||||
fn convert<T: StaticHexConversion>(self) -> T {
|
||||
T::from_static_hex(self)
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
// Copyright 2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Testing helpers.
|
||||
|
||||
use polkadot_primitives::AccountId;
|
||||
use super::statichex::StaticHexInto;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! map {
|
||||
($( $name:expr => $value:expr ),*) => (
|
||||
vec![ $( ( $name, $value ) ),* ].into_iter().collect()
|
||||
)
|
||||
}
|
||||
|
||||
/// One account (to which we know the secret key).
|
||||
pub fn one() -> AccountId {
|
||||
"2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee".convert()
|
||||
}
|
||||
/// Another account (secret key known).
|
||||
pub fn two() -> AccountId {
|
||||
"d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a".convert()
|
||||
}
|
||||
|
||||
/// Hex display, this time for no_std. See main codebase for documentation.
|
||||
pub struct HexDisplay<'a>(&'a [u8]);
|
||||
|
||||
impl<'a> HexDisplay<'a> {
|
||||
/// See main codebase for documentation.
|
||||
pub fn from(d: &'a AsBytesRef) -> Self { HexDisplay(d.as_bytes_ref()) }
|
||||
}
|
||||
|
||||
impl<'a> ::std::fmt::Display for HexDisplay<'a> {
|
||||
fn fmt(&self, fmtr: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
|
||||
for byte in self.0 {
|
||||
try!( fmtr.write_fmt(format_args!("{:02x}", byte)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// See main codebase for documentation.
|
||||
pub trait AsBytesRef {
|
||||
/// See main codebase for documentation.
|
||||
fn as_bytes_ref(&self) -> &[u8];
|
||||
}
|
||||
|
||||
impl AsBytesRef for [u8] {
|
||||
fn as_bytes_ref(&self) -> &[u8] { &self }
|
||||
}
|
||||
|
||||
impl<'a> AsBytesRef for &'a[u8] {
|
||||
fn as_bytes_ref(&self) -> &[u8] { self }
|
||||
}
|
||||
|
||||
impl AsBytesRef for Vec<u8> {
|
||||
fn as_bytes_ref(&self) -> &[u8] { &self[..] }
|
||||
}
|
||||
|
||||
macro_rules! impl_non_endians {
|
||||
( $( $t:ty ),* ) => { $(
|
||||
impl AsBytesRef for $t {
|
||||
fn as_bytes_ref(&self) -> &[u8] { &self[..] }
|
||||
}
|
||||
)* }
|
||||
}
|
||||
|
||||
impl_non_endians!([u8; 1], [u8; 2], [u8; 3], [u8; 4], [u8; 5], [u8; 6], [u8; 7], [u8; 8],
|
||||
[u8; 10], [u8; 12], [u8; 14], [u8; 16], [u8; 20], [u8; 24], [u8; 28], [u8; 32], [u8; 40],
|
||||
[u8; 48], [u8; 56], [u8; 64], [u8; 80], [u8; 96], [u8; 112], [u8; 128]);
|
||||
+14
@@ -395,6 +395,7 @@ dependencies = [
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-runtime-io 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"substrate-runtime-support 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -638,6 +639,19 @@ dependencies = [
|
||||
"rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-runtime-support"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"environmental 0.1.0",
|
||||
"hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-runtime-io 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"substrate-state-machine 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-state-machine"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -10,6 +10,7 @@ crate-type = ["cdylib"]
|
||||
substrate-codec = { path = "../../../substrate/codec", default-features = false }
|
||||
substrate-runtime-std = { path = "../../../substrate/runtime-std", default-features = false }
|
||||
substrate-runtime-io = { path = "../../../substrate/runtime-io", default-features = false }
|
||||
substrate-runtime-support = { path = "../../../substrate/runtime-support", default-features = false }
|
||||
substrate-primitives = { path = "../../../substrate/primitives", default-features = false }
|
||||
polkadot-primitives = { path = "../../primitives", default-features = false }
|
||||
|
||||
@@ -19,8 +20,9 @@ std = [
|
||||
"substrate-codec/std",
|
||||
"substrate-runtime-io/std",
|
||||
"substrate-runtime-std/std",
|
||||
"substrate-runtime-support/std",
|
||||
"substrate-primitives/std",
|
||||
"polkadot-primitives/std"
|
||||
"polkadot-primitives/std",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -7,11 +7,13 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
error-chain = "0.11"
|
||||
log = "0.3"
|
||||
parking_lot = "0.4"
|
||||
substrate-primitives = { path = "../primitives", version = "0.1" }
|
||||
substrate-state-machine = { path = "../state-machine", version = "0.1" }
|
||||
substrate-serializer = { path = "../serializer" }
|
||||
substrate-executor = { path = "../executor" }
|
||||
substrate-codec = { path = "../codec", version = "0.1" }
|
||||
triehash = "0.1"
|
||||
hex-literal = "0.1"
|
||||
ed25519 = { path = "../ed25519", version = "0.1" }
|
||||
ed25519 = { path = "../ed25519" }
|
||||
substrate-codec = { path = "../codec" }
|
||||
substrate-executor = { path = "../executor" }
|
||||
substrate-primitives = { path = "../primitives" }
|
||||
substrate-runtime-support = { path = "../runtime-support" }
|
||||
substrate-serializer = { path = "../serializer" }
|
||||
substrate-state-machine = { path = "../state-machine" }
|
||||
substrate-test-runtime = { path = "../test-runtime" }
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! Tool for creating the genesis block.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use polkadot_primitives::{Block, Header};
|
||||
use primitives::{Block, Header};
|
||||
use triehash::trie_root;
|
||||
|
||||
/// Create a genesis block, given the initial storage.
|
||||
@@ -40,16 +40,36 @@ pub fn construct_genesis_block(storage: &HashMap<Vec<u8>, Vec<u8>>) -> Block {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use codec::{Slicable, Joiner};
|
||||
use polkadot_runtime::support::{one, two, Hashable};
|
||||
use polkadot_runtime::genesismap::{GenesisConfig, additional_storage_with_genesis};
|
||||
use state_machine::execute;
|
||||
use state_machine::OverlayedChanges;
|
||||
use runtime_support::{one, two, Hashable};
|
||||
use test_runtime::genesismap::{GenesisConfig, additional_storage_with_genesis};
|
||||
use executor::{NativeExecutionDispatch, NativeExecutor, WasmExecutor, with_native_environment,
|
||||
error};
|
||||
use state_machine::{execute, Externalities, OverlayedChanges};
|
||||
use state_machine::backend::InMemory;
|
||||
use polkadot_executor::executor;
|
||||
use polkadot_primitives::{AccountId, Hash, BlockNumber, Header, Digest, UncheckedTransaction,
|
||||
Transaction, Function};
|
||||
use test_runtime::{self, AccountId, Hash, Block, BlockNumber, Header, Digest, Transaction,
|
||||
UncheckedTransaction};
|
||||
use ed25519::Pair;
|
||||
|
||||
/// A null struct which implements `NativeExecutionDispatch` feeding in the hard-coded runtime.
|
||||
pub struct LocalNativeExecutionDispatch;
|
||||
|
||||
impl NativeExecutionDispatch for LocalNativeExecutionDispatch {
|
||||
fn native_equivalent() -> &'static [u8] {
|
||||
// WARNING!!! This assumes that the runtime was built *before* the main project. Until we
|
||||
// get a proper build script, this must be strictly adhered to or things will go wrong.
|
||||
include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm")
|
||||
}
|
||||
|
||||
fn dispatch(ext: &mut Externalities, method: &str, data: &[u8]) -> error::Result<Vec<u8>> {
|
||||
with_native_environment(ext, move || test_runtime::apis::dispatch(method, data))?
|
||||
.ok_or_else(|| error::ErrorKind::MethodNotFound(method.to_owned()).into())
|
||||
}
|
||||
}
|
||||
|
||||
fn executor() -> NativeExecutor<LocalNativeExecutionDispatch> {
|
||||
NativeExecutor { _dummy: Default::default() }
|
||||
}
|
||||
|
||||
fn secret_for(who: &AccountId) -> Option<Pair> {
|
||||
match who {
|
||||
x if *x == one() => Some(Pair::from_seed(b"12345678901234567890123456789012")),
|
||||
@@ -61,14 +81,14 @@ mod tests {
|
||||
fn construct_block(backend: &InMemory, number: BlockNumber, parent_hash: Hash, state_root: Hash, txs: Vec<Transaction>) -> (Vec<u8>, Hash) {
|
||||
use triehash::ordered_trie_root;
|
||||
|
||||
let transactions = txs.into_iter().map(|transaction| {
|
||||
let signature = secret_for(&transaction.signed).unwrap()
|
||||
.sign(&transaction.to_vec());
|
||||
let transactions = txs.into_iter().map(|tx| {
|
||||
let signature = secret_for(&tx.from).unwrap()
|
||||
.sign(&tx.encode());
|
||||
|
||||
UncheckedTransaction { transaction, signature }
|
||||
UncheckedTransaction { tx, signature }
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
let transaction_root = ordered_trie_root(transactions.iter().map(Slicable::to_vec)).0.into();
|
||||
let transaction_root = ordered_trie_root(transactions.iter().map(Slicable::encode)).0.into();
|
||||
|
||||
let mut header = Header {
|
||||
parent_hash,
|
||||
@@ -87,7 +107,7 @@ mod tests {
|
||||
&mut overlay,
|
||||
&executor(),
|
||||
"execute_transaction",
|
||||
&vec![].join(&header).join(tx)
|
||||
&vec![].and(&header).and(tx)
|
||||
).unwrap();
|
||||
header = Header::decode(&mut &ret_data[..]).unwrap();
|
||||
}
|
||||
@@ -97,11 +117,11 @@ mod tests {
|
||||
&mut overlay,
|
||||
&executor(),
|
||||
"finalise_block",
|
||||
&vec![].join(&header)
|
||||
&vec![].and(&header)
|
||||
).unwrap();
|
||||
header = Header::decode(&mut &ret_data[..]).unwrap();
|
||||
|
||||
(vec![].join(&Block { header, transactions }), hash.into())
|
||||
(vec![].and(&Block { header, transactions }), hash.into())
|
||||
}
|
||||
|
||||
fn block1(genesis_hash: Hash, backend: &InMemory) -> (Vec<u8>, Hash) {
|
||||
@@ -111,9 +131,10 @@ mod tests {
|
||||
genesis_hash,
|
||||
hex!("25e5b37074063ab75c889326246640729b40d0c86932edc527bc80db0e04fe5c").into(),
|
||||
vec![Transaction {
|
||||
signed: one(),
|
||||
from: one(),
|
||||
to: two(),
|
||||
amount: 69,
|
||||
nonce: 0,
|
||||
function: Function::StakingTransfer(two(), 69),
|
||||
}]
|
||||
)
|
||||
}
|
||||
@@ -139,4 +160,49 @@ mod tests {
|
||||
&b1data
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn construct_genesis_with_bad_transaction_should_panic() {
|
||||
let mut storage = GenesisConfig::new_simple(
|
||||
vec![one(), two()], 68
|
||||
).genesis_map();
|
||||
let block = construct_genesis_block(&storage);
|
||||
let genesis_hash = block.header.blake2_256().into();
|
||||
storage.extend(additional_storage_with_genesis(&block).into_iter());
|
||||
|
||||
let mut overlay = OverlayedChanges::default();
|
||||
let backend = InMemory::from(storage);
|
||||
let (b1data, _b1hash) = block1(genesis_hash, &backend);
|
||||
|
||||
let _ = execute(
|
||||
&backend,
|
||||
&mut overlay,
|
||||
&executor(),
|
||||
"execute_block",
|
||||
&b1data
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn construct_genesis_should_work_under_wasm() {
|
||||
let mut storage = GenesisConfig::new_simple(
|
||||
vec![one(), two()], 1000
|
||||
).genesis_map();
|
||||
let block = construct_genesis_block(&storage);
|
||||
let genesis_hash = block.header.blake2_256().into();
|
||||
storage.extend(additional_storage_with_genesis(&block).into_iter());
|
||||
|
||||
let mut overlay = OverlayedChanges::default();
|
||||
let backend = InMemory::from(storage);
|
||||
let (b1data, _b1hash) = block1(genesis_hash, &backend);
|
||||
|
||||
let _ = execute(
|
||||
&backend,
|
||||
&mut overlay,
|
||||
&WasmExecutor,
|
||||
"execute_block",
|
||||
&b1data
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ use primitives::block::{self, HeaderHash};
|
||||
use blockchain::{self, BlockId, BlockStatus};
|
||||
|
||||
fn header_hash(header: &block::Header) -> block::HeaderHash {
|
||||
primitives::hashing::blake2_256(&ser::to_vec(header)).into()
|
||||
primitives::hashing::blake2_256(&ser::encode(header)).into()
|
||||
}
|
||||
|
||||
struct PendingBlock {
|
||||
|
||||
@@ -22,11 +22,14 @@ extern crate substrate_primitives as primitives;
|
||||
extern crate substrate_state_machine as state_machine;
|
||||
extern crate substrate_serializer as ser;
|
||||
extern crate substrate_codec as codec;
|
||||
extern crate substrate_executor;
|
||||
extern crate substrate_executor as executor;
|
||||
extern crate ed25519;
|
||||
#[cfg(test)] extern crate substrate_runtime_support as runtime_support;
|
||||
#[cfg(test)] extern crate substrate_test_runtime as test_runtime;
|
||||
|
||||
extern crate triehash;
|
||||
extern crate parking_lot;
|
||||
#[cfg(test)] #[macro_use] extern crate hex_literal;
|
||||
#[macro_use] extern crate error_chain;
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
@@ -34,6 +37,7 @@ pub mod error;
|
||||
pub mod blockchain;
|
||||
pub mod backend;
|
||||
pub mod in_mem;
|
||||
pub mod genesis;
|
||||
|
||||
pub use blockchain::Info as ChainInfo;
|
||||
pub use blockchain::BlockId;
|
||||
|
||||
@@ -22,12 +22,12 @@ use super::slicable::Slicable;
|
||||
/// Trait to allow itself to be serialised into a value which can be extended
|
||||
/// by bytes.
|
||||
pub trait Joiner {
|
||||
fn join<V: Slicable + Sized>(self, value: &V) -> Self;
|
||||
fn and<V: Slicable + Sized>(self, value: &V) -> Self;
|
||||
}
|
||||
|
||||
impl<T> Joiner for T where T: for<'a> Extend<&'a u8> {
|
||||
fn join<V: Slicable + Sized>(mut self, value: &V) -> Self {
|
||||
value.as_slice_then(|s| self.extend(s));
|
||||
fn and<V: Slicable + Sized>(mut self, value: &V) -> Self {
|
||||
value.using_encoded(|s| self.extend(s));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ macro_rules! impl_endians {
|
||||
( $( $t:ty ),* ) => { $(
|
||||
impl KeyedVec for $t {
|
||||
fn to_keyed_vec(&self, prepend_key: &[u8]) -> Vec<u8> {
|
||||
self.as_slice_then(|slice| {
|
||||
self.using_encoded(|slice| {
|
||||
let mut r = prepend_key.to_vec();
|
||||
r.extend(slice);
|
||||
r
|
||||
|
||||
@@ -40,12 +40,16 @@ impl<'a> Input for &'a [u8] {
|
||||
pub trait Slicable: Sized {
|
||||
/// Attempt to deserialise the value from input.
|
||||
fn decode<I: Input>(value: &mut I) -> Option<Self>;
|
||||
|
||||
/// Convert self to an owned vector.
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
self.as_slice_then(|s| s.to_vec())
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
self.using_encoded(|s| s.to_vec())
|
||||
}
|
||||
|
||||
/// Convert self to a slice and then invoke the given closure with it.
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R;
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(&self.encode())
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait to mark that a type is not trivially (essentially "in place") serialisable.
|
||||
@@ -67,7 +71,7 @@ impl<T: EndianSensitive> Slicable for T {
|
||||
Some(val.from_le())
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.as_le_then(|le| {
|
||||
let size = mem::size_of::<T>();
|
||||
let value_slice = unsafe {
|
||||
@@ -96,15 +100,12 @@ impl Slicable for Vec<u8> {
|
||||
}
|
||||
})
|
||||
}
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(&self.to_vec())
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let len = self.len();
|
||||
assert!(len <= u32::max_value() as usize, "Attempted to serialize vec with too many elements.");
|
||||
|
||||
let mut r: Vec<u8> = Vec::new().join(&(len as u32));
|
||||
let mut r: Vec<u8> = Vec::new().and(&(len as u32));
|
||||
r.extend_from_slice(self);
|
||||
r
|
||||
}
|
||||
@@ -130,19 +131,19 @@ macro_rules! impl_vec_simple_array {
|
||||
})
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(&self.to_vec())
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(&self.encode())
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
use rstd::iter::Extend;
|
||||
|
||||
let len = self.len();
|
||||
assert!(len <= u32::max_value() as usize, "Attempted to serialize vec with too many elements.");
|
||||
|
||||
let mut r: Vec<u8> = Vec::new().join(&(len as u32));
|
||||
let mut r: Vec<u8> = Vec::new().and(&(len as u32));
|
||||
for item in self {
|
||||
r.extend(item.to_vec());
|
||||
r.extend(item.encode());
|
||||
}
|
||||
r
|
||||
}
|
||||
@@ -170,19 +171,15 @@ impl<T: NonTrivialSlicable> Slicable for Vec<T> {
|
||||
})
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(&self.to_vec())
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
use rstd::iter::Extend;
|
||||
|
||||
let len = self.len();
|
||||
assert!(len <= u32::max_value() as usize, "Attempted to serialize vec with too many elements.");
|
||||
|
||||
let mut r: Vec<u8> = Vec::new().join(&(len as u32));
|
||||
let mut r: Vec<u8> = Vec::new().and(&(len as u32));
|
||||
for item in self {
|
||||
r.extend(item.to_vec());
|
||||
r.extend(item.encode());
|
||||
}
|
||||
r
|
||||
}
|
||||
@@ -193,11 +190,11 @@ impl Slicable for () {
|
||||
Some(())
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(&[])
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
@@ -212,8 +209,8 @@ macro_rules! tuple_impl {
|
||||
}
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.as_slice_then(f)
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.using_encoded(f)
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -234,7 +231,7 @@ macro_rules! tuple_impl {
|
||||
))
|
||||
}
|
||||
|
||||
fn as_slice_then<RETURN, PROCESS>(&self, f: PROCESS) -> RETURN
|
||||
fn using_encoded<RETURN, PROCESS>(&self, f: PROCESS) -> RETURN
|
||||
where PROCESS: FnOnce(&[u8]) -> RETURN
|
||||
{
|
||||
let mut v = Vec::new();
|
||||
@@ -244,8 +241,8 @@ macro_rules! tuple_impl {
|
||||
$(ref $rest),+
|
||||
) = *self;
|
||||
|
||||
$first.as_slice_then(|s| v.extend(s));
|
||||
$($rest.as_slice_then(|s| v.extend(s));)+
|
||||
$first.using_encoded(|s| v.extend(s));
|
||||
$($rest.using_encoded(|s| v.extend(s));)+
|
||||
|
||||
f(v.as_slice())
|
||||
}
|
||||
@@ -271,7 +268,7 @@ mod tests {
|
||||
#[test]
|
||||
fn vec_is_slicable() {
|
||||
let v = b"Hello world".to_vec();
|
||||
v.as_slice_then(|ref slice|
|
||||
v.using_encoded(|ref slice|
|
||||
assert_eq!(slice, &b"\x0b\0\0\0Hello world")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -378,11 +378,11 @@ mod tests {
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
assert_eq!(
|
||||
WasmExecutor.call(&mut ext, &test_code[..], "test_blake2_256", &[]).unwrap(),
|
||||
blake2_256(&b""[..]).to_vec()
|
||||
blake2_256(&b""[..]).encode()
|
||||
);
|
||||
assert_eq!(
|
||||
WasmExecutor.call(&mut ext, &test_code[..], "test_blake2_256", b"Hello world!").unwrap(),
|
||||
blake2_256(&b"Hello world!"[..]).to_vec()
|
||||
blake2_256(&b"Hello world!"[..]).encode()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -435,7 +435,9 @@ mod tests {
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
assert_eq!(
|
||||
WasmExecutor.call(&mut ext, &test_code[..], "test_enumerated_trie_root", &[]).unwrap(),
|
||||
ordered_trie_root(vec![b"zero".to_vec(), b"one".to_vec(), b"two".to_vec()]).0.to_vec()
|
||||
ordered_trie_root(vec![b"zero".to_vec(), b"one".to_vec(), b"two".to_vec()]).0.encode()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,26 +14,26 @@ use runtime_io::{
|
||||
};
|
||||
|
||||
fn test_blake2_256(input: &[u8]) -> Vec<u8> {
|
||||
blake2_256(&input).to_vec()
|
||||
blake2_256(&input).encode()
|
||||
}
|
||||
|
||||
fn test_twox_256(input: &[u8]) -> Vec<u8> {
|
||||
twox_256(&input).to_vec()
|
||||
twox_256(&input).encode()
|
||||
}
|
||||
|
||||
fn test_twox_128(input: &[u8]) -> Vec<u8> {
|
||||
twox_128(&input).to_vec()
|
||||
twox_128(&input).encode()
|
||||
}
|
||||
|
||||
fn test_ed25519_verify(input: &[u8]) -> Vec<u8> {
|
||||
let sig = &input[0..64];
|
||||
let pubkey = &input[64..96];
|
||||
let msg = b"all ok!";
|
||||
[ed25519_verify(sig, &msg[..], pubkey) as u8].to_vec()
|
||||
[ed25519_verify(sig, &msg[..], pubkey) as u8].encode()
|
||||
}
|
||||
|
||||
fn test_enumerated_trie_root(_input: &[u8]) -> Vec<u8> {
|
||||
enumerated_trie_root(&[&b"zero"[..], &b"one"[..], &b"two"[..]]).to_vec()
|
||||
enumerated_trie_root(&[&b"zero"[..], &b"one"[..], &b"two"[..]]).encode()
|
||||
}
|
||||
|
||||
fn test_data_in(input: &[u8]) -> Vec<u8> {
|
||||
@@ -62,7 +62,7 @@ fn test_conditional_panic(input: &[u8]) -> Vec<u8> {
|
||||
if input.len() > 0 {
|
||||
panic!("test panic");
|
||||
}
|
||||
input.to_vec()
|
||||
input.encode()
|
||||
}
|
||||
|
||||
impl_stubs!(test_data_in, test_empty_return, test_panic, test_conditional_panic,
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -59,5 +59,5 @@ pub use network::{NonReservedPeerMode, ConnectionFilter, ConnectionDirection, Ne
|
||||
|
||||
// TODO: move it elsewhere
|
||||
fn header_hash(header: &primitives::Header) -> primitives::block::HeaderHash {
|
||||
primitives::hashing::blake2_256(&ser::to_vec(header)).into()
|
||||
primitives::hashing::blake2_256(&ser::encode(header)).into()
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ impl Slicable for Transaction {
|
||||
Vec::<u8>::decode(input).map(Transaction)
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.as_slice_then(f)
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.using_encoded(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ impl Slicable for Log {
|
||||
Vec::<u8>::decode(input).map(Log)
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.as_slice_then(f)
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.using_encoded(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ impl Slicable for Digest {
|
||||
Vec::<Log>::decode(input).map(|logs| Digest { logs })
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.logs.as_slice_then(f)
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.logs.using_encoded(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,18 +104,14 @@ impl Slicable for Block {
|
||||
})
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
v.extend(self.header.to_vec());
|
||||
v.extend(self.transactions.to_vec());
|
||||
v.extend(self.header.encode());
|
||||
v.extend(self.transactions.encode());
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(self.to_vec().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
/// A relay chain block header.
|
||||
@@ -162,21 +158,17 @@ impl Slicable for Header {
|
||||
})
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
self.parent_hash.as_slice_then(|s| v.extend(s));
|
||||
self.number.as_slice_then(|s| v.extend(s));
|
||||
self.state_root.as_slice_then(|s| v.extend(s));
|
||||
self.transaction_root.as_slice_then(|s| v.extend(s));
|
||||
self.digest.as_slice_then(|s| v.extend(s));
|
||||
self.parent_hash.using_encoded(|s| v.extend(s));
|
||||
self.number.using_encoded(|s| v.extend(s));
|
||||
self.state_root.using_encoded(|s| v.extend(s));
|
||||
self.transaction_root.using_encoded(|s| v.extend(s));
|
||||
self.digest.using_encoded(|s| v.extend(s));
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(self.to_vec().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -207,7 +199,7 @@ mod tests {
|
||||
}
|
||||
}"#);
|
||||
|
||||
let v = header.to_vec();
|
||||
let v = header.encode();
|
||||
assert_eq!(Header::decode(&mut &v[..]).unwrap(), header);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ macro_rules! impl_rest {
|
||||
<[u8; $len] as ::codec::Slicable>::decode(input).map($name)
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.as_slice_then(f)
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.using_encoded(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ extern crate substrate_serializer;
|
||||
extern crate pretty_assertions;
|
||||
|
||||
// TODO: factor out to separate crate.
|
||||
#[macro_export]
|
||||
macro_rules! try_opt {
|
||||
($e: expr) => {
|
||||
match $e {
|
||||
@@ -62,6 +63,14 @@ macro_rules! try_opt {
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! map {
|
||||
($( $name:expr => $value:expr ),*) => (
|
||||
vec![ $( ( $name, $value ) ),* ].into_iter().collect()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub mod bytes;
|
||||
#[cfg(feature = "std")]
|
||||
|
||||
@@ -138,7 +138,7 @@ macro_rules! impl_stubs {
|
||||
};
|
||||
|
||||
let output = $invoke(input);
|
||||
Some($crate::codec::Slicable::to_vec(&output))
|
||||
Some($crate::codec::Slicable::encode(&output))
|
||||
}
|
||||
)*
|
||||
_ => None,
|
||||
|
||||
@@ -199,7 +199,7 @@ macro_rules! impl_stubs {
|
||||
};
|
||||
|
||||
let output = ($invoke)(input);
|
||||
let output = $crate::codec::Slicable::to_vec(&output);
|
||||
let output = $crate::codec::Slicable::encode(&output);
|
||||
let res = output.as_ptr() as u64 + ((output.len() as u64) << 32);
|
||||
|
||||
// Leak the output vector to avoid it being freed.
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "substrate-runtime-support"
|
||||
version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
hex-literal = "0.1.0"
|
||||
substrate-runtime-std = { path = "../runtime-std", default_features = false }
|
||||
substrate-runtime-io = { path = "../runtime-io", default_features = false }
|
||||
environmental = { path = "../environmental", optional = true }
|
||||
substrate-state-machine = { path = "../state-machine", optional = true }
|
||||
substrate-primitives = { path = "../primitives", default_features = false }
|
||||
substrate-codec = { path = "../codec", default_features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"environmental",
|
||||
"substrate-state-machine",
|
||||
"substrate-primitives/std",
|
||||
"substrate-runtime-io/std",
|
||||
"substrate-codec/std",
|
||||
"substrate-runtime-std/std",
|
||||
]
|
||||
nightly = []
|
||||
strict = []
|
||||
+3
-3
@@ -27,12 +27,12 @@ pub trait Hashable: Sized {
|
||||
|
||||
impl<T: Slicable> Hashable for T {
|
||||
fn blake2_256(&self) -> [u8; 32] {
|
||||
blake2_256(&self.to_vec())
|
||||
blake2_256(&self.encode())
|
||||
}
|
||||
fn twox_128(&self) -> [u8; 16] {
|
||||
twox_128(&self.to_vec())
|
||||
twox_128(&self.encode())
|
||||
}
|
||||
fn twox_256(&self) -> [u8; 32] {
|
||||
twox_256(&self.to_vec())
|
||||
twox_256(&self.encode())
|
||||
}
|
||||
}
|
||||
+11
-8
@@ -16,21 +16,24 @@
|
||||
|
||||
//! Support code for the runtime.
|
||||
|
||||
mod environment;
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
extern crate substrate_runtime_std as rstd;
|
||||
extern crate substrate_runtime_io as runtime_io;
|
||||
extern crate substrate_codec as codec;
|
||||
extern crate substrate_primitives as primitives;
|
||||
#[macro_use]
|
||||
#[cfg(any(feature = "std", test))]
|
||||
extern crate hex_literal;
|
||||
|
||||
pub mod storage;
|
||||
mod hashable;
|
||||
#[cfg(feature = "std")]
|
||||
mod statichex;
|
||||
#[macro_use]
|
||||
#[cfg(feature = "std")]
|
||||
mod testing;
|
||||
|
||||
pub use self::environment::with_env;
|
||||
pub use self::storage::StorageVec;
|
||||
pub use self::hashable::Hashable;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use self::statichex::{StaticHexConversion, StaticHexInto};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use self::testing::{AsBytesRef, HexDisplay, one, two};
|
||||
pub use self::testing::{one, two};
|
||||
+11
-46
@@ -18,33 +18,14 @@
|
||||
|
||||
use rstd::prelude::*;
|
||||
use runtime_io::{self, twox_128};
|
||||
use codec::{Input, Slicable, KeyedVec};
|
||||
use codec::{Slicable, KeyedVec};
|
||||
|
||||
// TODO: consider using blake256 to avoid possible preimage attack.
|
||||
|
||||
struct IncrementalInput<'a> {
|
||||
key: &'a [u8],
|
||||
pos: usize,
|
||||
}
|
||||
|
||||
impl<'a> Input for IncrementalInput<'a> {
|
||||
fn read(&mut self, into: &mut [u8]) -> usize {
|
||||
let len = runtime_io::read_storage(self.key, into, self.pos);
|
||||
let read = ::rstd::cmp::min(len, into.len());
|
||||
self.pos += read;
|
||||
read
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 key = twox_128(key);
|
||||
let mut input = IncrementalInput {
|
||||
key: &key[..],
|
||||
pos: 0,
|
||||
};
|
||||
|
||||
Slicable::decode(&mut input)
|
||||
let raw = runtime_io::storage(&twox_128(key)[..]);
|
||||
Slicable::decode(&mut &raw[..])
|
||||
}
|
||||
|
||||
/// Return the value of the item in storage under `key`, or the type's default if there is no
|
||||
@@ -67,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_io::set_storage(&twox_128(key)[..], slice));
|
||||
value.using_encoded(|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_io::set_storage(&twox_128(key)[..], slice));
|
||||
value.using_encoded(|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.
|
||||
@@ -161,16 +142,12 @@ pub trait StorageVec {
|
||||
}
|
||||
|
||||
pub mod unhashed {
|
||||
use super::{runtime_io, Slicable, KeyedVec, Vec, IncrementalInput};
|
||||
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 mut input = IncrementalInput {
|
||||
key,
|
||||
pos: 0,
|
||||
};
|
||||
|
||||
T::decode(&mut input)
|
||||
let raw = runtime_io::storage(key);
|
||||
T::decode(&mut &raw[..])
|
||||
}
|
||||
|
||||
/// Return the value of the item in storage under `key`, or the type's default if there is no
|
||||
@@ -193,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_io::set_storage(key, slice));
|
||||
value.using_encoded(|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_io::set_storage(key, slice));
|
||||
value.using_encoded(|slice| runtime_io::set_storage(key, slice));
|
||||
}
|
||||
|
||||
/// Remove `key` from storage, returning its value if it had an explicit entry or `None` otherwise.
|
||||
@@ -291,7 +268,7 @@ pub mod unhashed {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
use support::HexDisplay;
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
use runtime_io::{storage, twox_128, TestExternalities, with_externalities};
|
||||
|
||||
#[test]
|
||||
@@ -358,16 +335,4 @@ mod tests {
|
||||
assert_eq!(x, y);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn proposals_can_be_stored() {
|
||||
use polkadot_primitives::Proposal;
|
||||
let mut t = TestExternalities { storage: HashMap::new(), };
|
||||
with_externalities(&mut t, || {
|
||||
let x = Proposal::StakingSetSessionsPerEra(25519);
|
||||
put(b":test", &x);
|
||||
let y: Proposal = get(b":test").unwrap();
|
||||
assert_eq!(x, y);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright 2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Testing helpers.
|
||||
|
||||
use primitives::AuthorityId;
|
||||
|
||||
/// One account (to which we know the secret key).
|
||||
pub fn one() -> AuthorityId {
|
||||
hex!("2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee")
|
||||
}
|
||||
/// Another account (secret key known).
|
||||
pub fn two() -> AuthorityId {
|
||||
hex!("d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a")
|
||||
}
|
||||
@@ -34,7 +34,7 @@ pub fn to_string_pretty<T: serde::Serialize + ?Sized>(value: &T) -> String {
|
||||
}
|
||||
|
||||
/// Serialize the given data structure as a JSON byte vector.
|
||||
pub fn to_vec<T: serde::Serialize + ?Sized>(value: &T) -> Vec<u8> {
|
||||
pub fn encode<T: serde::Serialize + ?Sized>(value: &T) -> Vec<u8> {
|
||||
serde_json::to_vec(value).expect(PROOF)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
[package]
|
||||
name = "substrate-test-runtime"
|
||||
version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
hex-literal = "0.1.0"
|
||||
log = { version = "0.3", optional = true }
|
||||
substrate-codec = { path = "../../substrate/codec" }
|
||||
substrate-runtime-std = { path = "../../substrate/runtime-std" }
|
||||
substrate-runtime-io = { path = "../../substrate/runtime-io" }
|
||||
substrate-runtime-support = { path = "../../substrate/runtime-support" }
|
||||
substrate-primitives = { path = "../../substrate/primitives" }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"substrate-codec/std",
|
||||
"substrate-runtime-std/std",
|
||||
"substrate-runtime-io/std",
|
||||
"substrate-runtime-support/std",
|
||||
"substrate-primitives/std",
|
||||
"log"
|
||||
]
|
||||
@@ -0,0 +1,48 @@
|
||||
// Copyright 2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! A toy unchecked transaction complete with signature.
|
||||
|
||||
use rstd::prelude::*;
|
||||
use codec::{Input, Slicable, Joiner};
|
||||
use super::{Header, UncheckedTransaction};
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
/// A coupling between a header and a list of transactions.
|
||||
pub struct Block {
|
||||
/// The block header.
|
||||
pub header: Header,
|
||||
/// The list of transactions in the block.
|
||||
pub transactions: Vec<UncheckedTransaction>,
|
||||
}
|
||||
|
||||
impl Slicable for Block {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
Some(Block {
|
||||
header: Slicable::decode(input)?,
|
||||
transactions: Slicable::decode(input)?,
|
||||
})
|
||||
}
|
||||
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
Vec::new()
|
||||
.and(&self.header)
|
||||
.and(&self.transactions)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::codec::NonTrivialSlicable for Block {}
|
||||
@@ -0,0 +1,68 @@
|
||||
// Copyright 2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Tool for creating the genesis block.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use runtime_io::twox_128;
|
||||
use runtime_support::Hashable;
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use primitives::AuthorityId;
|
||||
use primitives::block::Block;
|
||||
|
||||
/// Configuration of a general Substrate test genesis block.
|
||||
pub struct GenesisConfig {
|
||||
pub authorities: Vec<AuthorityId>,
|
||||
pub balances: Vec<(AuthorityId, u64)>,
|
||||
}
|
||||
|
||||
impl GenesisConfig {
|
||||
pub fn new_simple(authorities: Vec<AuthorityId>, balance: u64) -> Self {
|
||||
GenesisConfig {
|
||||
authorities: authorities.clone(),
|
||||
balances: authorities.into_iter().map(|a| (a, balance)).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn genesis_map(&self) -> HashMap<Vec<u8>, Vec<u8>> {
|
||||
let wasm_runtime = include_bytes!("../wasm/genesis.wasm").to_vec();
|
||||
self.balances.iter()
|
||||
.map(|&(account, balance)| (account.to_keyed_vec(b"balance:"), vec![].and(&balance)))
|
||||
.map(|(k, v)| (twox_128(&k[..])[..].to_vec(), v.to_vec()))
|
||||
.chain(vec![
|
||||
(b":code"[..].into(), wasm_runtime),
|
||||
(b":auth:len"[..].into(), vec![].and(&(self.authorities.len() as u32))),
|
||||
].into_iter())
|
||||
.chain(self.authorities.iter()
|
||||
.enumerate()
|
||||
.map(|(i, account)| ((i as u32).to_keyed_vec(b":auth:"), vec![].and(account)))
|
||||
)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! map {
|
||||
($( $name:expr => $value:expr ),*) => (
|
||||
vec![ $( ( $name, $value ) ),* ].into_iter().collect()
|
||||
)
|
||||
}
|
||||
|
||||
pub fn additional_storage_with_genesis(genesis_block: &Block) -> HashMap<Vec<u8>, Vec<u8>> {
|
||||
use codec::Slicable;
|
||||
map![
|
||||
twox_128(&b"latest"[..]).encode() => genesis_block.header.blake2_256().encode()
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// Copyright 2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! The Substrate runtime. This can be compiled with #[no_std], ready for Wasm.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
extern crate substrate_runtime_std as rstd;
|
||||
#[macro_use]
|
||||
extern crate substrate_runtime_io as runtime_io;
|
||||
extern crate substrate_runtime_support as runtime_support;
|
||||
extern crate substrate_codec as codec;
|
||||
#[cfg_attr(test, macro_use)] extern crate hex_literal;
|
||||
#[cfg_attr(test, macro_use)] extern crate substrate_primitives as primitives;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub mod genesismap;
|
||||
pub mod system;
|
||||
mod transaction;
|
||||
mod unchecked_transaction;
|
||||
mod block;
|
||||
|
||||
use rstd::prelude::*;
|
||||
use codec::Slicable;
|
||||
|
||||
use primitives::AuthorityId;
|
||||
use primitives::hash::H512;
|
||||
pub use primitives::hash::H256;
|
||||
pub use primitives::block::{Header, Number as BlockNumber, Digest};
|
||||
pub use transaction::Transaction;
|
||||
pub use unchecked_transaction::UncheckedTransaction;
|
||||
pub use block::Block;
|
||||
|
||||
/// An identifier for an account on this system.
|
||||
pub type AccountId = AuthorityId;
|
||||
/// Signature for our transactions.
|
||||
pub type Signature = H512;
|
||||
/// A simple hash type for all our hashing.
|
||||
pub type Hash = H256;
|
||||
|
||||
/// Run whatever tests we have.
|
||||
pub fn run_tests(mut input: &[u8]) -> Vec<u8> {
|
||||
use runtime_io::print;
|
||||
|
||||
print("run_tests...");
|
||||
let block = Block::decode(&mut input).unwrap();
|
||||
print("deserialised block.");
|
||||
let stxs = block.transactions.iter().map(Slicable::encode).collect::<Vec<_>>();
|
||||
print("reserialised transactions.");
|
||||
[stxs.len() as u8].encode()
|
||||
}
|
||||
|
||||
pub mod apis {
|
||||
use system;
|
||||
|
||||
impl_stubs!(
|
||||
execute_block => |block| system::execute_block(block),
|
||||
execute_transaction => |(header, utx)| system::execute_transaction(utx, header),
|
||||
finalise_block => |header| system::finalise_block(header)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
// Copyright 2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! System manager: Handles all of the top-level stuff; executing block/transaction, setting code
|
||||
//! and depositing logs.
|
||||
|
||||
use rstd::prelude::*;
|
||||
use runtime_io::{storage_root, enumerated_trie_root, ed25519_verify};
|
||||
use runtime_support::{Hashable, storage};
|
||||
use codec::{KeyedVec, Slicable};
|
||||
use super::{AccountId, UncheckedTransaction, H256 as Hash, Block, Header};
|
||||
|
||||
const NONCE_OF: &[u8] = b"nonce:";
|
||||
const BALANCE_OF: &[u8] = b"balance:";
|
||||
const LATEST_BLOCK_HASH: &[u8] = b"latest";
|
||||
|
||||
pub fn latest_block_hash() -> Hash {
|
||||
storage::get(LATEST_BLOCK_HASH).expect("There must always be a latest block")
|
||||
}
|
||||
|
||||
pub fn balance_of(who: AccountId) -> u64 {
|
||||
storage::get_or(&who.to_keyed_vec(BALANCE_OF), 0)
|
||||
}
|
||||
|
||||
pub fn nonce_of(who: AccountId) -> u64 {
|
||||
storage::get_or(&who.to_keyed_vec(NONCE_OF), 0)
|
||||
}
|
||||
|
||||
/// Actually execute all transitioning for `block`.
|
||||
pub fn execute_block(block: Block) {
|
||||
let ref header = block.header;
|
||||
|
||||
// check parent_hash is correct.
|
||||
assert!(
|
||||
header.number > 0 && latest_block_hash() == header.parent_hash,
|
||||
"Parent hash should be valid."
|
||||
);
|
||||
|
||||
// check transaction trie root represents the transactions.
|
||||
let txs = block.transactions.iter().map(Slicable::encode).collect::<Vec<_>>();
|
||||
let txs = txs.iter().map(Vec::as_slice).collect::<Vec<_>>();
|
||||
let txs_root = enumerated_trie_root(&txs).into();
|
||||
info_expect_equal_hash(&header.transaction_root, &txs_root);
|
||||
assert!(header.transaction_root == txs_root, "Transaction trie root must be valid.");
|
||||
|
||||
// execute transactions
|
||||
block.transactions.iter().for_each(execute_transaction_backend);
|
||||
|
||||
// check storage root.
|
||||
let storage_root = storage_root().into();
|
||||
info_expect_equal_hash(&header.state_root, &storage_root);
|
||||
assert!(header.state_root == storage_root, "Storage root must match that calculated.");
|
||||
|
||||
// put the header hash into storage.
|
||||
storage::put(LATEST_BLOCK_HASH, &header.blake2_256());
|
||||
}
|
||||
|
||||
/// Execute a transaction outside of the block execution function.
|
||||
/// This doesn't attempt to validate anything regarding the block.
|
||||
pub fn execute_transaction(utx: UncheckedTransaction, header: Header) -> Header {
|
||||
execute_transaction_backend(&utx);
|
||||
header
|
||||
}
|
||||
|
||||
/// Finalise the block - it is up the caller to ensure that all header fields are valid
|
||||
/// except state-root.
|
||||
pub fn finalise_block(mut header: Header) -> Header {
|
||||
header.state_root = storage_root().into();
|
||||
header
|
||||
}
|
||||
|
||||
fn execute_transaction_backend(utx: &UncheckedTransaction) {
|
||||
// check signature
|
||||
let ref tx = utx.tx;
|
||||
let msg = ::codec::Slicable::encode(tx);
|
||||
assert!(ed25519_verify(&utx.signature.0, &msg, &tx.from),
|
||||
"All transactions should be properly signed");
|
||||
|
||||
// check nonce
|
||||
let nonce_key = tx.from.to_keyed_vec(NONCE_OF);
|
||||
let expected_nonce: u64 = storage::get_or(&nonce_key, 0);
|
||||
assert!(tx.nonce == expected_nonce, "All transactions should have the correct nonce");
|
||||
|
||||
// increment nonce in storage
|
||||
storage::put(&nonce_key, &(expected_nonce + 1));
|
||||
|
||||
// check sender balance
|
||||
let from_balance_key = tx.from.to_keyed_vec(BALANCE_OF);
|
||||
let from_balance: u64 = storage::get_or(&from_balance_key, 0);
|
||||
assert!(tx.amount <= from_balance, "All transactions should transfer at most the sender balance");
|
||||
|
||||
// enact transfer
|
||||
let to_balance_key = tx.to.to_keyed_vec(BALANCE_OF);
|
||||
let to_balance: u64 = storage::get_or(&to_balance_key, 0);
|
||||
storage::put(&from_balance_key, &(from_balance - tx.amount));
|
||||
storage::put(&to_balance_key, &(to_balance + tx.amount));
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
fn info_expect_equal_hash(given: &Hash, expected: &Hash) {
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
if given != expected {
|
||||
println!("Hash: given={}, expected={}", HexDisplay::from(&given.0), HexDisplay::from(&expected.0));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn info_expect_equal_hash(given: &Hash, expected: &Hash) {
|
||||
if given != expected {
|
||||
::runtime_io::print("Hash not equal");
|
||||
::runtime_io::print(&given.0[..]);
|
||||
::runtime_io::print(&expected.0[..]);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{Joiner, KeyedVec, Slicable};
|
||||
use runtime_support::{one, two};
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
use ::{Header, Digest, UncheckedTransaction, Transaction};
|
||||
|
||||
fn new_test_ext() -> TestExternalities {
|
||||
let one = one();
|
||||
let two = two();
|
||||
let three = [3u8; 32];
|
||||
|
||||
TestExternalities { storage: map![
|
||||
twox_128(b"latest").to_vec() => vec![69u8; 32],
|
||||
twox_128(b":auth:len").to_vec() => vec![].and(&3u32),
|
||||
twox_128(&0u32.to_keyed_vec(b":auth:")).to_vec() => one.to_vec(),
|
||||
twox_128(&1u32.to_keyed_vec(b":auth:")).to_vec() => two.to_vec(),
|
||||
twox_128(&2u32.to_keyed_vec(b":auth:")).to_vec() => three.to_vec(),
|
||||
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
|
||||
], }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_import_works() {
|
||||
let one = one();
|
||||
let two = two();
|
||||
|
||||
let mut t = new_test_ext();
|
||||
|
||||
let h = Header {
|
||||
parent_hash: [69u8; 32].into(),
|
||||
number: 1,
|
||||
state_root: hex!("89b5f5775a45310806a77f421d66bffeff190a519c55f2dcb21f251c2b714524").into(),
|
||||
transaction_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(),
|
||||
digest: Digest { logs: vec![], },
|
||||
};
|
||||
|
||||
let b = Block {
|
||||
header: h,
|
||||
transactions: vec![],
|
||||
};
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
execute_block(b);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// Copyright 2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! A toy transaction.
|
||||
|
||||
use rstd::prelude::*;
|
||||
use codec::{Input, Slicable, Joiner};
|
||||
use super::AccountId;
|
||||
|
||||
/// An instruction to do something.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
pub struct Transaction {
|
||||
/// Who is sending.
|
||||
pub from: AccountId,
|
||||
/// Who to send to.
|
||||
pub to: AccountId,
|
||||
/// How much to send.
|
||||
pub amount: u64,
|
||||
/// How many transactions `self.from` already sent.
|
||||
pub nonce: u64,
|
||||
}
|
||||
|
||||
impl Slicable for Transaction {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
Some(Transaction {
|
||||
from: Slicable::decode(input)?,
|
||||
to: Slicable::decode(input)?,
|
||||
amount: Slicable::decode(input)?,
|
||||
nonce: Slicable::decode(input)?,
|
||||
})
|
||||
}
|
||||
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
Vec::new()
|
||||
.and(&self.from)
|
||||
.and(&self.to)
|
||||
.and(&self.amount)
|
||||
.and(&self.nonce)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::codec::NonTrivialSlicable for Transaction {}
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright 2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! A toy unchecked transaction complete with signature.
|
||||
|
||||
use rstd::prelude::*;
|
||||
use codec::{Input, Slicable};
|
||||
use super::{Signature, Transaction};
|
||||
|
||||
/// A transactions right from the external world. Unchecked.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
pub struct UncheckedTransaction {
|
||||
/// The actual transaction information.
|
||||
pub tx: Transaction,
|
||||
/// The signature; should be an Ed25519 signature applied to the serialised `transaction` field.
|
||||
pub signature: Signature,
|
||||
}
|
||||
|
||||
impl Slicable for UncheckedTransaction {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
// This is a little more complicated than usua since the binary format must be compatible
|
||||
// with substrate's generic `Vec<u8>` type. Basically this just means accepting that there
|
||||
// will be a prefix of u32, which has the total number of bytes following (we don't need
|
||||
// to use this).
|
||||
let _length_do_not_remove_me_see_above: u32 = Slicable::decode(input)?;
|
||||
Some(UncheckedTransaction {
|
||||
tx: Slicable::decode(input)?,
|
||||
signature: Slicable::decode(input)?,
|
||||
})
|
||||
}
|
||||
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
// need to prefix with the total length as u32 to ensure it's binary comptible with
|
||||
// Vec<u8>. we'll make room for it here, then overwrite once we know the length.
|
||||
v.extend(&[0u8; 4]);
|
||||
|
||||
self.tx.using_encoded(|s| v.extend(s));
|
||||
self.signature.using_encoded(|s| v.extend(s));
|
||||
|
||||
let length = (v.len() - 4) as u32;
|
||||
length.using_encoded(|s| v[0..4].copy_from_slice(s));
|
||||
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
impl ::codec::NonTrivialSlicable for UncheckedTransaction {}
|
||||
+881
@@ -0,0 +1,881 @@
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.3.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"odds 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bigint"
|
||||
version = "4.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "blake2-rfc"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "coco"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ed25519"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-primitives 0.1.0",
|
||||
"untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "elastic-array"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "environmental"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "ethcore-bigint"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bigint 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"plain_hasher 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ethcore-bytes"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ethcore-logger"
|
||||
version = "1.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"arrayvec 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"isatty 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fixed-hash"
|
||||
version = "0.1.3"
|
||||
source = "git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm#8dc457899afdaf968ff7f16140b03d1e37b01d71"
|
||||
dependencies = [
|
||||
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-zircon"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-zircon-sys"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "gcc"
|
||||
version = "0.3.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "hashdb"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heapsize"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hex-literal"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"hex-literal-impl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hex-literal-impl"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "isatty"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "keccak-hash"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cc 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tiny-keccak 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kernel32-sys"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memorydb"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bigint 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashdb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keccak-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rlp 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nodrop"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "odds"
|
||||
version = "0.2.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "owning_ref"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot_core 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot_core"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "patricia-trie"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-logger 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashdb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keccak-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memorydb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rlp 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "plain_hasher"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-hack"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-hack-impl"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "pwasm-alloc"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"pwasm-libc 0.1.0",
|
||||
"rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pwasm-libc"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.3.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon-core"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.1.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "redox_termios"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rlp"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hex"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hex"
|
||||
version = "2.0.0"
|
||||
source = "git+https://github.com/rphmeier/rustc-hex.git#ee2ec40b9062ac7769ccb9dc891d6dc2cc9009d7"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive_internals 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive_internals"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "stable_deref_trait"
|
||||
version = "1.0.0"
|
||||
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"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fixed-hash 0.1.3 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)",
|
||||
"rustc-hex 2.0.0 (git+https://github.com/rphmeier/rustc-hex.git)",
|
||||
"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",
|
||||
"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 = [
|
||||
"pwasm-alloc 0.1.0",
|
||||
"pwasm-libc 0.1.0",
|
||||
"rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-runtime-support"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"environmental 0.1.0",
|
||||
"hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-runtime-io 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"substrate-state-machine 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-state-machine"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashdb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memorydb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"patricia-trie 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-primitives 0.1.0",
|
||||
"triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-test-runtime"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-runtime-io 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"substrate-runtime-support 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.11.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "synom"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termion"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiny-keccak"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "triehash"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ethcore-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keccak-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rlp 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "twox-hash"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uint"
|
||||
version = "0.1.2"
|
||||
source = "git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm#8dc457899afdaf968ff7f16140b03d1e37b01d71"
|
||||
dependencies = [
|
||||
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "unreachable"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "untrusted"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "utf8-ranges"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-build"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4"
|
||||
"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
|
||||
"checksum arrayvec 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)" = "06f59fe10306bb78facd90d28c2038ad23ffaaefa85bac43c8a434cde383334f"
|
||||
"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef"
|
||||
"checksum bigint 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5442186ef6560f30f1ee4b9c1e4c87a35a6879d3644550cc248ec2b955eb5fcd"
|
||||
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
|
||||
"checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400"
|
||||
"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23"
|
||||
"checksum cc 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "deaf9ec656256bb25b404c51ef50097207b9cbb29c933d31f92cae5a8a0ffee0"
|
||||
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
|
||||
"checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd"
|
||||
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
|
||||
"checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda"
|
||||
"checksum either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740178ddf48b1a9e878e6d6509a1442a2d42fd2928aae8e7a6f8a36fb01981b3"
|
||||
"checksum elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "258ff6a9a94f648d0379dbd79110e057edbb53eb85cc237e33eadf8e5a30df85"
|
||||
"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b"
|
||||
"checksum ethcore-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcb5af77e74a8f70e9c3337e069c37bc82178ef1b459c02091f73c4ad5281eb5"
|
||||
"checksum ethcore-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3977c772cd6c5c22e1c7cfa208e4c3b746bd6c3a6c8eeec0999a6b2103015ad5"
|
||||
"checksum ethcore-logger 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1fd5813e49546030be7d134e775088d56b8ff4ab60617b90e93d4f0513da4c5b"
|
||||
"checksum fixed-hash 0.1.3 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)" = "<none>"
|
||||
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
||||
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
||||
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
|
||||
"checksum hashdb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d97be07c358c5b461268b4ce60304024c5fa5acfd4bd8cd743639f0252003cf5"
|
||||
"checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461"
|
||||
"checksum hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd546ef520ab3745f1aae5f2cdc6de9e6498e94d1ab138b9eb3ddfbf335847fb"
|
||||
"checksum hex-literal-impl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2ea76da4c7f1a54d01d54985566d3fdd960b2bbd7b970da024821c883c2d9631"
|
||||
"checksum isatty 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f2a233726c7bb76995cec749d59582e5664823b7245d4970354408f1d79a7a2"
|
||||
"checksum keccak-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f300c1f149cd9ca5214eed24f6e713a597517420fb8b15499824aa916259ec1"
|
||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
|
||||
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
|
||||
"checksum libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "1e5d97d6708edaa407429faa671b942dc0f2727222fb6b6539bf1db936e4b121"
|
||||
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
|
||||
"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
|
||||
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
|
||||
"checksum memorydb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "013b7e4c5e10c764936ebc6bd3662d8e3c92292d267bf6a42ef3f5cad9c793ee"
|
||||
"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
|
||||
"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
|
||||
"checksum odds 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)" = "4eae0151b9dacf24fcc170d9995e511669a082856a91f958a2fe380bfab3fb22"
|
||||
"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
|
||||
"checksum parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "149d8f5b97f3c1133e3cfcd8886449959e856b557ff281e292b733d7c69e005e"
|
||||
"checksum parking_lot_core 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "9f35048d735bb93dd115a0030498785971aab3234d311fbe273d020084d26bd8"
|
||||
"checksum patricia-trie 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f1e2f638d79aba5c4a71a4f373df6e3cd702250a53b7f0ed4da1e2a7be9737ae"
|
||||
"checksum plain_hasher 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83ae80873992f511142c07d0ec6c44de5636628fdb7e204abd655932ea79d995"
|
||||
"checksum proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ba8d4f9257b85eb6cdf13f055cea3190520aab1409ca2ab43493ea4820c25f0"
|
||||
"checksum proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5cb6f960ad471404618e9817c0e5d10b1ae74cfdf01fab89ea0641fe7fb2892"
|
||||
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||
"checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1"
|
||||
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
|
||||
"checksum rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b614fe08b6665cb9a231d07ac1364b0ef3cb3698f1239ee0c4c3a88a524f54c8"
|
||||
"checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53"
|
||||
"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
|
||||
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
|
||||
"checksum regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "744554e01ccbd98fff8c457c3b092cd67af62a555a43bfe97ae8a0451f7799fa"
|
||||
"checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e"
|
||||
"checksum ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6f7d28b30a72c01b458428e0ae988d4149c20d902346902be881e3edc4bb325c"
|
||||
"checksum rlp 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "babe6fce20c0ca9b1582998734c4569082d0ad08e43772a1c6c40aef4f106ef9"
|
||||
"checksum rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ceb8ce7a5e520de349e1fa172baeba4a9e8d5ef06c47471863530bc4972ee1e"
|
||||
"checksum rustc-hex 2.0.0 (git+https://github.com/rphmeier/rustc-hex.git)" = "<none>"
|
||||
"checksum rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9743a7670d88d5d52950408ecdb7c71d8986251ab604d4689dd2ca25c9bca69"
|
||||
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
|
||||
"checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "db99f3919e20faa51bb2996057f5031d8685019b5a06139b1ce761da671b8526"
|
||||
"checksum serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "f4ba7591cfe93755e89eeecdbcc668885624829b020050e6aec99c2a03bd3fd0"
|
||||
"checksum serde_derive_internals 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e03f1c9530c3fb0a0a5c9b826bdd9246a5921ae995d75f512ac917fc4dd55b5"
|
||||
"checksum smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44db0ecb22921ef790d17ae13a3f6d15784183ff5f2a01aa32098c7498d2b4b9"
|
||||
"checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b"
|
||||
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
|
||||
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
||||
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
||||
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
|
||||
"checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098"
|
||||
"checksum tiny-keccak 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e9241752647ca572f12c9b520a5d360d9099360c527770647e694001646a1d0"
|
||||
"checksum triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9291c7f0fae44858b5e087dd462afb382354120003778f1695b44aab98c7abd7"
|
||||
"checksum twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "475352206e7a290c5fccc27624a163e8d0d115f7bb60ca18a64fc9ce056d7435"
|
||||
"checksum uint 0.1.2 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)" = "<none>"
|
||||
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
|
||||
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
|
||||
"checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae"
|
||||
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
|
||||
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
||||
"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
|
||||
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
|
||||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
@@ -0,0 +1,30 @@
|
||||
[package]
|
||||
name = "substrate-test-runtime"
|
||||
version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
substrate-codec = { path = "../../codec", default-features = false }
|
||||
substrate-runtime-std = { path = "../../runtime-std", default-features = false }
|
||||
substrate-runtime-io = { path = "../../runtime-io", default-features = false }
|
||||
substrate-runtime-support = { path = "../../runtime-support", default-features = false }
|
||||
substrate-primitives = { path = "../../primitives", default-features = false }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
std = [
|
||||
"substrate-codec/std",
|
||||
"substrate-runtime-io/std",
|
||||
"substrate-runtime-std/std",
|
||||
"substrate-runtime-support/std",
|
||||
"substrate-primitives/std"
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
|
||||
[workspace]
|
||||
members = []
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
cargo +nightly build --target=wasm32-unknown-unknown --release
|
||||
for i in substrate_test_runtime
|
||||
do
|
||||
wasm-gc target/wasm32-unknown-unknown/release/$i.wasm target/wasm32-unknown-unknown/release/$i.compact.wasm
|
||||
done
|
||||
Binary file not shown.
+6
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
rustup update nightly
|
||||
rustup target add wasm32-unknown-unknown --toolchain nightly
|
||||
rustup update stable
|
||||
cargo install --git https://github.com/alexcrichton/wasm-gc
|
||||
@@ -0,0 +1 @@
|
||||
../src
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
Reference in New Issue
Block a user