mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 16:37:57 +00:00
Initial (non-functional) code.
- Kill Externalities Error type requirement.
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
//! Rust executor possible errors.
|
||||
|
||||
use serializer;
|
||||
use state_machine;
|
||||
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
@@ -38,9 +37,9 @@ error_chain! {
|
||||
}
|
||||
|
||||
/// Externalities have failed.
|
||||
Externalities(e: Box<state_machine::Error>) {
|
||||
Externalities {
|
||||
description("externalities failure"),
|
||||
display("Externalities error: {}", e),
|
||||
display("Externalities error"),
|
||||
}
|
||||
|
||||
/// Invalid index.
|
||||
|
||||
@@ -34,6 +34,8 @@ extern crate serde;
|
||||
extern crate parity_wasm;
|
||||
extern crate byteorder;
|
||||
extern crate rustc_hex;
|
||||
extern crate native_runtime;
|
||||
extern crate runtime_support;
|
||||
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
@@ -44,10 +46,13 @@ extern crate assert_matches;
|
||||
#[macro_use]
|
||||
mod wasm_utils;
|
||||
mod wasm_executor;
|
||||
mod native_executor;
|
||||
|
||||
pub mod error;
|
||||
|
||||
/// Creates new RustExecutor for contracts.
|
||||
pub fn executor() -> wasm_executor::WasmExecutor {
|
||||
// TODO: check what the code to execute is and use NativeExecutor if the wasm is compiled with
|
||||
// matches.
|
||||
wasm_executor::WasmExecutor::default()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
use primitives::contract::CallData;
|
||||
use state_machine::{Externalities, CodeExecutor};
|
||||
use error::{Error, ErrorKind, Result};
|
||||
use native_runtime as runtime;
|
||||
use runtime_support;
|
||||
|
||||
struct NativeExecutor;
|
||||
|
||||
impl CodeExecutor for NativeExecutor {
|
||||
type Error = Error;
|
||||
|
||||
fn call<E: Externalities>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
code: &[u8],
|
||||
method: &str,
|
||||
data: &CallData,
|
||||
) -> Result<Vec<u8>> {
|
||||
// WARNING!!! This assumes that the runtime was built *before* the main project. Until we
|
||||
// get a proper build script, this must be strictly adhered to or things will go wrong.
|
||||
let native_equivalent = include_bytes!("../../wasm-runtime/target/wasm32-unknown-unknown/release/runtime_polkadot.compact.wasm");
|
||||
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)),
|
||||
_ => Err(ErrorKind::MethodNotFound(method.to_owned()).into()),
|
||||
})
|
||||
} else {
|
||||
// call into wasm.
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -241,15 +241,14 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
use rustc_hex::FromHex;
|
||||
use state_machine::ExternalitiesError;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct TestExternalities {
|
||||
storage: HashMap<Vec<u8>, Vec<u8>>,
|
||||
}
|
||||
impl Externalities for TestExternalities {
|
||||
type Error = Error;
|
||||
|
||||
fn storage(&self, key: &[u8]) -> Result<&[u8]> {
|
||||
fn storage(&self, key: &[u8]) -> ::std::result::Result<&[u8], ExternalitiesError> {
|
||||
Ok(self.storage.get(&key.to_vec()).map_or(&[] as &[u8], Vec::as_slice))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user