[英]How to implement the EVM Trait for a Substrate Runtime?
Following the adding a module to your runtime , I'm trying to implement the Parity Substrate paint-evm
trait for the Dothereum Runtime .在向您的运行时添加模块之后,我正在尝试为Dothereum Runtime实现Parity Substrate
paint-evm
特征。
TheEVM module trait is defined as follows: 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;
}
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.."
“.. 如果事情没有意义,请探索 [..] 模块的源代码..”
While the EVM module code doesn't seem too complex, I fail to understand how to implement the EVM trait for my runtime:虽然 EVM 模块代码似乎不太复杂,但我不明白如何为我的运行时实现 EVM 特征:
impl evm::Trait for Runtime {
type FeeCalculator = ();
type ConvertAccountId = ();
type Currency = Balances;
type Event = Event;
type Precompiles = ();
}
What types do FeeCalculator
and ConvertAccountId
expect here? FeeCalculator
和ConvertAccountId
在这里期望什么类型?
Because pallet-evm doesn't provide default implementations for the types you need, you'll need to create them yourself.因为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)
}
I look forward to improving this answer as I understand more myself.随着我对自己的了解更多,我期待改进这个答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.