Skip to content

Commit

Permalink
[pallet-revive] Add Ethereum JSON-RPC server (#6147)
Browse files Browse the repository at this point in the history
Redo of #5953

---------

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
3 people authored Oct 28, 2024
1 parent 8590122 commit 58fd5ae
Show file tree
Hide file tree
Showing 39 changed files with 2,823 additions and 20 deletions.
170 changes: 163 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ members = [
"substrate/frame/revive/fixtures",
"substrate/frame/revive/mock-network",
"substrate/frame/revive/proc-macro",
"substrate/frame/revive/rpc",
"substrate/frame/revive/uapi",
"substrate/frame/root-offences",
"substrate/frame/root-testing",
Expand Down Expand Up @@ -965,6 +966,7 @@ pallet-recovery = { path = "substrate/frame/recovery", default-features = false
pallet-referenda = { path = "substrate/frame/referenda", default-features = false }
pallet-remark = { default-features = false, path = "substrate/frame/remark" }
pallet-revive = { path = "substrate/frame/revive", default-features = false }
pallet-revive-eth-rpc = { path = "substrate/frame/revive/rpc", default-features = false }
pallet-revive-fixtures = { path = "substrate/frame/revive/fixtures", default-features = false }
pallet-revive-mock-network = { default-features = false, path = "substrate/frame/revive/mock-network" }
pallet-revive-proc-macro = { path = "substrate/frame/revive/proc-macro", default-features = false }
Expand Down
13 changes: 11 additions & 2 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use frame_system::{
};
use pallet_asset_conversion_tx_payment::SwapAssetAdapter;
use pallet_nfts::{DestroyWitness, PalletFeatures};
use pallet_revive::evm::runtime::EthExtra;
use pallet_revive::{evm::runtime::EthExtra, AddressMapper};
use parachains_common::{
impls::DealWithFees, message_queue::*, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance,
BlockNumber, CollectionId, Hash, Header, ItemId, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO,
Expand Down Expand Up @@ -2069,8 +2069,17 @@ impl_runtime_apis! {
}
}

impl pallet_revive::ReviveApi<Block, AccountId, Balance, BlockNumber, EventRecord> for Runtime
impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber, EventRecord> for Runtime
{
fn balance(address: H160) -> Balance {
let account = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&address);
Balances::usable_balance(account)
}

fn nonce(address: H160) -> Nonce {
let account = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&address);
System::account_nonce(account)
}
fn eth_transact(
from: H160,
dest: Option<H160>,
Expand Down
17 changes: 17 additions & 0 deletions prdoc/pr_6147.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
title: "[pallet-revive] Ethereum JSON-RPC"

doc:
- audience: Runtime Dev
description: |
Add a new Ethereum JSON-RPC server that can be used a substrate chain configured with pallet-revive
crates:
- name: pallet-revive
bump: patch
- name: asset-hub-westend-runtime
bump: patch
- name: pallet-revive-eth-rpc
bump: patch
- name: pallet-revive-fixtures
bump: patch
- name: polkadot-sdk
bump: patch
4 changes: 0 additions & 4 deletions substrate/bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,6 @@ fn default_endowed_accounts() -> Vec<AccountId> {
.chain([
eth_account(subxt_signer::eth::dev::alith()),
eth_account(subxt_signer::eth::dev::baltathar()),
eth_account(subxt_signer::eth::dev::charleth()),
eth_account(subxt_signer::eth::dev::dorothy()),
eth_account(subxt_signer::eth::dev::ethan()),
eth_account(subxt_signer::eth::dev::faith()),
])
.collect()
}
Expand Down
14 changes: 12 additions & 2 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ use pallet_identity::legacy::IdentityInfo;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_nfts::PalletFeatures;
use pallet_nis::WithMaximumOf;
use pallet_revive::evm::runtime::EthExtra;
use pallet_revive::{evm::runtime::EthExtra, AddressMapper};
use pallet_session::historical as pallet_session_historical;
// Can't use `FungibleAdapter` here until Treasury pallet migrates to fungibles
// <https://github.com/paritytech/polkadot-sdk/issues/226>
Expand Down Expand Up @@ -3157,8 +3157,18 @@ impl_runtime_apis! {
}
}

impl pallet_revive::ReviveApi<Block, AccountId, Balance, BlockNumber, EventRecord> for Runtime
impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber, EventRecord> for Runtime
{
fn balance(address: H160) -> Balance {
let account = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&address);
Balances::usable_balance(account)
}

fn nonce(address: H160) -> Nonce {
let account = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&address);
System::account_nonce(account)
}

fn eth_transact(
from: H160,
dest: Option<H160>,
Expand Down
Loading

0 comments on commit 58fd5ae

Please sign in to comment.