Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/basic-authorship/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
log = "0.4"
codec = { package = "parity-codec", version = "3.2" }
codec = { package = "parity-codec", version = "3.5" }
runtime_primitives = { package = "sr-primitives", path = "../../core/sr-primitives" }
client = { package = "substrate-client", path = "../../core/client" }
aura_primitives = { package = "substrate-consensus-aura-primitives", path = "../../core/consensus/aura/primitives" }
Expand Down
2 changes: 1 addition & 1 deletion core/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trie = { package = "substrate-trie", path = "../trie", optional = true }
substrate-telemetry = { path = "../telemetry", optional = true }
hash-db = { version = "0.12.2", default-features = false }
kvdb = { git = "https://github.com/paritytech/parity-common", optional = true, rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
parity-codec = { version = "3.3", default-features = false, features = ["derive"] }
parity-codec = { version = "3.5", default-features = false, features = ["derive"] }
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
runtime-primitives = { package = "sr-primitives", path = "../sr-primitives", default-features = false }
runtime-version = { package = "sr-version", path = "../sr-version", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion core/client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ primitives = { package = "substrate-primitives", path = "../../primitives" }
runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" }
client = { package = "substrate-client", path = "../../client" }
state-machine = { package = "substrate-state-machine", path = "../../state-machine" }
parity-codec = { version = "3.3", features = ["derive"] }
parity-codec = { version = "3.5", features = ["derive"] }
executor = { package = "substrate-executor", path = "../../executor" }
state_db = { package = "substrate-state-db", path = "../../state-db" }
trie = { package = "substrate-trie", path = "../../trie" }
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/aura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "Aura consensus algorithm for substrate"
edition = "2018"

[dependencies]
parity-codec = "3.4"
parity-codec = "3.5"
primitives = { package = "substrate-primitives", path = "../../primitives" }
runtime_support = { package = "srml-support", path = "../../../srml/support" }
runtime_version = { package = "sr-version", path = "../../sr-version" }
Expand Down
3 changes: 1 addition & 2 deletions core/consensus/babe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ description = "BABE consensus algorithm for substrate"
edition = "2018"

[dependencies]
parity-codec = "3.4.0"
parity-codec-derive = "3.3.0"
parity-codec = { version = "3.5", features = ["derive"] }
babe_primitives = { package = "substrate-consensus-babe-primitives", path = "primitives" }
primitives = { package = "substrate-primitives", path = "../../primitives" }
runtime_support = { package = "srml-support", path = "../../../srml/support" }
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/babe/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ rstd = { package = "sr-std", path = "../../../sr-std", default-features = false
runtime_primitives = { package = "sr-primitives", path = "../../../sr-primitives", default-features = false }
substrate-primitives = { path = "../../../primitives", default-features = false }
slots = { package = "substrate-consensus-slots", path = "../../slots", optional = true }
parity-codec = { version = "3.5.1", default-features = false }
parity-codec = { version = "3.5", default-features = false }

[features]
default = ["std"]
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ runtime_version = { package = "sr-version", path = "../../sr-version" }
runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" }
tokio-executor = "0.1.6"
tokio-timer = "0.2"
parity-codec = { version = "3.3", features = ["derive"] }
parity-codec = { version = "3.5", features = ["derive"] }
parking_lot = "0.8.0"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/rhd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
[dependencies]
derive_more = "0.14.0"
futures = "0.1.17"
codec = { package = "parity-codec", version = "3.2", features = ["derive"] }
codec = { package = "parity-codec", version = "3.5", features = ["derive"] }
primitives = { package = "substrate-primitives", path = "../../primitives" }
consensus = { package = "substrate-consensus-common", path = "../common" }
client = { package = "substrate-client", path = "../../client" }
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/slots/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "Generic slots-based utilities for consensus"
edition = "2018"

[dependencies]
codec = { package = "parity-codec", version = "3.2" }
codec = { package = "parity-codec", version = "3.5" }
client = { package = "substrate-client", path = "../../client" }
primitives = { package = "substrate-primitives", path = "../../primitives" }
runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" }
Expand Down
2 changes: 1 addition & 1 deletion core/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
derive_more = "0.14.0"
parity-codec = "3.3"
parity-codec = "3.5"
runtime_io = { package = "sr-io", path = "../sr-io" }
primitives = { package = "substrate-primitives", path = "../primitives" }
trie = { package = "substrate-trie", path = "../trie" }
Expand Down
2 changes: 1 addition & 1 deletion core/finality-grandpa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ log = "0.4"
parking_lot = "0.8.0"
tokio = "0.1.7"
rand = "0.6"
parity-codec = { version = "3.3", features = ["derive"] }
parity-codec = { version = "3.5", features = ["derive"] }
runtime_primitives = { package = "sr-primitives", path = "../sr-primitives" }
consensus_common = { package = "substrate-consensus-common", path = "../consensus/common" }
substrate-primitives = { path = "../primitives" }
Expand Down
2 changes: 1 addition & 1 deletion core/finality-grandpa/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
client = { package = "substrate-client", path = "../../client", default-features = false }
substrate-primitives = { path = "../../primitives", default-features = false }
parity-codec = { version = "3.3", default-features = false, features = ["derive"] }
parity-codec = { version = "3.5", default-features = false, features = ["derive"] }
sr-primitives = { path = "../../sr-primitives", default-features = false }
rstd = { package = "sr-std", path = "../../sr-std", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion core/inherents/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
parking_lot = { version = "0.8.0", optional = true }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
parity-codec = { version = "3.3", default-features = false, features = ["derive"] }
parity-codec = { version = "3.5", default-features = false, features = ["derive"] }
runtime_primitives = { package = "sr-primitives", path = "../sr-primitives", default-features = false }

[features]
Expand Down
2 changes: 1 addition & 1 deletion core/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ primitives = { package = "substrate-primitives", path = "../../core/primitives"
consensus = { package = "substrate-consensus-common", path = "../../core/consensus/common" }
client = { package = "substrate-client", path = "../../core/client" }
runtime_primitives = { package = "sr-primitives", path = "../../core/sr-primitives" }
parity-codec = { version = "3.3", features = ["derive"] }
parity-codec = { version = "3.5", features = ["derive"] }
peerset = { package = "substrate-peerset", path = "../../core/peerset" }
serde = { version = "1.0.70", features = ["derive"] }
serde_json = "1.0.24"
Expand Down
2 changes: 1 addition & 1 deletion core/offchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ consensus = { package = "substrate-consensus-common", path = "../../core/consens
futures = "0.1.25"
log = "0.4"
offchain-primitives = { package = "substrate-offchain-primitives", path = "./primitives" }
parity-codec = { version = "3.3", features = ["derive"] }
parity-codec = { version = "3.5", features = ["derive"] }
parking_lot = "0.8.0"
primitives = { package = "substrate-primitives", path = "../../core/primitives" }
runtime_primitives = { package = "sr-primitives", path = "../../core/sr-primitives" }
Expand Down
4 changes: 2 additions & 2 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ edition = "2018"

[dependencies]
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
parity-codec = { version = "3.4.0", default-features = false, features = ["derive"] }
parity-codec = { version = "3.5", default-features = false, features = ["derive"] }
rustc-hex = { version = "2.0", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive"] }
twox-hash = { version = "1.2.0", optional = true }
byteorder = { version = "1.3.1", default-features = false }
primitive-types = { version = "0.2.3", default-features = false, features = ["codec"] }
primitive-types = { version = "0.2", default-features = false, features = ["codec"] }
impl-serde = { version = "0.1", optional = true }
wasmi = { version = "0.4.3", optional = true }
hash-db = { version = "0.12", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion core/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jsonrpc-pubsub = "12.0.0"
jsonrpc-derive = "12.0.0"
log = "0.4"
parking_lot = "0.8.0"
parity-codec = "3.3"
parity-codec = "3.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
client = { package = "substrate-client", path = "../client" }
Expand Down
2 changes: 1 addition & 1 deletion core/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ consensus_common = { package = "substrate-consensus-common", path = "../../core/
network = { package = "substrate-network", path = "../../core/network" }
client = { package = "substrate-client", path = "../../core/client" }
client_db = { package = "substrate-client-db", path = "../../core/client/db", features = ["kvdb-rocksdb"] }
parity-codec = "3.3"
parity-codec = "3.5"
substrate-executor = { path = "../../core/executor" }
transaction_pool = { package = "substrate-transaction-pool", path = "../../core/transaction-pool" }
rpc = { package = "substrate-rpc-servers", path = "../../core/rpc-servers" }
Expand Down
2 changes: 1 addition & 1 deletion core/sr-api-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sr-version = { path = "../sr-version" }
substrate-primitives = { path = "../primitives" }
criterion = "0.2"
consensus_common = { package = "substrate-consensus-common", path = "../consensus/common" }
codec = { package = "parity-codec", version = "3.5.1" }
codec = { package = "parity-codec", version = "3.5" }
trybuild = "1.0"

[[bench]]
Expand Down
2 changes: 1 addition & 1 deletion core/sr-io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ rustc_version = "0.2"
[dependencies]
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
codec = { package = "parity-codec", version = "3.5.1", default-features = false }
codec = { package = "parity-codec", version = "3.5", default-features = false }
hash-db = { version = "0.12", default-features = false }
libsecp256k1 = { version = "0.2.1", optional = true }
tiny-keccak = { version = "1.4.2", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion core/sr-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
num-traits = { version = "0.2", default-features = false }
integer-sqrt = { version = "0.1.2" }
serde = { version = "1.0", optional = true, features = ["derive"] }
codec = { package = "parity-codec", version = "3.5.1", default-features = false, features = ["derive"] }
codec = { package = "parity-codec", version = "3.5", default-features = false, features = ["derive"] }
substrate-primitives = { path = "../primitives", default-features = false }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
runtime_io = { package = "sr-io", path = "../sr-io", default-features = false }
Expand Down
8 changes: 8 additions & 0 deletions core/sr-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ pub type Justification = Vec<u8>;

use traits::{Verify, Lazy};

/// A module identifier. These are per module and should be stored in a registry somewhere.
#[derive(Clone, Copy, Eq, PartialEq, Encode, Decode)]
pub struct ModuleId(pub [u8; 8]);

impl traits::TypeId for ModuleId {
const TYPE_ID: [u8; 4] = *b"modl";
}

/// A String that is a `&'static str` on `no_std` and a `Cow<'static, str>` on `std`.
#[cfg(feature = "std")]
pub type RuntimeString = ::std::borrow::Cow<'static, str>;
Expand Down
104 changes: 104 additions & 0 deletions core/sr-primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,110 @@ pub trait OpaqueKeys: Clone {
fn ownership_proof_is_valid(&self, _proof: &[u8]) -> bool { true }
}

struct TrailingZeroInput<'a>(&'a [u8]);
impl<'a> codec::Input for TrailingZeroInput<'a> {
fn read(&mut self, into: &mut [u8]) -> usize {
let len = into.len().min(self.0.len());
into[..len].copy_from_slice(&self.0[..len]);
for i in &mut into[len..] {
*i = 0;
}
self.0 = &self.0[len..];
into.len()
}
}

/// This type can be converted into and possibly from an AccountId (which itself is generic).
pub trait AccountIdConversion<AccountId>: Sized {
/// Convert into an account ID. This is infallible.
fn into_account(&self) -> AccountId;

/// Try to convert an account ID into this type. Might not succeed.
fn try_from_account(a: &AccountId) -> Option<Self>;
}

/// Provide a simply 4 byte identifier for a type.
pub trait TypeId {
/// Simple 4 byte identifier.
const TYPE_ID: [u8; 4];
}

/// Format is b"para" ++ encode(parachain ID) ++ 00.... where 00... is indefinite trailing zeroes to fill AccountId.
Comment thread
gavofyork marked this conversation as resolved.
Outdated
impl<T: Encode + Decode + Default, Id: Encode + Decode + TypeId> AccountIdConversion<T> for Id {
fn into_account(&self) -> T {
(Id::TYPE_ID, self).using_encoded(|b|
T::decode(&mut TrailingZeroInput(b))
).unwrap_or_default()
}

fn try_from_account(x: &T) -> Option<Self> {
x.using_encoded(|d| {
if &d[0..4] != Id::TYPE_ID { return None }
let mut cursor = &d[4..];
let result = Decode::decode(&mut cursor)?;
if cursor.iter().all(|x| *x == 0) {
Some(result)
} else {
None
}
})
}
}

#[cfg(test)]
mod tests {
use super::AccountIdConversion;
use crate::codec::{Encode, Decode};

#[derive(Encode, Decode, Default, PartialEq, Debug)]
struct U32Value(u32);
impl super::TypeId for U32Value {
const TYPE_ID: [u8; 4] = [0x0d, 0xf0, 0xfe, 0xca];
}
// cafef00d

#[derive(Encode, Decode, Default, PartialEq, Debug)]
struct U16Value(u16);
impl super::TypeId for U16Value {
const TYPE_ID: [u8; 4] = [0xfe, 0xca, 0x0d, 0xf0];
}
// f00dcafe

type AccountId = u64;

#[test]
fn into_account_should_work() {
let r: AccountId = U32Value::into_account(&U32Value(0xdeadbeef));
assert_eq!(r, 0x_deadbeef_cafef00d);
}

#[test]
fn try_from_account_should_work() {
let r = U32Value::try_from_account(&0x_deadbeef_cafef00d_u64);
assert_eq!(r.unwrap(), U32Value(0xdeadbeef));
}

#[test]
fn into_account_with_fill_should_work() {
let r: AccountId = U16Value::into_account(&U16Value(0xc0da));
assert_eq!(r, 0x_0000_c0da_f00dcafe);
}

#[test]
fn try_from_account_with_fill_should_work() {
let r = U16Value::try_from_account(&0x0000_c0da_f00dcafe_u64);
assert_eq!(r.unwrap(), U16Value(0xc0da));
}

#[test]
fn bad_try_from_account_should_fail() {
let r = U16Value::try_from_account(&0x0000_c0de_baadcafe_u64);
assert!(r.is_none());
let r = U16Value::try_from_account(&0x0100_c0da_f00dcafe_u64);
assert!(r.is_none());
}
}

/// Calls a given macro a number of times with a set of fixed params and an incrementing numeral.
/// e.g.
/// ```nocompile
Expand Down
2 changes: 1 addition & 1 deletion core/sr-sandbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rustc_version = "0.2"
wasmi = { version = "0.4.3", optional = true }
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
codec = { package = "parity-codec", version = "3.2", default-features = false }
codec = { package = "parity-codec", version = "3.5", default-features = false }

[dev-dependencies]
wabt = "~0.7.4"
Expand Down
2 changes: 1 addition & 1 deletion core/sr-version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
impl-serde = { version = "0.1", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }
parity-codec = { version = "3.3", default-features = false, features = ["derive"] }
parity-codec = { version = "3.5", default-features = false, features = ["derive"] }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
runtime_primitives = { package = "sr-primitives", path = "../sr-primitives", default-features = false }

Expand Down
2 changes: 1 addition & 1 deletion core/state-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
parking_lot = "0.8.0"
log = "0.4"
primitives = { package = "substrate-primitives", path = "../../core/primitives" }
parity-codec = { version = "3.3", features = ["derive"] }
parity-codec = { version = "3.5", features = ["derive"] }

[dev-dependencies]
env_logger = "0.6"
2 changes: 1 addition & 1 deletion core/state-machine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trie-root = "0.12"
trie = { package = "substrate-trie", path = "../trie" }
primitives = { package = "substrate-primitives", path = "../primitives" }
panic-handler = { package = "substrate-panic-handler", path = "../panic-handler" }
parity-codec = "3.3"
parity-codec = "3.5"
num-traits = "0.2"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion core/test-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ executor = { package = "substrate-executor", path = "../executor" }
futures = { version = "0.1.27" }
hash-db = "0.12"
keyring = { package = "substrate-keyring", path = "../keyring" }
parity-codec = "3.5.1"
parity-codec = "3.5"
primitives = { package = "substrate-primitives", path = "../primitives" }
runtime_primitives = { package = "sr-primitives", path = "../sr-primitives" }
state_machine = { package = "substrate-state-machine", path = "../state-machine" }
2 changes: 1 addition & 1 deletion core/test-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
log = { version = "0.4", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }
parity-codec = { version = "3.3", default-features = false, features = ["derive"] }
parity-codec = { version = "3.5", default-features = false, features = ["derive"] }
keyring = { package = "substrate-keyring", path = "../keyring", optional = true }
substrate-client = { path = "../client", default-features = false }
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
Expand Down
Loading