Skip to content

Commit

Permalink
Adds EVM pallet to runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
crystalin committed May 7, 2020
1 parent 98a8625 commit 31905be
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
5 changes: 5 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,10 @@ version = '2.0.0-alpha.7'
[build-dependencies.substrate-build-script-utils]
version = '2.0.0-alpha.7'

[dependencies.evm]
default-features = false
version = '2.0.0-alpha.7'
package = 'pallet-evm'

[[bin]]
name = 'node-moonbeam'
22 changes: 18 additions & 4 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use node_moonbeam_runtime::{
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig,
SystemConfig, WASM_BINARY,
AccountId, AuraConfig, BalancesConfig, EVMAccount, EVMConfig, GenesisConfig, GrandpaConfig,
Signature, SudoConfig, SystemConfig, WASM_BINARY,
};
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{sr25519, Pair, Public};
use sp_core::{sr25519, Pair, Public, U256};
use sp_finality_grandpa::AuthorityId as GrandpaId;
use sp_runtime::traits::{IdentifyAccount, Verify};
use sp_runtime::traits::{BlakeTwo256, IdentifyAccount, Verify};

use evm::{ConvertAccountId, HashTruncateConvertAccountId};
// Note this is the URL for the telemetry server
//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";

Expand Down Expand Up @@ -105,6 +106,10 @@ fn testnet_genesis(
endowed_accounts: Vec<AccountId>,
_enable_println: bool,
) -> GenesisConfig {
let alice_account_id = get_account_id_from_seed::<sr25519::Public>("Alice");
let alice_evm_account_id =
HashTruncateConvertAccountId::<BlakeTwo256>::convert_account_id(&alice_account_id);

GenesisConfig {
system: Some(SystemConfig {
code: WASM_BINARY.to_vec(),
Expand All @@ -127,5 +132,14 @@ fn testnet_genesis(
.collect(),
}),
sudo: Some(SudoConfig { key: root_key }),
evm: Some(EVMConfig {
accounts: vec![(
alice_evm_account_id,
EVMAccount {
nonce: 0.into(),
balance: U256::MAX,
},
)],
}),
}
}
6 changes: 6 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ version = '1.0.5'
[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']

[dependencies.evm]
default-features = false
version = '2.0.0-alpha.7'
package = 'pallet-evm'

[features]
default = ['std']
std = [
Expand Down Expand Up @@ -148,4 +153,5 @@ std = [
'system/std',
'timestamp/std',
'transaction-payment/std',
'evm/std',
]
31 changes: 29 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@ use grandpa::fg_primitives;
use grandpa::AuthorityList as GrandpaAuthorityList;
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::OpaqueMetadata;
use sp_core::{OpaqueMetadata, U256};
use sp_runtime::traits::{
BlakeTwo256, Block as BlockT, ConvertInto, IdentifyAccount, IdentityLookup, Verify,
};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
ApplyExtrinsicResult, ModuleId, MultiSignature,
};
use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use evm::{FeeCalculator, HashTruncateConvertAccountId};

// A few exports that help ease life for downstream crates.
pub use balances::Call as BalancesCall;
pub use evm::Account as EVMAccount;
pub use frame_support::{
construct_runtime, parameter_types,
traits::Randomness,
Expand Down Expand Up @@ -68,6 +71,9 @@ pub type Hash = sp_core::H256;
/// Digest item type.
pub type DigestItem = generic::DigestItem<Hash>;

// EVM structs
pub struct FixedGasPrice;

/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
Expand Down Expand Up @@ -128,6 +134,8 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
pub const Version: RuntimeVersion = VERSION;

pub const EVMModuleId: ModuleId = ModuleId(*b"py/evmpa");
}

impl system::Trait for Runtime {
Expand Down Expand Up @@ -231,6 +239,24 @@ impl sudo::Trait for Runtime {
type Call = Call;
}

impl FeeCalculator for FixedGasPrice {
fn min_gas_price() -> U256 {
// Gas price is always one token per gas.
1.into()
}
}

impl evm::Trait for Runtime {
type ModuleId = EVMModuleId;
type FeeCalculator = FixedGasPrice;
type ConvertAccountId = HashTruncateConvertAccountId<BlakeTwo256>;
type Currency = Balances;
type Event = Event;
type Precompiles = (); // We can use () here because paint_evm provides an
// `impl Precompiles for ()``
// block that always returns none (line 75)
}

construct_runtime!(
pub enum Runtime where
Block = Block,
Expand All @@ -245,6 +271,7 @@ construct_runtime!(
Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},
TransactionPayment: transaction_payment::{Module, Storage},
Sudo: sudo::{Module, Call, Config<T>, Storage, Event<T>},
EVM: evm::{Module, Config, Call, Storage, Event<T>},
}
);

Expand Down

0 comments on commit 31905be

Please sign in to comment.