Merge branch 'master' into types-binary

Conflicts:
	ethcore/src/error.rs
This commit is contained in:
Nikolay Volf
2016-05-14 23:12:18 +03:00
24 changed files with 206 additions and 92 deletions

View File

@@ -398,7 +398,7 @@ impl<V> Client<V> where V: Verifier {
}
impl<V> BlockChainClient for Client<V> where V: Verifier {
fn call(&self, t: &SignedTransaction) -> Result<Executed, Error> {
fn call(&self, t: &SignedTransaction) -> Result<Executed, ExecutionError> {
let header = self.block_header(BlockId::Latest).unwrap();
let view = HeaderView::new(&header);
let last_hashes = self.build_last_hashes(view.hash());
@@ -413,7 +413,10 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
};
// that's just a copy of the state.
let mut state = self.state();
let sender = try!(t.sender());
let sender = try!(t.sender().map_err(|e| {
let message = format!("Transaction malformed: {:?}", e);
ExecutionError::TransactionMalformed(message)
}));
let balance = state.balance(&sender);
// give the sender max balance
state.sub_balance(&sender, &balance);

View File

@@ -41,7 +41,7 @@ use header::{BlockNumber, Header};
use transaction::{LocalizedTransaction, SignedTransaction};
use log_entry::LocalizedLogEntry;
use filter::Filter;
use error::{ImportResult, Error};
use error::{ImportResult, ExecutionError};
use receipt::LocalizedReceipt;
use engine::{Engine};
use trace::LocalizedTrace;
@@ -132,7 +132,7 @@ pub trait BlockChainClient : Sync + Send {
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock>;
/// Makes a non-persistent transaction call.
fn call(&self, t: &SignedTransaction) -> Result<Executed, Error>;
fn call(&self, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
/// Attempt to seal the block internally. See `Engine`.
fn generate_seal(&self, block: &ExecutedBlock, accounts: Option<&AccountProvider>) -> Option<Vec<Bytes>> { self.engine().generate_seal(block, accounts) }

View File

@@ -31,7 +31,7 @@ use error::{ImportResult};
use block_queue::BlockQueueInfo;
use block::{SealedBlock, ClosedBlock, LockedBlock};
use executive::Executed;
use error::Error;
use error::{ExecutionError};
use engine::Engine;
use trace::LocalizedTrace;
@@ -221,7 +221,7 @@ impl TestBlockChainClient {
}
impl BlockChainClient for TestBlockChainClient {
fn call(&self, _t: &SignedTransaction) -> Result<Executed, Error> {
fn call(&self, _t: &SignedTransaction) -> Result<Executed, ExecutionError> {
Ok(self.execution_result.read().unwrap().clone().unwrap())
}

View File

@@ -82,7 +82,7 @@ impl<'a> Executive<'a> {
}
/// This function should be used to execute transaction.
pub fn transact(&'a mut self, t: &SignedTransaction, options: TransactOptions) -> Result<Executed, Error> {
pub fn transact(&'a mut self, t: &SignedTransaction, options: TransactOptions) -> Result<Executed, ExecutionError> {
let check = options.check_nonce;
match options.tracing {
true => self.transact_with_tracer(t, check, ExecutiveTracer::default()),
@@ -91,8 +91,11 @@ impl<'a> Executive<'a> {
}
/// Execute transaction/call with tracing enabled
pub fn transact_with_tracer<T>(&'a mut self, t: &SignedTransaction, check_nonce: bool, mut tracer: T) -> Result<Executed, Error> where T: Tracer {
let sender = try!(t.sender());
pub fn transact_with_tracer<T>(&'a mut self, t: &SignedTransaction, check_nonce: bool, mut tracer: T) -> Result<Executed, ExecutionError> where T: Tracer {
let sender = try!(t.sender().map_err(|e| {
let message = format!("Transaction malformed: {:?}", e);
ExecutionError::TransactionMalformed(message)
}));
let nonce = self.state.nonce(&sender);
let schedule = self.engine.schedule(self.info);
@@ -946,8 +949,8 @@ mod tests {
};
match res {
Err(Error::Util(UtilError::Crypto(CryptoError::InvalidSignature))) => (),
_ => assert!(false, "Expected invalid signature error.")
Err(ExecutionError::TransactionMalformed(_)) => (),
_ => assert!(false, "Expected an invalid transaction error.")
}
}
@@ -978,7 +981,7 @@ mod tests {
};
match res {
Err(Error::Execution(ExecutionError::InvalidNonce { expected, got }))
Err(ExecutionError::InvalidNonce { expected, got })
if expected == U256::zero() && got == U256::one() => (),
_ => assert!(false, "Expected invalid nonce error.")
}
@@ -1012,7 +1015,7 @@ mod tests {
};
match res {
Err(Error::Execution(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, gas }))
Err(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, gas })
if gas_limit == U256::from(100_000) && gas_used == U256::from(20_000) && gas == U256::from(80_001) => (),
_ => assert!(false, "Expected block gas limit error.")
}
@@ -1046,7 +1049,7 @@ mod tests {
};
match res {
Err(Error::Execution(ExecutionError::NotEnoughCash { required , got }))
Err(ExecutionError::NotEnoughCash { required , got })
if required == U512::from(100_018) && got == U512::from(100_017) => (),
_ => assert!(false, "Expected not enough cash error. {:?}", res)
}

View File

@@ -99,7 +99,9 @@ pub enum ExecutionError {
got: U512
},
/// Returned when internal evm error occurs.
Internal
Internal,
/// Returned when generic transaction occurs
TransactionMalformed(String),
}