【发布时间】:2021-11-04 19:27:54
【问题描述】:
我正在向 Sputnik DAO v2 Near 合约添加一项功能,以将代币映射到投票数。
这是我的构造函数:
#[ext_contract(ext_self)]
pub trait Contract {
fn exchange_callback_post_withdraw(&mut self, sender_id: AccountId, token_id: String, amount: U128);
}
#[near_bindgen]
impl Contract {
#[init]
pub fn new(
owner_id: AccountId,
token_ids: UnorderedSet<String>,
unstake_period: U64,
token_vote_weights: LookupMap<String, U128>,
) -> Self {
Self {
owner_id: owner_id.into(),
vote_token_ids: token_ids,
users: LookupMap::new(StorageKeys::Users),
total_amount: UnorderedMap::new(StorageKeys::ValidNFTs),
unstake_period: unstake_period.0,
token_vote_weights,
}
}
我收到此错误:
error[E0277]: the trait bound `LookupMap<std::string::String, near_sdk::json_types::U128>: Serialize` is not satisfied
--> sputnik-nft-staking/src/lib.rs:67:1
|
67 | #[near_bindgen]
| ^^^^^^^^^^^^^^^ the trait `Serialize` is not implemented for `LookupMap<std::string::String, near_sdk::json_types::U128>`
|
::: /home/rashi/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_json-1.0.64/src/value/mod.rs:965:8
|
965 | T: Serialize,
| --------- required by this bound in `to_value`
|
= note: required because of the requirements on the impl of `Serialize` for `&LookupMap<std::string::String, near_sdk::json_types::U128>`
我如何序列化字符串,或者是否有代码更改可以更好地帮助实现将投票权重与令牌相关联的目标?
【问题讨论】:
标签: rust near-sdk-rs