State Machine: Abstract function execution (#19)

* initial primitives

* add block primitives

* state machine: backend

* in-memory backend

* tests for overlayed storage

* blanked impl for state machine error

* abstract call execution

* squash warnings temporarily

* fix contracts crate

* address grumbles

* remove redundant state-machine dependency
This commit is contained in:
Robert Habermeier
2017-11-13 16:39:58 +01:00
committed by GitHub
parent 2fa0239dab
commit 3dfafb5ec3
10 changed files with 824 additions and 18 deletions
+2 -2
View File
@@ -15,7 +15,7 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use primitives::Address;
use state_machine::Externalities;
use state_machine::StaticExternalities;
use error::Result;
use executor::RustExecutor;
@@ -32,7 +32,7 @@ impl Contract {
/// Given Message and Authentication Data verifies it and returns:
/// 1. None in case it doesn't match (i.e. signature is invalid)
/// 2. A address who signed that Message.
pub fn check_auth<E: Externalities<RustExecutor>>(&self, _ext: &E, _data: DataAndAuth) -> Result<Option<Address>> {
pub fn check_auth<E: StaticExternalities<RustExecutor>>(&self, _ext: &E, _data: DataAndAuth) -> Result<Option<Address>> {
unimplemented!()
}
}
+4 -4
View File
@@ -16,7 +16,7 @@
use primitives::Address;
use primitives::uint::U256;
use state_machine::Externalities;
use state_machine::{Externalities, StaticExternalities};
use error::Result;
use executor::RustExecutor;
@@ -38,12 +38,12 @@ pub struct Transfer {
pub struct Contract;
impl Contract {
/// Returns a balance of given address.
pub fn balance_of<E: Externalities<RustExecutor>>(&self, _ext: &E, _data: Address) -> Result<U256> {
pub fn balance_of<E: StaticExternalities<RustExecutor>>(&self, _ext: &E, _data: Address) -> Result<U256> {
unimplemented!()
}
/// Returns the next nonce to authorize the transfer from given address.
pub fn next_nonce<E: Externalities<RustExecutor>>(&self, _ext: &E, _data: Address) -> Result<U256> {
pub fn next_nonce<E: StaticExternalities<RustExecutor>>(&self, _ext: &E, _data: Address) -> Result<U256> {
unimplemented!()
}
@@ -52,7 +52,7 @@ impl Contract {
/// - signature
/// - replay protection
/// - enough balance
pub fn transfer_preconditions<E: Externalities<RustExecutor>>(&self, _db: &E, _data: Transfer) -> Result<bool> {
pub fn transfer_preconditions<E: StaticExternalities<RustExecutor>>(&self, _db: &E, _data: Transfer) -> Result<bool> {
unimplemented!()
}
-2
View File
@@ -46,5 +46,3 @@ error_chain! {
}
}
}
impl state_machine::Error for Error {}
+22 -2
View File
@@ -18,7 +18,7 @@
use primitives::contract::{CallData, OutData};
use serializer::{from_slice as de, to_vec as ser};
use state_machine::{Externalities, Executor};
use state_machine::{StaticExternalities, Externalities, Executor};
use error::{Error, ErrorKind, Result};
use auth;
@@ -45,7 +45,7 @@ impl RustExecutor {
impl Executor for RustExecutor {
type Error = Error;
fn static_call<E: Externalities<Self>>(
fn call_static<E: StaticExternalities<Self>>(
&self,
ext: &E,
code: &[u8],
@@ -95,11 +95,31 @@ impl Executor for RustExecutor {
#[cfg(test)]
mod tests {
use super::*;
use primitives::Address;
use primitives::hash::H256;
#[derive(Debug, Default)]
struct TestExternalities;
impl Externalities<RustExecutor> for TestExternalities {
fn set_storage(&mut self, _key: H256, _value: Vec<u8>) {
unimplemented!()
}
fn call(&mut self, _address: &Address, _method: &str, _data: &CallData) -> Result<OutData> {
unimplemented!()
}
}
impl StaticExternalities<RustExecutor> for TestExternalities {
type Error = Error;
fn storage(&self, _key: &H256) -> Result<&[u8]> {
unimplemented!()
}
fn call_static(&self, _address: &Address, _method: &str, _data: &CallData) -> Result<OutData> {
unimplemented!()
}
}
#[test]
+2 -2
View File
@@ -15,7 +15,7 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use primitives::Address;
use state_machine::Externalities;
use state_machine::StaticExternalities;
use error::Result;
use executor::RustExecutor;
@@ -25,7 +25,7 @@ use executor::RustExecutor;
pub struct Contract;
impl Contract {
/// Returns current validator set.
pub fn validator_set<E: Externalities<RustExecutor>>(&self, _db: &E, _data: ()) -> Result<Vec<Address>> {
pub fn validator_set<E: StaticExternalities<RustExecutor>>(&self, _db: &E, _data: ()) -> Result<Vec<Address>> {
unimplemented!()
}
}