RPC & Client (#21)

* Initial version of http server.

* Refactor the structure.

* add unassigned ports info.

* Rename servers to match conventions.

* Add client crate and some proper RPC implementations.

* Style & docs.
This commit is contained in:
Tomasz Drwięga
2017-11-15 19:29:14 +01:00
committed by Robert Habermeier
parent 0ceebe6625
commit db78e5fb4c
33 changed files with 1121 additions and 34 deletions
+5 -1
View File
@@ -16,7 +16,7 @@
//! State machine backends. These manage the code and storage of contracts.
use std::fmt;
use std::{error, fmt};
use primitives::Address;
use primitives::hash::H256;
@@ -60,6 +60,10 @@ impl fmt::Display for Void {
}
}
impl error::Error for Void {
fn description(&self) -> &str { "unreachable error" }
}
/// In-memory backend. Fully recomputes tries on each commit but useful for
/// tests.
#[derive(Default)]
+14 -5
View File
@@ -16,13 +16,13 @@
//! Conrete externalities implementation.
use std::fmt;
use std::{error, fmt};
use backend::Backend;
use primitives::Address;
use primitives::contract::{CallData, OutData};
use primitives::hash::H256;
use {Externalities, Executor, StaticExternalities, OverlayedChanges};
use {Externalities, CodeExecutor, StaticExternalities, OverlayedChanges};
/// Errors that can occur when interacting with the externalities.
#[derive(Debug, Copy, Clone)]
@@ -42,6 +42,15 @@ impl<B: fmt::Display, E: fmt::Display> fmt::Display for Error<B, E> {
}
}
impl<B: error::Error, E: error::Error> error::Error for Error<B, E> {
fn description(&self) -> &str {
match *self {
Error::Backend(..) => "backend error",
Error::Executor(..) => "executor error",
}
}
}
/// Wraps a read-only backend, call executor, and current overlayed changes.
pub struct Ext<'a, B: 'a, E: 'a> {
/// The overlayed changes to write to.
@@ -55,7 +64,7 @@ pub struct Ext<'a, B: 'a, E: 'a> {
}
impl<'a, B: 'a, E: 'a> StaticExternalities<E> for Ext<'a, B, E>
where B: Backend, E: Executor
where B: Backend, E: CodeExecutor
{
type Error = Error<B::Error, E::Error>;
@@ -89,7 +98,7 @@ impl<'a, B: 'a, E: 'a> StaticExternalities<E> for Ext<'a, B, E>
}
impl<'a, B: 'a, E: 'a> Externalities<E> for Ext<'a, B, E>
where B: Backend, E: Executor
where B: Backend, E: CodeExecutor
{
fn set_storage(&mut self, key: H256, value: Vec<u8>) {
self.overlay.set_storage(self.local, key, value);
@@ -130,7 +139,7 @@ struct StaticExt<'a, B: 'a, E: 'a> {
}
impl<'a, B: 'a, E: 'a> StaticExternalities<E> for StaticExt<'a, B, E>
where B: Backend, E: Executor
where B: Backend, E: CodeExecutor
{
type Error = Error<B::Error, E::Error>;
+4 -4
View File
@@ -162,7 +162,7 @@ pub trait Error: 'static + fmt::Debug + fmt::Display + Send {}
impl<E> Error for E where E: 'static + fmt::Debug + fmt::Display + Send {}
/// Externalities: pinned to specific active address.
pub trait Externalities<Executor>: StaticExternalities<Executor> {
pub trait Externalities<CodeExecutor>: StaticExternalities<CodeExecutor> {
/// Read storage of current contract being called.
fn storage(&self, key: &H256) -> Result<&[u8], Self::Error> {
StaticExternalities::storage(self, key)
@@ -181,7 +181,7 @@ pub trait Externalities<Executor>: StaticExternalities<Executor> {
}
/// Static externalities: used only for read-only requests.
pub trait StaticExternalities<Executor> {
pub trait StaticExternalities<CodeExecutor> {
/// Externalities error type.
type Error: Error;
@@ -193,7 +193,7 @@ pub trait StaticExternalities<Executor> {
}
/// Contract code executor.
pub trait Executor: Sized {
pub trait CodeExecutor: Sized {
/// Error type for contract execution.
type Error: Error;
@@ -220,7 +220,7 @@ pub trait Executor: Sized {
/// Execute a call using the given state backend, overlayed changes, and call executor.
///
/// On an error, no prospective changes are written to the overlay.
pub fn execute<B: backend::Backend, Exec: Executor>(
pub fn execute<B: backend::Backend, Exec: CodeExecutor>(
backend: &B,
overlay: &mut OverlayedChanges,
exec: &Exec,