我的目标是将哈希值存储在底层链中。我已经在下面的代码中声明了它的存储和模块:
use support::{decl_module, decl_storage, dispatch::Result, ensure, StorageMap};
use system::ensure_signed;
pub trait Trait: balances::Trait {}
decl_storage! {
trait Store for Module<T: Trait> as KittyStorage {
Value: map str => Option<T::AccountId>;
}
}
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)?;
ensure!(!<Value<T>>::exists(value), "key already exists");
<Value<T>>::insert(value, sender);
Ok(())
}
}
}
只要我u64
在该行中使用,该代码就可以正常工作,但是当我将其更改为时收到错误消息str
:
Value: map str => Option<T::AccountId>;
错误是:
error[E0277]: the trait bound `str: _::_parity_scale_codec::EncodeLike` is not satisfied
--> /Users/aviralsrivastava/dev/substrate-package/substrate-node-template/runtime/src/substratekitties.rs:6:1
|
6 | / decl_storage! {
7 | | trait Store for Module<T: Trait> as KittyStorage {
8 | | Value: map str => Option<T::AccountId>;
9 | | }
10 | | }
| |_^ the trait `_::_parity_scale_codec::EncodeLike` is not implemented for `str`
|
我尝试阅读它,但找不到任何其他存储字符串的方法。虽然,我的字符串将是固定大小的,因为它始终是 SHA256。