Skip to content

Commit

Permalink
Properly return retval in TransactValue (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas authored Jan 28, 2024
1 parent 0d2ce88 commit 691b04b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! for the function.
//!
//! * Select an [Invoker]. The invoker defines all details of the execution
//! environment except the external backend. [standard::SimpleInvoker] is
//! environment except the external backend. [standard::Invoker] is
//! probably want you want if you are not extending EVM.
//! * For the standard invoker, select a [standard::Config], which represents
//! different Ethereum hard forks.
Expand Down
55 changes: 42 additions & 13 deletions src/standard/invoker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ pub enum SubstackInvoke {
Create { trap: CreateTrapData, address: H160 },
}

/// Return value of a transaction.
pub enum TransactValue {
Call {
/// The exit result. If we return a value, then it will be an
/// `ExitSucceed`.
succeed: ExitSucceed,
/// The return value, if any.
retval: Vec<u8>,
},
Create {
/// The exit result. If we return a value, then it will be an
/// `ExitSucceed`.
succeed: ExitSucceed,
/// The contract address created.
address: H160,
},
}

/// The invoke used in a top-layer transaction stack.
pub struct TransactInvoke {
pub create_address: Option<H160>,
Expand Down Expand Up @@ -165,7 +183,7 @@ where
type Interrupt = Tr::Rest;
type TransactArgs = TransactArgs;
type TransactInvoke = TransactInvoke;
type TransactValue = (ExitSucceed, Option<H160>);
type TransactValue = TransactValue;
type SubstackInvoke = SubstackInvoke;

fn new_transact(
Expand Down Expand Up @@ -335,21 +353,32 @@ where
let left_gas = substate.effective_gas();

let work = || -> Result<Self::TransactValue, ExitError> {
if result.is_ok() {
if let Some(address) = invoke.create_address {
let retbuf = retval;
match result {
Ok(result) => {
if let Some(address) = invoke.create_address {
let retbuf = retval;

routines::deploy_create_code(
self.config,
address,
retbuf,
&mut substate,
handler,
)?;
routines::deploy_create_code(
self.config,
address,
retbuf,
&mut substate,
handler,
)?;

Ok(TransactValue::Create {
succeed: result,
address,
})
} else {
Ok(TransactValue::Call {
succeed: result,
retval,
})
}
}
Err(result) => Err(result),
}

result.map(|s| (s, invoke.create_address))
};

let result = work();
Expand Down

0 comments on commit 691b04b

Please sign in to comment.