如何为基板运行时实现EVM特性? [英] How to implement the EVM Trait for a Substrate Runtime?

查看:143
本文介绍了如何为基板运行时实现EVM特性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照将模块添加到您的运行时,我正在尝试实现 Parity Substrate paint-evm特性用于 Dothereum Runtime .

Following the adding a module to your runtime, I'm trying to implement the Parity Substrate paint-evm trait for the Dothereum Runtime.

EVM模块特征的定义如下:

The EVM module trait is defined as follows:

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

但是,这里的添加模块教程有点含糊,建议大家这样做:

The adding a module tutorial here, however, is a bit vague and encourages one to:

"..如果没有任何意义,请探索[..]模块的源代码."

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

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

While the EVM module code doesn't seem too complex, I fail to understand how to implement the EVM trait for my runtime:

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

FeeCalculatorConvertAccountId在这里期望什么类型?

What types do FeeCalculator and ConvertAccountId expect here?

推荐答案

由于pallet-evm不提供所需类型的默认实现,因此需要自行创建.

Because pallet-evm doesn't provide default implementations for the types you need, you'll need to create them yourself.

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

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

I look forward to improving this answer as I understand more myself.

这篇关于如何为基板运行时实现EVM特性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆