我正在尝试使用 near_sdk Map和Vector使用一对多关系。
use near_sdk::collections::Map;
use near_sdk::collections::Vector;
#[near_bindgen]
#[derive(Default, BorshDeserialize, BorshSerialize)]
pub struct ProfileDetails {
profileTags: Map<String, IdProducts>,
}
#[near_bindgen]
#[derive(Default, BorshDeserialize, BorshSerialize)]
pub struct Products {
product_name: String,
product_details: String,
}
#[near_bindgen]
#[derive(Default, BorshDeserialize, BorshSerialize)]
pub struct IdProducts {
products: Vector<Products>,
}
对于 rust 本机集合,它是使用 push 方法完成的,例如
let mut hash_map: HashMap<u32, Vec<Sender>> = HashMap::new()
hash_map.entry(3)
.or_insert_with(Vec::new)
.push(sender)
如何使用近协议集合推送?
#[near_bindgen]
impl ProfileDetails {
pub fn set_profile(&mut self, product_name:String, product_details:String) {
let account_id = env::signer_account_id();
p = Products {
product_name,
product_details
};
self.profileTags.insert(&account_id, ???);
}
}
Solidity 示例在这里:https ://ethereum.stackexchange.com/a/39705/56408