gpt4 book ai didi

rust - 如何为 Substrate Runtime 实现 EVM Trait?

转载 作者:行者123 更新时间:2023-11-29 08:06:58 24 4
gpt4 key购买 nike

adding a module to your runtime 之后,我正在尝试实现 Parity Substrate Dothereum Runtimepaint-evm 特性.

EVM module trait定义如下:

pub trait Trait: Trait + Trait {
type FeeCalculator: FeeCalculator;
type ConvertAccountId: ConvertAccountId<Self::AccountId>;
type Currency: Currency<Self::AccountId>;
type Event: From<Event> + Into<Self::Event>;
type Precompiles: Precompiles;
}

然而,此处的添加模块教程有点含糊,并鼓励人们:

".. explore the source code of the [..] module if things don't make sense .."

虽然 EVM 模块代码看起来并不太复杂,但我无法理解如何为我的运行时实现 EVM 特性:

impl evm::Trait for Runtime {
type FeeCalculator = ();
type ConvertAccountId = ();
type Currency = Balances;
type Event = Event;
type Precompiles = ();
}

FeeCalculatorConvertAccountId 在这里需要什么类型?

最佳答案

因为 pallet-evm 不为您需要的类型提供默认实现,您需要自己创建它们。

use paint_evm::{FeeCalculator, ConvertAccountId};
use primitives::{U256, H160};

pub struct FixedGasPrice;

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

pub struct TruncatedAccountId;

impl<AccountId> ConvertAccountId<AccountId> for TruncatedAccountId {
fn convert_account_id(account_id: &AccountId) -> H160 {
//TODO just truncate the fist several bits and return the resulting H160
// Or maybe hashing is easier to figure out
unimplemented!();
}
}

impl paint_evm::Trait for Runtime {
type FeeCalculator = FixedGasPrice;
type ConvertAccountId = TruncatedAccountId;
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)
}

随着我对自己的了解越来越多,我期待着改进这个答案。

关于rust - 如何为 Substrate Runtime 实现 EVM Trait?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58942015/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com