mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +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
@@ -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.
Reference in New Issue
Block a user