3

向您的运行时添加模块之后,我正在尝试为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 = ();
}

FeeCalculator在这里做什么和ConvertAccountId期望什么类型?

4

1 回答 1

4

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

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

于 2019-11-19T21:50:20.243 回答