mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
define Id type in polkadot-parachain and depend on that in primitives. (#144)
* define Id type in polkadot-parachain and depend on that in primitives. * fix tests
This commit is contained in:
committed by
Gav Wood
parent
84d8629de6
commit
4ef53912e6
Generated
+3
@@ -2273,6 +2273,8 @@ dependencies = [
|
||||
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@@ -2283,6 +2285,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"polkadot-parachain 0.1.0",
|
||||
"pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
||||
@@ -305,8 +305,7 @@ pub fn validate_collation<P>(
|
||||
parent_head: chain_head,
|
||||
block_data: collation.block_data.0.clone(),
|
||||
ingress: incoming.iter()
|
||||
.flat_map(|&(para_id, ref messages)| {
|
||||
let source: u32 = para_id.into();
|
||||
.flat_map(|&(source, ref messages)| {
|
||||
messages.iter().map(move |msg| IncomingMessage {
|
||||
source,
|
||||
data: msg.0.clone(),
|
||||
@@ -391,7 +390,7 @@ mod tests {
|
||||
outgoing: Vec::new(),
|
||||
};
|
||||
|
||||
assert!(ext.post_message(MessageRef { target: 1, data: &[] }).is_ok());
|
||||
assert!(ext.post_message(MessageRef { target: 5, data: &[] }).is_err());
|
||||
assert!(ext.post_message(MessageRef { target: 1.into(), data: &[] }).is_ok());
|
||||
assert!(ext.post_message(MessageRef { target: 5.into(), data: &[] }).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ parity-codec = { version = "3.0", default-features = false }
|
||||
parity-codec-derive = { version = "3.0", default-features = false }
|
||||
wasmi = { version = "0.4.3", optional = true }
|
||||
error-chain = { version = "0.12", optional = true }
|
||||
serde = { version = "1.0", default-features = false }
|
||||
serde_derive = { version = "1.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
tiny-keccak = "1.4"
|
||||
@@ -16,4 +18,4 @@ tiny-keccak = "1.4"
|
||||
[features]
|
||||
default = ["std"]
|
||||
wasm-api = []
|
||||
std = ["parity-codec/std", "wasmi", "error-chain"]
|
||||
std = ["parity-codec/std", "wasmi", "error-chain", "serde_derive", "serde/std"]
|
||||
|
||||
@@ -62,6 +62,13 @@ extern crate wasmi;
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
extern crate serde;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
|
||||
@@ -93,12 +100,32 @@ pub struct ValidationResult {
|
||||
pub head_data: Vec<u8>,
|
||||
}
|
||||
|
||||
/// Unique identifier of a parachain.
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
|
||||
pub struct Id(u32);
|
||||
|
||||
impl From<Id> for u32 {
|
||||
fn from(x: Id) -> Self { x.0 }
|
||||
}
|
||||
|
||||
impl From<u32> for Id {
|
||||
fn from(x: u32) -> Self { Id(x) }
|
||||
}
|
||||
|
||||
impl Id {
|
||||
/// Convert this Id into its inner representation.
|
||||
pub fn into_inner(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// An incoming message.
|
||||
#[derive(PartialEq, Eq, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Encode))]
|
||||
pub struct IncomingMessage {
|
||||
/// The source parachain.
|
||||
pub source: u32,
|
||||
pub source: Id,
|
||||
/// The data of the message.
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
@@ -106,8 +133,7 @@ pub struct IncomingMessage {
|
||||
/// A reference to a message.
|
||||
pub struct MessageRef<'a> {
|
||||
/// The target parachain.
|
||||
pub target: u32,
|
||||
pub target: Id,
|
||||
/// Underlying data of the message.
|
||||
pub data: &'a [u8],
|
||||
}
|
||||
|
||||
|
||||
@@ -59,5 +59,5 @@ pub fn post_message(message: MessageRef) {
|
||||
let data_ptr = message.data.as_ptr();
|
||||
let data_len = message.data.len();
|
||||
|
||||
unsafe { ll::ext_post_message(message.target, data_ptr, data_len as u32) }
|
||||
unsafe { ll::ext_post_message(message.target.into_inner(), data_ptr, data_len as u32) }
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ impl<'a, E: 'a + Externalities> ValidationExternals<'a, E> {
|
||||
Err(Trap::new(wasmi::TrapKind::MemoryAccessOutOfBounds))
|
||||
} else {
|
||||
let res = self.externalities.post_message(MessageRef {
|
||||
target,
|
||||
target: target.into(),
|
||||
data: &mem[data_ptr..][..data_len],
|
||||
});
|
||||
|
||||
|
||||
@@ -185,9 +185,9 @@ fn processes_messages() {
|
||||
parent_head: parent_head.encode(),
|
||||
block_data: block_data.encode(),
|
||||
ingress: vec![
|
||||
IncomingMessage { source: 1, data: (AddMessage { amount: 256 }).encode() },
|
||||
IncomingMessage { source: 2, data: bad_message_data },
|
||||
IncomingMessage { source: 3, data: (AddMessage { amount: 256 }).encode() },
|
||||
IncomingMessage { source: 1.into(), data: (AddMessage { amount: 256 }).encode() },
|
||||
IncomingMessage { source: 2.into(), data: bad_message_data },
|
||||
IncomingMessage { source: 3.into(), data: (AddMessage { amount: 256 }).encode() },
|
||||
],
|
||||
},
|
||||
&mut DummyExt,
|
||||
|
||||
Binary file not shown.
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", default-features = false }
|
||||
serde = { version = "1.0", optional = true }
|
||||
serde_derive = { version = "1.0", optional = true }
|
||||
parity-codec = { version = "3.0", default-features = false }
|
||||
parity-codec-derive = { version = "3.0", default-features = false }
|
||||
@@ -13,6 +13,7 @@ substrate-client = { git = "https://github.com/paritytech/substrate", default-fe
|
||||
sr-version = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
sr-std = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
sr-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
polkadot-parachain = { path = "../parachain", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
substrate-serializer = { git = "https://github.com/paritytech/substrate" }
|
||||
@@ -29,5 +30,6 @@ std = [
|
||||
"sr-version/std",
|
||||
"sr-primitives/std",
|
||||
"serde_derive",
|
||||
"serde/std",
|
||||
"serde",
|
||||
"polkadot-parachain/std",
|
||||
]
|
||||
|
||||
@@ -26,6 +26,7 @@ extern crate substrate_primitives as primitives;
|
||||
extern crate sr_primitives as runtime_primitives;
|
||||
extern crate sr_std as rstd;
|
||||
extern crate sr_version;
|
||||
extern crate polkadot_parachain;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate substrate_serializer;
|
||||
|
||||
@@ -25,29 +25,11 @@ use {AccountId};
|
||||
#[cfg(feature = "std")]
|
||||
use primitives::bytes;
|
||||
|
||||
pub use polkadot_parachain::Id;
|
||||
|
||||
/// Signature on candidate's block data by a collator.
|
||||
pub type CandidateSignature = ::runtime_primitives::Ed25519Signature;
|
||||
|
||||
/// Unique identifier of a parachain.
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
|
||||
pub struct Id(u32);
|
||||
|
||||
impl From<Id> for u32 {
|
||||
fn from(x: Id) -> Self { x.0 }
|
||||
}
|
||||
|
||||
impl From<u32> for Id {
|
||||
fn from(x: u32) -> Self { Id(x) }
|
||||
}
|
||||
|
||||
impl Id {
|
||||
/// Convert this Id into its inner representation.
|
||||
pub fn into_inner(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Identifier for a chain, either one of a number of parachains or the relay chain.
|
||||
#[derive(Copy, Clone, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
|
||||
Generated
+13
@@ -806,12 +806,25 @@ name = "pkg-config"
|
||||
version = "0.3.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "polkadot-parachain"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "polkadot-primitives"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"polkadot-parachain 0.1.0",
|
||||
"serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-primitives 0.1.0 (git+https://github.com/paritytech/substrate)",
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user