2

我正在关注Substrate Kitties研讨会。在1/Viewing a Storage Mapping中,我无法访问Polkadot UI 选项卡上的kitties模块:#extrinsics

截图于 2019-07-18 11-36-02

我尝试多次重新加载它。这是我的kitties.rs(编译得很好):

use support::{decl_storage, decl_module, StorageMap, dispatch::Result};
use system::ensure_signed;

pub trait Trait: balances::Trait {}

decl_storage! {
    trait Store for Module<T: Trait> as KittyStorage {
        Value: map T::AccountId => u64;
    }
}

decl_module! {
    pub struct Module<T: Trait> for enum Call where origin: T::Origin {
        fn set_value(origin, value: u64) -> Result {
            let sender = ensure_signed(origin)?;
            <Value<T>>::insert(sender, value);
            Ok(())
        }
    }
}

我在lib.rs

/// Used for the Substrate Kitties in `./kitties.rs`
mod kitties;

[...]

/// Used for the Substrate Kitties in `./kitties.rs`
impl kitties::Trait for Runtime {}

并将其添加到运行时。

construct_runtime!(
    pub enum Runtime with Log(InternalLog: DigestItem<Hash, AuthorityId, AuthoritySignature>) where
        Block = Block,
        NodeBlock = opaque::Block,
        UncheckedExtrinsic = UncheckedExtrinsic
    {
        System: system::{default, Log(ChangesTrieRoot)},
        Timestamp: timestamp::{Module, Call, Storage, Config<T>, Inherent},
        Consensus: consensus::{Module, Call, Storage, Config<T>, Log(AuthoritiesChange), Inherent},
        Aura: aura::{Module},
        Indices: indices,
        Balances: balances,
        Sudo: sudo,
        Kitties: kitties::{Module, Call, Storage},
        // Used for the module template in `./template.rs`
        TemplateModule: template::{Module, Call, Storage, Event<T>},
        ExampleModule: substrate_module_template::{Module, Call, Storage, Event<T>},

    }
);

我错过了什么?向 Substrate 运行时注册我的模块还需要什么?

4

1 回答 1

2

这里的问题可能是您的链尚未升级运行时,因此您无法在现有链上看到新模块。当您在运行时开发和注册新模块时运行链时会发生这种情况。

要解决此问题并确保正确注册所有模块,您必须清除链并使用最新代码开始新的开发链。要清除,请运行:

❯ target/release/substratekitties purge-chain --dev

重新启动一个新链:

❯ target/release/substratekitties --dev

kitties 模块应该在外部选项卡中可用。

于 2019-07-18T10:09:20.557 回答