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
@@ -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],
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user