我希望从Sputnik v2 DAO合同中接收v2数据。我想打电话给get_proposals,但这会返回一个提议的json列表。我不确定回调函数上的方法签名会是什么样子来接收数据。由于sputnik-dao-contract不是已发布的Rust,所以我不能导入Proposal结构并使用它进行反序列化。处理响应和获取Proposal id的最佳方法是什么?
下面是我想调用的方法:https://github.com/near-daos/sputnik-dao-contract#view-multiple-proposals
如何在Rust中以编程方式接收、反序列化和使用响应?
发布于 2022-02-14 21:02:51
结果,答案是创建一个与json响应相匹配的基本结构。最基本的结构
pub struct Proposal {
pub id: u64,
}(来自https://github.com/near-daos/sputnik-dao-contract/blob/main/sputnikdao2/src/views.rs#L12)我得到了我所需要的。我在必要时增加了其他字段。
发布于 2022-02-12 02:10:39
如果get_proposals方法已经返回了一个提议列表,那么您不是已经得到所需的了吗?我的意思是,数据在回应中。如果您需要对特定ID提出建议,则可以始终使用另一个函数提案。
从响应来看,这个结构看起来很简单,您可以自己创建它。您也可以从回购中直接复制提案结构。
/// Proposal that are sent to this DAO.
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
#[cfg_attr(not(target_arch = "wasm32"), derive(Debug))]
#[serde(crate = "near_sdk::serde")]
pub struct Proposal {
/// Original proposer.
pub proposer: AccountId,
/// Description of this proposal.
pub description: String,
/// Kind of proposal with relevant information.
pub kind: ProposalKind,
/// Current status of the proposal.
pub status: ProposalStatus,
/// Count of votes per role per decision: yes / no / spam.
pub vote_counts: HashMap<String, [Balance; 3]>,
/// Map of who voted and how.
pub votes: HashMap<AccountId, Vote>,
/// Submission time (for voting period).
pub submission_time: U64,
}https://stackoverflow.com/questions/71026052
复制相似问题