Overview
TheProposalTypes module defines the core data structures for representing governance proposals in the OpenChat Bot SDK. These types are used throughout the proposal service to represent proposal data, status, and filtering arguments.
Types
ProposalId
Unique identifier for a governance proposal.Proposal
Internal representation of a governance proposal with mutable fields.Unique identifier for the proposal
The topic/function ID that categorizes the proposal (e.g., Governance, Network Economics, etc.)
Human-readable title of the proposal
Optional detailed description or summary of the proposal
Neuron ID of the entity that created the proposal
Timestamp when the proposal was processed (in nanoseconds since epoch)
Current status of the proposal (mutable field)
Optional deadline for voting on the proposal (in seconds since epoch)
Timestamp when the proposal was originally created (in seconds since epoch)
ProposalAPI
API-safe representation of a proposal with immutable fields.Proposal, but all fields are immutable. This type is suitable for returning from public API methods or sending across canister boundaries.
Conversion:
Use proposalToAPI() from ProposalMappings to convert a Proposal to ProposalAPI.
ProposalStatus
Represents the current state of a governance proposal.The proposal is currently open for voting and has not been executed yet
The proposal has been executed with one of two outcomes:
#Approved: The proposal was accepted and executed successfully#Rejected: The proposal was rejected and not executed
1→#Pending4→#Executed(#Approved)2→#Executed(#Rejected)
ListProposalArgs
Arguments for filtering and configuring proposal list queries.Array of reward status codes to include in results. Empty array means no filtering by reward status.
If
true, large fields (like detailed proposal payloads) are omitted from results to reduce response sizeArray of topic IDs to exclude from results. Useful for filtering out specific proposal types.
If
true, includes all ManageNeuron proposals. If false or null, may filter out some ManageNeuron proposals.Array of status codes to include in results. Empty array means no filtering by status.
Mapping Functions
TheProposalMappings module provides utility functions for converting between different proposal representations.
proposalToAPI
Converts aProposal to ProposalAPI format.
The proposal to convert
Returns an immutable API-safe version of the proposal
mapProposal
Maps a governance canister’sProposalInfo to the SDK’s Proposal type.
Raw proposal data from the governance canister
Returns:
#ok(Proposal)if mapping succeeds#err(Text)if required fields are missing or status is unknown
- Proposal has no ID
- Proposal has no proposer
- Status cannot be mapped
mapGetProposals
Maps an array ofProposalInfo objects to an array of Proposal objects, silently skipping invalid proposals.
Array of raw proposal data from the governance canister
Returns an array of successfully mapped proposals. Invalid proposals are silently excluded.
Status Mapping
Internal function that maps NNS status codes toProposalStatus:
| NNS Status Code | ProposalStatus |
|---|---|
| 1 | #Pending |
| 4 | #Executed(#Approved) |
| 2 | #Executed(#Rejected) |
| Other | Error: “Unknown proposal status” |
Usage Example
Complete example of fetching and working with proposals:Related
- ProposalService - Service methods for working with proposals
- GovernanceTypes - Underlying governance canister types