Skip to content

Commit

Permalink
Document EthereumRuntimeApi and README update (#81)
Browse files Browse the repository at this point in the history
* Document EthereumRuntimeApi

* Update readme

* Styling fixes
  • Loading branch information
tgmichel committed Jul 22, 2020
1 parent fcea972 commit e92bef4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ It consists of the following components:

Frontier is still work-in-progress. Below are some notes about the development.

### Runtime

A few notes on the EthereumRuntimeApi's runtime implementation requirements:

- For supporting author rpc call, the FindAuthor trait must be implemented in an
arbitrary struct. This implementation must call the authorities accessor in either
Aura or Babe and convert the authority id response to H160 using
pallet_evm::HashTruncateConvertAccountId::convert_account_id.

The struct implementing FindAuthor is passed as the FindAuthor associated type's
value for pallet_ethereum.

An Aura example for this is available in the template's runtime (EthereumFindAuthor).

- For supporting chain_id rpc call, a u64 ChainId constant must be defined.

- For supporting gas_price rpc call, FeeCalculator trait must be implemented in an
arbitrary struct. An example FixedGasPrice is available in the template's runtime.

### Vendor folder

The vendor folder contains dependencies that contains changes that has not yet
Expand Down
27 changes: 27 additions & 0 deletions rpc/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,19 @@ impl Default for TransactionStatus {
sp_api::decl_runtime_apis! {
/// API necessary for Ethereum-compatibility layer.
pub trait EthereumRuntimeApi {
/// Returns runtime defined pallet_evm::ChainId.
fn chain_id() -> u64;
/// Returns pallet_evm::Accounts by address.
fn account_basic(address: H160) -> pallet_evm::Account;
/// Returns FixedGasPrice::min_gas_price
fn gas_price() -> U256;
/// For a given account address, returns pallet_evm::AccountCodes.
fn account_code_at(address: H160) -> Vec<u8>;
/// Returns the converted FindAuthor::find_author authority id.
fn author() -> H160;
/// For a given account address and index, returns pallet_evm::AccountStorages.
fn storage_at(address: H160, index: U256) -> H256;
/// Returns a pallet_evm::execute_call response.
fn call(
from: H160,
to: H160,
Expand All @@ -68,17 +75,32 @@ sp_api::decl_runtime_apis! {
gas_price: U256,
nonce: Option<U256>,
) -> 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>>);
/// For a given block number, returns the number of transactions.
fn block_transaction_count_by_number(number: u32) -> Option<U256>;
/// For a given block hash, returns an ethereum::Block.
fn block_by_hash(hash: H256) -> Option<EthereumBlock>;
/// For a given block hash, returns an ethereum::Block and all its TransactionStatus.
fn block_by_hash_with_statuses(hash: H256) -> (Option<EthereumBlock>, Vec<Option<TransactionStatus>>);
/// For a given block hash, returns the number of transactions in a given block hash.
fn block_transaction_count_by_hash(hash: H256) -> Option<U256>;
/// For a given transaction hash, returns data necessary to build an Transaction rpc type response.
/// - EthereumTransaction: transaction as stored in pallet-ethereum.
/// - EthereumBlock: block as stored in pallet-ethereum .
/// - TransactionStatus: transaction execution metadata.
/// - EthereumReceipt: transaction receipt.
fn transaction_by_hash(hash: H256) -> Option<(
EthereumTransaction,
EthereumBlock,
TransactionStatus,
Vec<EthereumReceipt>
)>;
/// For a given block hash and transaction index, returns data necessary to build an Transaction rpc
/// type response.
/// - EthereumTransaction: transaction as stored in pallet-ethereum.
/// - EthereumBlock: block as stored in pallet-ethereum .
/// - TransactionStatus: transaction execution metadata.
fn transaction_by_block_hash_and_index(
hash: H256,
index: u32
Expand All @@ -87,6 +109,11 @@ sp_api::decl_runtime_apis! {
EthereumBlock,
TransactionStatus
)>;
/// For a given block number and transaction index, returns data necessary to build an Transaction rpc
/// type response.
/// - EthereumTransaction: transaction as stored in pallet-ethereum.
/// - EthereumBlock: block as stored in pallet-ethereum .
/// - TransactionStatus: transaction execution metadata.
fn transaction_by_block_number_and_index(
number: u32,
index: u32
Expand Down

0 comments on commit e92bef4

Please sign in to comment.