Skip to content

Commit

Permalink
fix prefunded accounts for proper development experience on PolkadotJ…
Browse files Browse the repository at this point in the history
…S Apps (#1053)

* add eth prefunded accounts to template

* fix Account Lookup

* rm unnecessary mut

* fix prefunded accounts + sudo

* taplo format

* clippy

* lint hex_literal import
  • Loading branch information
bernardoaraujor committed May 21, 2023
1 parent 451d4fd commit 7374fec
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 28 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ environmental = { version = "1.1.4", default-features = false }
ethereum = { version = "0.14.0", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }
evm = { version = "0.37.0", default-features = false }
hex-literal = { version = "0.3.4" }
impl-serde = { version = "0.4.0", default-features = false }
jsonrpsee = "0.16.2"
kvdb-rocksdb = "0.17.0"
Expand Down
1 change: 1 addition & 0 deletions template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
async-trait = "0.1"
clap = { version = "4.1", features = ["derive", "deprecated"] }
futures = "0.3.25"
hex-literal = { workspace = true }
jsonrpsee = { workspace = true, features = ["server", "macros"] }
log = "0.4.17"
scale-codec = { package = "parity-scale-codec", workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions template/node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder {
self.client.as_ref(),
acc,
BalancesCall::transfer_keep_alive {
dest: self.dest.into(),
dest: self.dest,
value: self.value,
}
.into(),
Expand Down Expand Up @@ -171,7 +171,7 @@ pub fn create_benchmark_extrinsic(

runtime::UncheckedExtrinsic::new_signed(
call,
AccountId20::from(sender.public()).into(),
AccountId20::from(sender.public()),
runtime::Signature::new(signature),
extra,
)
Expand Down
44 changes: 23 additions & 21 deletions template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::{collections::BTreeMap, str::FromStr};

use hex_literal::hex;
use serde::{Deserialize, Serialize};
// Substrate
use sc_chain_spec::{ChainType, Properties};
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_core::{ecdsa, storage::Storage, Pair, Public, H160, U256};
#[allow(unused_imports)]
use sp_core::ecdsa;
use sp_core::{storage::Storage, Pair, Public, H160, U256};
use sp_runtime::traits::{IdentifyAccount, Verify};
use sp_state_machine::BasicExternalities;
// Frontier
Expand Down Expand Up @@ -49,9 +52,12 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu
.public()
}

#[allow(dead_code)]
type AccountPublic = <Signature as Verify>::Signer;

/// Generate an account ID from seed.
/// For use with `AccountId32`, `dead_code` if `AccountId20`.
#[allow(dead_code)]
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
Expand Down Expand Up @@ -84,14 +90,16 @@ pub fn development_config(enable_manual_seal: Option<bool>) -> DevChainSpec {
DevGenesisExt {
genesis_config: testnet_genesis(
wasm_binary,
// Sudo account
get_account_id_from_seed::<ecdsa::Public>("Alice"),
// Sudo account (Alith)
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
// Pre-funded accounts
vec![
get_account_id_from_seed::<ecdsa::Public>("Alice"),
get_account_id_from_seed::<ecdsa::Public>("Bob"),
get_account_id_from_seed::<ecdsa::Public>("Alice//stash"),
get_account_id_from_seed::<ecdsa::Public>("Bob//stash"),
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), // Alith
AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), // Baltathar
AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), // Charleth
AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), // Dorothy
AccountId::from(hex!("Ff64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB")), // Ethan
AccountId::from(hex!("C0F0f4ab324C46e55D02D0033343B4Be8A55532d")), // Faith
],
// Initial PoA authorities
vec![authority_keys_from_seed("Alice")],
Expand Down Expand Up @@ -129,22 +137,16 @@ pub fn local_testnet_config() -> ChainSpec {
testnet_genesis(
wasm_binary,
// Initial PoA authorities
// Sudo account
get_account_id_from_seed::<ecdsa::Public>("Alice"),
// Sudo account (Alith)
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
// Pre-funded accounts
vec![
get_account_id_from_seed::<ecdsa::Public>("Alice"),
get_account_id_from_seed::<ecdsa::Public>("Bob"),
get_account_id_from_seed::<ecdsa::Public>("Charlie"),
get_account_id_from_seed::<ecdsa::Public>("Dave"),
get_account_id_from_seed::<ecdsa::Public>("Eve"),
get_account_id_from_seed::<ecdsa::Public>("Ferdie"),
get_account_id_from_seed::<ecdsa::Public>("Alice//stash"),
get_account_id_from_seed::<ecdsa::Public>("Bob//stash"),
get_account_id_from_seed::<ecdsa::Public>("Charlie//stash"),
get_account_id_from_seed::<ecdsa::Public>("Dave//stash"),
get_account_id_from_seed::<ecdsa::Public>("Eve//stash"),
get_account_id_from_seed::<ecdsa::Public>("Ferdie//stash"),
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), // Alith
AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), // Baltathar
AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), // Charleth
AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), // Dorothy
AccountId::from(hex!("Ff64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB")), // Ethan
AccountId::from(hex!("C0F0f4ab324C46e55D02D0033343B4Be8A55532d")), // Faith
],
vec![
authority_keys_from_seed("Alice"),
Expand Down
2 changes: 1 addition & 1 deletion template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ pub fn build_full(
}

pub fn new_chain_ops(
mut config: &mut Configuration,
config: &mut Configuration,
eth_config: &EthConfiguration,
) -> Result<
(
Expand Down
8 changes: 4 additions & 4 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use sp_core::{
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, Get,
IdentifyAccount, NumberFor, PostDispatchInfoOf, UniqueSaturatedInto, Verify,
BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, Get, IdentifyAccount,
IdentityLookup, NumberFor, PostDispatchInfoOf, UniqueSaturatedInto, Verify,
},
transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError},
ApplyExtrinsicResult, ConsensusEngineId, Perbill, Permill,
Expand Down Expand Up @@ -181,7 +181,7 @@ impl frame_system::Config for Runtime {
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = AccountIdLookup<AccountId, ()>;
type Lookup = IdentityLookup<AccountId>;
/// The header type.
type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// The ubiquitous event type.
Expand Down Expand Up @@ -438,7 +438,7 @@ impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConve
}

/// The address format for describing accounts.
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
pub type Address = AccountId;
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Block type as expected by this runtime.
Expand Down

0 comments on commit 7374fec

Please sign in to comment.