Skip to content

Commit

Permalink
bootstrap fp-account
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardoaraujor committed Mar 15, 2023
1 parent 58c5689 commit bd2da65
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 43 deletions.
41 changes: 35 additions & 6 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"client/db",
"client/storage",
"client/mapping-sync",
"primitives/account",
"primitives/consensus",
"primitives/dynamic-fee",
"primitives/evm",
Expand All @@ -41,15 +42,18 @@ environmental = { version = "1.1.3", 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 }
impl-serde = { version = "0.3.1", default-features = false }
jsonrpsee = "0.16.2"
kvdb-rocksdb = "0.17.0"
libsecp256k1 = "0.7.1"
libsecp256k1 = { version = "0.7.1", default-features = false }
log = { version = "0.4.17", default-features = false }
parity-db = "0.4.2"
rlp = { version = "0.5", default-features = false }
scale-codec = { package = "parity-scale-codec", version = "3.2.1", default-features = false, features = ["derive"] }
scale-info = { version = "2.3.1", default-features = false, features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha3 = { version = "0.10", default-features = false }
# Substrate Client
sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-block-builder = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down Expand Up @@ -124,6 +128,7 @@ fc-rpc = { version = "2.0.0-dev", path = "client/rpc" }
fc-rpc-core = { version = "1.1.0-dev", path = "client/rpc-core" }
fc-storage = { version = "1.0.0-dev", path = "client/storage" }
# Frontier Primitive
fp-account = { version = "1.0.0-dev", path = "primitives/account", default-features = false }
fp-consensus = { version = "2.0.0-dev", path = "primitives/consensus", default-features = false }
fp-dynamic-fee = { version = "1.0.0", path = "primitives/dynamic-fee", default-features = false }
fp-ethereum = { version = "1.0.0-dev", path = "primitives/ethereum", default-features = false }
Expand Down
4 changes: 3 additions & 1 deletion frame/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ environmental = { workspace = true, optional = true }
evm = { workspace = true, features = ["with-codec"] }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
impl-trait-for-tuples = "0.2.2"
log = { version = "0.4.17", default-features = false }
log = { workspace = true }
rlp = { workspace = true }
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
Expand All @@ -30,6 +30,7 @@ sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
# Frontier
fp-account = { workspace = true }
fp-evm = { workspace = true }

[dev-dependencies]
Expand Down Expand Up @@ -59,6 +60,7 @@ std = [
"sp-std/std",
# Frontier
"fp-evm/std",
"fp-account/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
29 changes: 29 additions & 0 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ use sp_std::{cmp::min, vec::Vec};
pub use evm::{
Config as EvmConfig, Context, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed,
};
use fp_account::AccountId20;
#[cfg(feature = "std")]
use fp_evm::GenesisAccount;
pub use fp_evm::{
Expand Down Expand Up @@ -603,6 +604,24 @@ where
}
}

/// Ensure that the address is AccountId20.
pub struct EnsureAccountId20;

impl<OuterOrigin> EnsureAddressOrigin<OuterOrigin> for EnsureAccountId20
where
OuterOrigin: Into<Result<RawOrigin<AccountId20>, OuterOrigin>> + From<RawOrigin<AccountId20>>,
{
type Success = AccountId20;

fn try_address_origin(address: &H160, origin: OuterOrigin) -> Result<AccountId20, OuterOrigin> {
let acc: AccountId20 = AccountId20::from(*address);
origin.into().and_then(|o| match o {
RawOrigin::Signed(who) if who == acc => Ok(who),
r => Err(OuterOrigin::from(r)),
})
}
}

pub trait AddressMapping<A> {
fn into_account_id(address: H160) -> A;
}
Expand All @@ -616,6 +635,16 @@ impl AddressMapping<H160> for IdentityAddressMapping {
}
}

/// This is basically identical to IdentityAddressMapping,
/// but it works for any type that is `Into<H160>` (e.g.: `AccountId20`).
pub struct IntoAddressMapping;

impl<T: From<H160>> AddressMapping<T> for IntoAddressMapping {
fn into_account_id(address: H160) -> T {
address.into()
}
}

/// Hashed address mapping.
pub struct HashedAddressMapping<H>(sp_std::marker::PhantomData<H>);

Expand Down
38 changes: 38 additions & 0 deletions primitives/account/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "fp-account"
version = "1.0.0-dev"
license = "Apache-2.0"
description = "Primitives for Frontier AccountId20."
authors = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }

[dependencies]
hex = { version = "0.4.3", default-features = false }
impl-serde = { workspace = true }
libsecp256k1 = { workspace = true, default-features = false }
log = { workspace = true }
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
serde = { workspace = true }
sha3 = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]

[features]
default = ["std"]
std = [
"impl-serde/std",
"hex/std",
"libsecp256k1/std",
"log/std",
"sha3/std",
"serde/std",
# Substrate
"sp-io/std",
"sp-core/std",
"sp-runtime/std",
]
Loading

0 comments on commit bd2da65

Please sign in to comment.