使用 near-sdk-rust 初始化 LookupMap

Initializing a LookupMap with near-sdk-rust

我目前正在开发一个合同,我想在其中使用 LookupMap,但是我不清楚如何初始化它。这是代码:

// Just a structyre
pub struct Gift {
    url: String,
    n_tokens_required: usize,
    current_tokens: usize,
}

// Main contract code
#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize)]
pub struct Voting { // TODO: Rename this class
    pub gifts: LookupMap<String, Vector<Gift>>,
    pub contract_owner: String,
}

impl Default for Voting {
    fn default() -> Self {
        Voting {gifts: LookupMap::new(), contract_owner: env::current_account_id()}
    }
}

所以我希望我的合约的 gifts 属性是一个带有签名 LookupMap<String, Vector<Gift>> 的 LookupMap。如何在我的默认函数实现上初始化它?

当我尝试执行 LookupMap::new() 时,它说我需要一个具有 IntoStorageKey 特征的参数 key_prefix,但是我不清楚这个参数实际上是什么。

谁能帮助我更好地理解这一点?

谢谢!

您将在本页找到答案https://www.near-sdk.io/contract-structure/collections