繁体   English   中英

如何为 Substrate Runtime 实现 EVM Trait?

[英]How to implement the EVM Trait for a Substrate Runtime?

向您的运行时添加模块之后,我正在尝试为Dothereum Runtime实现Parity Substrate paint-evm特征。

EVM 模块特征定义如下:

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;
}

然而,这里的添加模块教程有点含糊,鼓励人们:

“.. 如果事情没有意义,请探索 [..] 模块的源代码..”

虽然 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)
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM