mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
Refactored Slicable (#324)
* Refactored Slicable * Docs * Wasm build * Wasm build * Renamed traits * Review nits * Renamed Slicable as well
This commit is contained in:
committed by
Gav Wood
parent
e1c90b573b
commit
1e1ddf61f2
@@ -61,7 +61,7 @@ extern crate error_chain;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
use codec::Slicable;
|
||||
use codec::{Encode, Decode, Input, Output};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub mod wasm;
|
||||
@@ -77,20 +77,18 @@ pub struct ValidationParams {
|
||||
pub parent_head: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Slicable for ValidationParams {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
self.block_data.using_encoded(|s| v.extend(s));
|
||||
self.parent_head.using_encoded(|s| v.extend(s));
|
||||
|
||||
v
|
||||
impl Encode for ValidationParams {
|
||||
fn encode_to<T: Output>(&self, dest: &mut T) {
|
||||
dest.push(&self.block_data);
|
||||
dest.push(&self.parent_head);
|
||||
}
|
||||
}
|
||||
|
||||
fn decode<I: codec::Input>(input: &mut I) -> Option<Self> {
|
||||
impl Decode for ValidationParams {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
Some(ValidationParams {
|
||||
block_data: Slicable::decode(input)?,
|
||||
parent_head: Slicable::decode(input)?,
|
||||
block_data: Decode::decode(input)?,
|
||||
parent_head: Decode::decode(input)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -104,14 +102,16 @@ pub struct ValidationResult {
|
||||
pub head_data: Vec<u8>
|
||||
}
|
||||
|
||||
impl Slicable for ValidationResult {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
self.head_data.encode()
|
||||
impl Encode for ValidationResult {
|
||||
fn encode_to<T: Output>(&self, dest: &mut T) {
|
||||
dest.push(&self.head_data);
|
||||
}
|
||||
}
|
||||
|
||||
fn decode<I: codec::Input>(input: &mut I) -> Option<Self> {
|
||||
impl Decode for ValidationResult {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
Some(ValidationResult {
|
||||
head_data: Slicable::decode(input)?,
|
||||
head_data: Decode::decode(input)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
//! Assuming the parameters are correct, this module provides a wrapper around
|
||||
//! a WASM VM for re-execution of a parachain candidate.
|
||||
|
||||
use codec::Slicable;
|
||||
use codec::{Decode, Encode};
|
||||
|
||||
use wasmi::{self, Module, ModuleInstance, MemoryInstance, MemoryDescriptor, MemoryRef, ModuleImportResolver};
|
||||
use wasmi::{memory_units, RuntimeValue};
|
||||
|
||||
@@ -33,7 +33,7 @@ extern crate wee_alloc;
|
||||
extern crate tiny_keccak;
|
||||
extern crate pwasm_libc;
|
||||
|
||||
use parachain::codec::{Slicable, Input};
|
||||
use parachain::codec::{Decode, Encode, Input, Output};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
mod wasm;
|
||||
@@ -41,9 +41,6 @@ mod wasm;
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub use wasm::*;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
|
||||
// Define global allocator.
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[global_allocator]
|
||||
@@ -60,22 +57,20 @@ struct HeadData {
|
||||
post_state: [u8; 32],
|
||||
}
|
||||
|
||||
impl Slicable for HeadData {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
self.number.using_encoded(|s| v.extend(s));
|
||||
self.parent_hash.using_encoded(|s| v.extend(s));
|
||||
self.post_state.using_encoded(|s| v.extend(s));
|
||||
|
||||
v
|
||||
impl Encode for HeadData {
|
||||
fn encode_to<T: Output>(&self, dest: &mut T) {
|
||||
dest.push(&self.number);
|
||||
dest.push(&self.parent_hash);
|
||||
dest.push(&self.post_state);
|
||||
}
|
||||
}
|
||||
|
||||
impl Decode for HeadData {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
Some(HeadData {
|
||||
number: Slicable::decode(input)?,
|
||||
parent_hash: Slicable::decode(input)?,
|
||||
post_state: Slicable::decode(input)?,
|
||||
number: Decode::decode(input)?,
|
||||
parent_hash: Decode::decode(input)?,
|
||||
post_state: Decode::decode(input)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -89,20 +84,18 @@ struct BlockData {
|
||||
add: u64,
|
||||
}
|
||||
|
||||
impl Slicable for BlockData {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
self.state.using_encoded(|s| v.extend(s));
|
||||
self.add.using_encoded(|s| v.extend(s));
|
||||
|
||||
v
|
||||
impl Encode for BlockData {
|
||||
fn encode_to<T: Output>(&self, dest: &mut T) {
|
||||
dest.push(&self.state);
|
||||
dest.push(&self.add);
|
||||
}
|
||||
}
|
||||
|
||||
impl Decode for BlockData {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
Some(BlockData {
|
||||
state: Slicable::decode(input)?,
|
||||
add: Slicable::decode(input)?,
|
||||
state: Decode::decode(input)?,
|
||||
add: Decode::decode(input)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use core::{intrinsics, panic, alloc};
|
||||
use parachain::{self, ValidationResult};
|
||||
use parachain::codec::Slicable;
|
||||
use parachain::codec::{Encode, Decode};
|
||||
use super::{HeadData, BlockData};
|
||||
|
||||
#[panic_implementation]
|
||||
|
||||
@@ -20,7 +20,7 @@ extern crate polkadot_parachain as parachain;
|
||||
extern crate tiny_keccak;
|
||||
|
||||
use parachain::ValidationParams;
|
||||
use parachain::codec::{Slicable, Input};
|
||||
use parachain::codec::{Decode, Encode, Input, Output};
|
||||
|
||||
// Head data for this parachain.
|
||||
#[derive(Default, Clone)]
|
||||
@@ -33,22 +33,20 @@ struct HeadData {
|
||||
post_state: [u8; 32],
|
||||
}
|
||||
|
||||
impl Slicable for HeadData {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
self.number.using_encoded(|s| v.extend(s));
|
||||
self.parent_hash.using_encoded(|s| v.extend(s));
|
||||
self.post_state.using_encoded(|s| v.extend(s));
|
||||
|
||||
v
|
||||
impl Encode for HeadData {
|
||||
fn encode_to<T: Output>(&self, dest: &mut T) {
|
||||
dest.push(&self.number);
|
||||
dest.push(&self.parent_hash);
|
||||
dest.push(&self.post_state);
|
||||
}
|
||||
}
|
||||
|
||||
impl Decode for HeadData {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
Some(HeadData {
|
||||
number: Slicable::decode(input)?,
|
||||
parent_hash: Slicable::decode(input)?,
|
||||
post_state: Slicable::decode(input)?,
|
||||
number: Decode::decode(input)?,
|
||||
parent_hash: Decode::decode(input)?,
|
||||
post_state: Decode::decode(input)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -62,20 +60,18 @@ struct BlockData {
|
||||
add: u64,
|
||||
}
|
||||
|
||||
impl Slicable for BlockData {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
self.state.using_encoded(|s| v.extend(s));
|
||||
self.add.using_encoded(|s| v.extend(s));
|
||||
|
||||
v
|
||||
impl Encode for BlockData {
|
||||
fn encode_to<T: Output>(&self, dest: &mut T) {
|
||||
dest.push(&self.state);
|
||||
dest.push(&self.add);
|
||||
}
|
||||
}
|
||||
|
||||
impl Decode for BlockData {
|
||||
fn decode<I: Input>(input: &mut I) -> Option<Self> {
|
||||
Some(BlockData {
|
||||
state: Slicable::decode(input)?,
|
||||
add: Slicable::decode(input)?,
|
||||
state: Decode::decode(input)?,
|
||||
add: Decode::decode(input)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user