-3

I am looking to receive Proposal data from a Sputnik v2 DAO Contract. I want to call get_proposals but that returns a json list of the proposals. I am unsure as to what the method signature on the callback function would look like to receive the data. Since sputnik-dao-contract is not a published Rust Crate, I cannot import the Proposal struct and use it to deserialize. What is the best approach to processing the response and getting the Proposal id?

Here is the method I want to call: https://github.com/near-daos/sputnik-dao-contract#view-multiple-proposals

How to I recieve, deserialize and use the response programmatically in Rust?

Rashi Abramson
  • 1,127
  • 8
  • 16

2 Answers2

0

If the get_proposals method already returns a list of proposals, aren't you already getting what you need? I mean, the data is in the response. If you need a proposal on a specific ID, you can always use another function, get_proposal instead.

From the response, the struct looks simple enough that you can create it on your own. You can copy the Proposal struct directly from the repo as well.

/// 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,
}
John
  • 10,165
  • 5
  • 55
  • 71
-1

It turned out the answer was to create a barebones struct that matched the json response. The barebones struct of

pub struct Proposal {
    pub id: u64,
}

(from https://github.com/near-daos/sputnik-dao-contract/blob/main/sputnikdao2/src/views.rs#L12) got me what I needed. I added other fields as necessary.

Rashi Abramson
  • 1,127
  • 8
  • 16