mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 09:31:12 +00:00
Fix up wasm runtime.
This commit is contained in:
@@ -136,8 +136,8 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
|
||||
} else { 0 }
|
||||
} else { 0 }
|
||||
},
|
||||
ext_deposit_log(_log_data: *const u8, _log_len: u32) => {
|
||||
// TODO
|
||||
ext_chain_id() -> u64 => {
|
||||
42u64
|
||||
}
|
||||
=> <'e, E: Externalities + 'e>
|
||||
);
|
||||
|
||||
@@ -68,6 +68,12 @@ pub fn set_storage(_key: &[u8], _value: &[u8]) {
|
||||
);
|
||||
}
|
||||
|
||||
/// The current relay chain identifier.
|
||||
pub fn chain_id() -> u64 {
|
||||
// TODO: fetch from Externalities.
|
||||
42u64
|
||||
}
|
||||
|
||||
/// Execute the given closure with global function available whose functionality routes into the
|
||||
/// externalities `ext`. Forwards the value that the closure returns.
|
||||
pub fn with_externalities<R, F: FnOnce() -> R>(ext: &mut Externalities<Error=NoError>, f: F) -> R {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use runtime_support::Vec;
|
||||
use keyedvec::KeyedVec;
|
||||
use storage::Storage;
|
||||
use primitives::{AccountID, SessionKey, BlockNumber};
|
||||
|
||||
@@ -6,7 +6,9 @@ extern crate runtime_support;
|
||||
|
||||
mod support;
|
||||
pub use support::{endiansensitive, streamreader, joiner, slicable, primitives, keyedvec, function,
|
||||
environment, storage, testing};
|
||||
environment, storage};
|
||||
#[cfg(test)]
|
||||
pub use support::testing;
|
||||
|
||||
#[allow(unused)]
|
||||
mod system;
|
||||
@@ -19,9 +21,12 @@ mod timestamp;
|
||||
|
||||
use runtime_support::Vec;
|
||||
use slicable::Slicable;
|
||||
use primitives::{ChainID, Block, Transaction};
|
||||
use primitives::{Block, Transaction};
|
||||
|
||||
// TODO: add keccak256 (or some better hashing scheme) & ECDSA-recover (or some better sig scheme)
|
||||
// TODO: add externals for:
|
||||
// - keccak256 (or some better hashing scheme)
|
||||
// - trie rooting
|
||||
// - ECDSA-recover (or some better sig scheme)
|
||||
|
||||
pub fn execute_block(input: Vec<u8>) -> Vec<u8> {
|
||||
system::execute_block(Block::from_slice(&input).unwrap())
|
||||
@@ -32,9 +37,3 @@ pub fn execute_transaction(input: Vec<u8>) -> Vec<u8> {
|
||||
}
|
||||
|
||||
impl_stubs!(execute_block, execute_transaction);
|
||||
|
||||
/// The current relay chain identifier.
|
||||
pub fn chain_id() -> ChainID {
|
||||
// TODO: retrieve from external
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use runtime_support::Vec;
|
||||
use slicable::Slicable;
|
||||
|
||||
pub trait Joiner {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use runtime_support::Vec;
|
||||
use primitives::AccountID;
|
||||
use slicable::Slicable;
|
||||
|
||||
|
||||
@@ -7,4 +7,6 @@ pub mod keyedvec;
|
||||
pub mod function;
|
||||
pub mod environment;
|
||||
pub mod storage;
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod testing;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use runtime_support::Vec;
|
||||
use streamreader::StreamReader;
|
||||
use joiner::Joiner;
|
||||
use slicable::{Slicable, NonTrivialSlicable};
|
||||
@@ -62,7 +63,7 @@ impl Slicable for Transaction {
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
vec![]
|
||||
Vec::new()
|
||||
.join(&self.signed)
|
||||
.join(&(self.function as u8))
|
||||
.join(&self.nonce)
|
||||
@@ -84,7 +85,7 @@ impl<T: NonTrivialSlicable> Slicable for Vec<T> {
|
||||
fn from_slice(value: &[u8]) -> Option<Self> {
|
||||
let len = Self::size_of(&value[0..4])?;
|
||||
let mut off = 4;
|
||||
let mut r = vec![];
|
||||
let mut r = Vec::new();
|
||||
while off < len {
|
||||
let element_len = T::size_of(&value[off..])?;
|
||||
r.push(T::from_slice(&value[off..off + element_len])?);
|
||||
@@ -100,7 +101,7 @@ impl<T: NonTrivialSlicable> Slicable for Vec<T> {
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
let vecs = self.iter().map(Slicable::to_vec).collect::<Vec<_>>();
|
||||
let len = vecs.iter().fold(0, |mut a, v| {a += v.len(); a});
|
||||
let mut r = vec![].join(&(len as u32));
|
||||
let mut r = Vec::new().join(&(len as u32));
|
||||
vecs.iter().for_each(|v| r.extend_from_slice(v));
|
||||
r
|
||||
}
|
||||
@@ -127,7 +128,7 @@ impl Slicable for Header {
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
vec![]
|
||||
Vec::new()
|
||||
.join(&self.parent_hash)
|
||||
.join(&self.number)
|
||||
.join(&self.state_root)
|
||||
@@ -156,7 +157,7 @@ impl Slicable for Block {
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
vec![]
|
||||
Vec::new()
|
||||
.join(&self.header)
|
||||
.join(&self.transactions)
|
||||
}
|
||||
@@ -181,7 +182,7 @@ mod tests {
|
||||
let tx = Transaction {
|
||||
signed: one.clone(),
|
||||
function: Function::StakingTransferStake,
|
||||
input_data: vec![].join(&two).join(&69u64),
|
||||
input_data: Vec::new().join(&two).join(&69u64),
|
||||
nonce: 69,
|
||||
};
|
||||
let serialised = tx.to_vec();
|
||||
@@ -202,7 +203,7 @@ mod tests {
|
||||
let tx = Transaction {
|
||||
signed: one.clone(),
|
||||
function: Function::StakingTransferStake,
|
||||
input_data: vec![].join(&two).join(&69u64),
|
||||
input_data: Vec::new().join(&two).join(&69u64),
|
||||
nonce: 69,
|
||||
};
|
||||
let data = [
|
||||
@@ -271,13 +272,13 @@ mod tests {
|
||||
let tx1 = Transaction {
|
||||
signed: one.clone(),
|
||||
function: Function::StakingTransferStake,
|
||||
input_data: vec![].join(&two).join(&69u64),
|
||||
input_data: Vec::new().join(&two).join(&69u64),
|
||||
nonce: 69,
|
||||
};
|
||||
let tx2 = Transaction {
|
||||
signed: two.clone(),
|
||||
function: Function::StakingStake,
|
||||
input_data: vec![],
|
||||
input_data: Vec::new(),
|
||||
nonce: 42,
|
||||
};
|
||||
let h = Header {
|
||||
@@ -327,13 +328,13 @@ mod tests {
|
||||
let tx1 = Transaction {
|
||||
signed: one.clone(),
|
||||
function: Function::StakingTransferStake,
|
||||
input_data: vec![].join(&two).join(&69u64),
|
||||
input_data: Vec::new().join(&two).join(&69u64),
|
||||
nonce: 69,
|
||||
};
|
||||
let tx2 = Transaction {
|
||||
signed: two.clone(),
|
||||
function: Function::StakingStake,
|
||||
input_data: vec![],
|
||||
input_data: Vec::new(),
|
||||
nonce: 42,
|
||||
};
|
||||
let h = Header {
|
||||
|
||||
@@ -59,7 +59,7 @@ impl Slicable for Vec<u8> {
|
||||
unimplemented!();
|
||||
}
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
let mut r: Vec<u8> = vec![].join(&(self.len() as u32));
|
||||
let mut r: Vec<u8> = Vec::new().join(&(self.len() as u32));
|
||||
r.extend_from_slice(&self);
|
||||
r
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ pub use alloc::vec::Vec;
|
||||
pub use alloc::boxed::Box;
|
||||
pub use alloc::rc::Rc;
|
||||
pub use core::mem::{transmute, size_of, uninitialized, swap};
|
||||
pub use core::slice;
|
||||
pub use core::cell::{RefCell, Ref, RefMut};
|
||||
|
||||
extern crate pwasm_libc;
|
||||
@@ -27,7 +28,7 @@ extern "C" {
|
||||
fn ext_set_storage(key_data: *const u8, key_len: u32, value_data: *const u8, value_len: u32);
|
||||
fn ext_get_allocated_storage(key_data: *const u8, key_len: u32, written_out: *mut u32) -> *mut u8;
|
||||
fn ext_get_storage_into(key_data: *const u8, key_len: u32, value_data: *mut u8, value_len: u32) -> u32;
|
||||
fn ext_deposit_log(log_data: *const u8, log_len: u32);
|
||||
fn ext_chain_id() -> u64;
|
||||
}
|
||||
|
||||
pub fn storage(key: &[u8]) -> Vec<u8> {
|
||||
@@ -64,11 +65,16 @@ pub fn set_storage(key: &[u8], value: &[u8]) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deposit_log(log: &[u8]) {
|
||||
pub fn read_storage(key: &[u8], value_out: &mut [u8]) -> usize {
|
||||
unsafe {
|
||||
ext_deposit_log(
|
||||
&log[0] as *const u8, log.len() as u32,
|
||||
)
|
||||
ext_get_storage_into(&key[0], key.len() as u32, &mut value_out[0], value_out.len() as u32) as usize
|
||||
}
|
||||
}
|
||||
|
||||
/// The current relay chain identifier.
|
||||
pub fn chain_id() -> u64 {
|
||||
unsafe {
|
||||
ext_chain_id()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user