mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
Implement NativeExecutor, which attempts a native execution and falls back on Wasm otherwise.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use primitives::contract::CallData;
|
||||
use state_machine::{Externalities, CodeExecutor};
|
||||
use error::{Error, ErrorKind, Result};
|
||||
use wasm_executor::WasmExecutor;
|
||||
use native_runtime as runtime;
|
||||
use runtime_support;
|
||||
|
||||
@@ -22,13 +23,13 @@ impl CodeExecutor for NativeExecutor {
|
||||
if code == &native_equivalent[..] {
|
||||
runtime_support::with_externalities(ext, || match method {
|
||||
// TODO: Panic handler that comes back with error.
|
||||
"execute_block" => Ok(runtime::execute_block(data.0)),
|
||||
"execute_transaction" => Ok(runtime::execute_transaction(data.0)),
|
||||
"execute_block" => Ok(runtime::execute_block(&data.0)),
|
||||
"execute_transaction" => Ok(runtime::execute_transaction(&data.0)),
|
||||
_ => Err(ErrorKind::MethodNotFound(method.to_owned()).into()),
|
||||
})
|
||||
} else {
|
||||
// call into wasm.
|
||||
unimplemented!()
|
||||
WasmExecutor.call(ext, code, method, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ impl fmt::Display for NoError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "") }
|
||||
}
|
||||
|
||||
environmental!(ext : Externalities + 'static);
|
||||
environmental!(ext : trait Externalities);
|
||||
|
||||
/// Get `key` from storage and return a `Vec`, empty if there's a problem.
|
||||
pub fn storage(key: &[u8]) -> Vec<u8> {
|
||||
@@ -93,7 +93,7 @@ pub fn ed25519_verify(sig: &[u8; 64], msg: &[u8], pubkey: &[u8; 32]) -> bool {
|
||||
|
||||
/// 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 + 'static), f: F) -> R {
|
||||
pub fn with_externalities<R, F: FnOnce() -> R>(ext: &mut Externalities, f: F) -> R {
|
||||
ext::using(ext, f)
|
||||
}
|
||||
|
||||
|
||||
@@ -40,14 +40,14 @@ use primitives::{Block, UncheckedTransaction};
|
||||
|
||||
/// Execute a block, with `input` being the canonical serialisation of the block. Returns the
|
||||
/// empty vector.
|
||||
pub fn execute_block(input: Vec<u8>) -> Vec<u8> {
|
||||
runtime::system::execute_block(Block::from_slice(&input).unwrap());
|
||||
pub fn execute_block(input: &[u8]) -> Vec<u8> {
|
||||
runtime::system::execute_block(Block::from_slice(input).unwrap());
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// Execute a given, serialised, transaction. Returns the empty vector.
|
||||
pub fn execute_transaction(input: Vec<u8>) -> Vec<u8> {
|
||||
runtime::system::execute_transaction(&UncheckedTransaction::from_slice(&input).unwrap());
|
||||
pub fn execute_transaction(input: &[u8]) -> Vec<u8> {
|
||||
runtime::system::execute_transaction(&UncheckedTransaction::from_slice(input).unwrap());
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ macro_rules! impl_stubs {
|
||||
$crate::Vec::from_raw_parts(input_data, input_len, input_len)
|
||||
};
|
||||
|
||||
let output = super::$name(input);
|
||||
let output = super::$name(&input[..]);
|
||||
&output[0] as *const u8 as u64 + ((output.len() as u64) << 32)
|
||||
}
|
||||
)*
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -10,26 +10,26 @@ use alloc::vec::Vec;
|
||||
extern crate runtime_support;
|
||||
use runtime_support::{set_storage, storage, print, blake2_256, twox_128, twox_256, ed25519_verify};
|
||||
|
||||
fn test_blake2_256(input: Vec<u8>) -> Vec<u8> {
|
||||
fn test_blake2_256(input: &[u8]) -> Vec<u8> {
|
||||
blake2_256(&input).to_vec()
|
||||
}
|
||||
|
||||
fn test_twox_256(input: Vec<u8>) -> Vec<u8> {
|
||||
fn test_twox_256(input: &[u8]) -> Vec<u8> {
|
||||
twox_256(&input).to_vec()
|
||||
}
|
||||
|
||||
fn test_twox_128(input: Vec<u8>) -> Vec<u8> {
|
||||
fn test_twox_128(input: &[u8]) -> Vec<u8> {
|
||||
twox_128(&input).to_vec()
|
||||
}
|
||||
|
||||
fn test_ed25519_verify(input: Vec<u8>) -> Vec<u8> {
|
||||
fn test_ed25519_verify(input: &[u8]) -> Vec<u8> {
|
||||
let sig = &input[0..64];
|
||||
let pubkey = &input[64..96];
|
||||
let msg = b"all ok!";
|
||||
[ed25519_verify(sig, &msg[..], pubkey) as u8].to_vec()
|
||||
}
|
||||
|
||||
fn test_data_in(input: Vec<u8>) -> Vec<u8> {
|
||||
fn test_data_in(input: &[u8]) -> Vec<u8> {
|
||||
print(b"set_storage" as &[u8]);
|
||||
set_storage(b"input", &input);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user