Skip to content

Commit

Permalink
Add RPC integration
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Sep 30, 2024
1 parent 05b5fb2 commit 4f4efcc
Show file tree
Hide file tree
Showing 20 changed files with 1,884 additions and 42 deletions.
73 changes: 71 additions & 2 deletions Cargo.lock

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

28 changes: 26 additions & 2 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3005,14 +3005,38 @@ impl_runtime_apis! {

impl pallet_revive::ReviveApi<Block, AccountId, Balance, BlockNumber, EventRecord> for Runtime
{
fn eth_transact(
from: H160,
dest: Option<H160>,
value: Balance,
input: Vec<u8>,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
) -> pallet_revive::ContractResult<pallet_revive::EthTransactReturnValue, Balance, EventRecord>
{
use pallet_revive::AddressMapper;
let blockweights: BlockWeights = <Runtime as frame_system::Config>::BlockWeights::get();
let origin = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id_contract(&from);
Revive::bare_eth_transact(
RuntimeOrigin::signed(origin),
dest,
value,
input,
gas_limit.unwrap_or(blockweights.max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
)
}

fn call(
origin: AccountId,
dest: H160,
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_revive::ContractExecResult<Balance, EventRecord> {
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance, EventRecord> {
Revive::bare_call(
RuntimeOrigin::signed(origin),
dest,
Expand All @@ -3033,7 +3057,7 @@ impl_runtime_apis! {
code: pallet_revive::Code,
data: Vec<u8>,
salt: Option<[u8; 32]>,
) -> pallet_revive::ContractInstantiateResult<Balance, EventRecord>
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance, EventRecord>
{
Revive::bare_instantiate(
RuntimeOrigin::signed(origin),
Expand Down
24 changes: 21 additions & 3 deletions substrate/frame/revive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ codec = { features = [
], workspace = true }
scale-info = { features = ["derive"], workspace = true }
log = { workspace = true }
serde = { optional = true, features = ["derive"], workspace = true, default-features = true }
serde = { features = ["alloc", "derive"], workspace = true, default-features = false }
impl-trait-for-tuples = { workspace = true }
rlp = { workspace = true }
derive_more.workspace = true
hex = { workspace = true }
jsonrpsee = { workspace = true, features = ["full"], optional = true }
ethereum-types = { workspace = true, features = ["codec", "rlp", "serialize"] }

# Polkadot SDK Dependencies
frame-benchmarking = { optional = true, workspace = true }
Expand All @@ -39,19 +43,21 @@ pallet-balances = { optional = true, workspace = true }
pallet-revive-fixtures = { workspace = true, default-features = false }
pallet-revive-uapi = { workspace = true, default-features = true }
pallet-revive-proc-macro = { workspace = true, default-features = true }
pallet-transaction-payment = { workspace = true }
sp-api = { workspace = true }
sp-arithmetic = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
sp-weights = { workspace = true }
xcm = { workspace = true }
xcm-builder = { workspace = true }

[dev-dependencies]
array-bytes = { workspace = true, default-features = true }
assert_matches = { workspace = true }
pretty_assertions = { workspace = true }
wat = { workspace = true }
pallet-revive-fixtures = { workspace = true, default-features = true }

# Polkadot SDK Dependencies
Expand All @@ -64,6 +70,9 @@ pallet-proxy = { workspace = true, default-features = true }
sp-keystore = { workspace = true, default-features = true }
sp-tracing = { workspace = true, default-features = true }
xcm-builder = { workspace = true, default-features = true }
secp256k1 = { workspace = true, features = ["recovery"] }
serde_json.workspace = true
hex-literal.workspace = true

[features]
default = ["std"]
Expand All @@ -77,6 +86,7 @@ std = [
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"jsonrpsee",
"log/std",
"pallet-balances?/std",
"pallet-proxy/std",
Expand All @@ -86,13 +96,20 @@ std = [
"polkavm/std",
"rlp/std",
"scale-info/std",
"serde",
"ethereum-types/std",
"hex/std",
"pallet-transaction-payment/std",
"secp256k1/std",
"serde/std",
"serde_json/std",
"sp-api/std",
"sp-arithmetic/std",
"sp-core/std",
"sp-io/std",
"sp-keystore/std",
"sp-runtime/std",
"sp-std/std",
"sp-weights/std",
"xcm-builder/std",
"xcm/std",
]
Expand All @@ -117,6 +134,7 @@ try-runtime = [
"pallet-message-queue/try-runtime",
"pallet-proxy/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-utility/try-runtime",
"sp-runtime/try-runtime",
]
4 changes: 3 additions & 1 deletion substrate/frame/revive/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

//! Functions that deal contract addresses.

use crate::LOG_TARGET;
use alloc::vec::Vec;
use sp_core::H160;
use sp_io::hashing::keccak_256;
Expand All @@ -34,7 +35,7 @@ use sp_runtime::AccountId32;
/// case for all existing runtimes as of right now. Reasing is that this will allow
/// us to reverse an address -> account_id mapping by just stripping the prefix.
pub trait AddressMapper<T>: private::Sealed {
/// Convert an account id to an ethereum adress.
/// Convert an account id to an ethereum address.
///
/// This mapping is **not** required to be reversible.
fn to_address(account_id: &T) -> H160;
Expand Down Expand Up @@ -77,6 +78,7 @@ impl AddressMapper<AccountId32> for DefaultAddressMapper {

/// Determine the address of a contract using CREATE semantics.
pub fn create1(deployer: &H160, nonce: u64) -> H160 {
log::debug!(target: LOG_TARGET, "create1: deployer={deployer:?}, nonce={nonce}");
let mut list = rlp::RlpStream::new_list(2);
list.append(&deployer.as_bytes());
list.append(&nonce);
Expand Down
6 changes: 6 additions & 0 deletions substrate/frame/revive/src/evm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//!Types, and traits to integrate pallet-revive with EVM.
#![warn(missing_docs)]

mod api;
pub use api::*;
pub mod runtime;
21 changes: 21 additions & 0 deletions substrate/frame/revive/src/evm/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! JSON-RPC methods and types, for Ethereum.

mod byte;
pub use byte::*;

mod rlp_codec;
pub use rlp;

mod type_id;
pub use type_id::*;

mod rpc_types;
mod rpc_types_gen;
pub use rpc_types_gen::*;

#[cfg(feature = "std")]
pub mod rpc_methods_gen;
#[cfg(feature = "std")]
pub use rpc_methods_gen::*;

mod signature;
Loading

0 comments on commit 4f4efcc

Please sign in to comment.