Skip to content

Commit

Permalink
Allows eth call to be used to create contract (paritytech#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
crystalin authored Jul 23, 2020
1 parent a889e92 commit bcb7745
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use rlp;
use sha3::{Digest, Keccak256};

pub use frontier_rpc_primitives::TransactionStatus;
pub use ethereum::{Transaction, Log, Block, Receipt};
pub use ethereum::{Transaction, Log, Block, Receipt, TransactionAction};

#[cfg(all(feature = "std", test))]
mod tests;
Expand Down
4 changes: 2 additions & 2 deletions rpc/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use sp_core::{H160, H256, U256};
use ethereum::{
Log, Block as EthereumBlock, Transaction as EthereumTransaction,
Receipt as EthereumReceipt
Receipt as EthereumReceipt, TransactionAction
};
use ethereum_types::Bloom;
use codec::{Encode, Decode};
Expand Down Expand Up @@ -68,12 +68,12 @@ sp_api::decl_runtime_apis! {
/// Returns a pallet_evm::execute_call response.
fn call(
from: H160,
to: H160,
data: Vec<u8>,
value: U256,
gas_limit: U256,
gas_price: U256,
nonce: Option<U256>,
action: TransactionAction
) -> Option<(Vec<u8>, U256)>;
/// For a given block number, returns an ethereum::Block and all its TransactionStatus.
fn block_by_number(number: u32) -> (Option<EthereumBlock>, Vec<Option<TransactionStatus>>);
Expand Down
9 changes: 6 additions & 3 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::{marker::PhantomData, sync::Arc};
use std::collections::BTreeMap;
use ethereum::{Block as EthereumBlock, Transaction as EthereumTransaction};
use ethereum::{Block as EthereumBlock, Transaction as EthereumTransaction, TransactionAction};
use ethereum_types::{H160, H256, H64, U256, U64};
use jsonrpc_core::{BoxFuture, Result, ErrorCode, Error, futures::future::{self, Future}};
use futures::future::TryFutureExt;
Expand Down Expand Up @@ -470,12 +470,12 @@ impl<B, C, SC, P, CT, BE> EthApiT for EthApi<B, C, SC, P, CT, BE> where
.call(
&BlockId::Hash(header.hash()),
from,
to,
data,
value,
gas_limit,
gas_price,
nonce,
ethereum::TransactionAction::Call(to)
)
.map_err(|_| internal_err("executing call failed"))?
.ok_or(internal_err("inner executing call failed"))?;
Expand All @@ -501,12 +501,15 @@ impl<B, C, SC, P, CT, BE> EthApiT for EthApi<B, C, SC, P, CT, BE> where
.call(
&BlockId::Hash(header.hash()),
from,
to,
data,
value,
gas_limit,
gas_price,
nonce,
match request.to {
Some(to) => ethereum::TransactionAction::Call(to),
_ => ethereum::TransactionAction::Create,
}
)
.map_err(|_| internal_err("executing call failed"))?
.ok_or(internal_err("inner executing call failed"))?;
Expand Down
35 changes: 24 additions & 11 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,23 +496,36 @@ impl_runtime_apis! {

fn call(
from: H160,
to: H160,
data: Vec<u8>,
value: U256,
gas_limit: U256,
gas_price: U256,
nonce: Option<U256>,
action: ethereum::TransactionAction,
) -> Option<(Vec<u8>, U256)> {
evm::Module::<Runtime>::execute_call(
from,
to,
data,
value,
gas_limit.low_u32(),
gas_price,
nonce,
false,
).ok().map(|(_, ret, gas)| (ret, gas))
match action {
ethereum::TransactionAction::Call(to) =>
evm::Module::<Runtime>::execute_call(
from,
to,
data,
value,
gas_limit.low_u32(),
gas_price,
nonce,
false,
).ok().map(|(_, ret, gas)| (ret, gas)),
ethereum::TransactionAction::Create =>
evm::Module::<Runtime>::execute_create(
from,
data,
value,
gas_limit.low_u32(),
gas_price,
nonce,
false,
).ok().map(|(_, _, gas)| (vec![], gas)),
}
}

fn block_by_number(number: u32) -> (
Expand Down

0 comments on commit bcb7745

Please sign in to comment.