Overview
TheProposalService class provides methods for retrieving and processing governance proposals from NNS and SNS governance canisters. It works in conjunction with GovernanceService to fetch proposal data and format it for display.
Constructor
ProposalService
Creates a new ProposalService instance.The governance service instance used to make governance canister calls
The log service instance for logging operations
Methods
getValidTopicIds
Retrieves valid topic IDs (also called functions) for a given governance canister.The canister ID of the governance canister (e.g.,
"rrkah-fqaaa-aaaaa-aaaaq-cai" for NNS)Returns a tuple array where each entry contains:
- Topic ID (Int32)
- Topic name (Text)
- Optional description (?Text)
listProposalsAfterId
Fetches all proposals after a specific proposal ID, paginating through results automatically.The canister ID of the governance canister
Optional proposal ID to start fetching from. If
null, fetches the most recent proposal only.Configuration for proposal filtering and inclusion. See ListProposalArgs.
Returns a
ListProposalInfoResponse containing an array of ProposalInfo objects, or an error message.- Automatically paginates through proposals in batches of 50
- Fetches proposals with ID greater than the
_afterparameter - Results are returned in chronological order (oldest to newest)
- Stops fetching when it encounters a proposal with ID less than or equal to
_after
Utility Functions
processIncludeTopics
Filters out specified topics from a list of valid topics, creating an exclusion list.Array of all valid topics with their IDs, names, and descriptions
Array of topic IDs that should be included in results
Returns an array of topic IDs to exclude (inverse of
topicsToInclude)ListProposalArgsDefault
Returns default arguments for listing proposals.Returns a default
ListProposalArgs configuration:includeRewardStatus: empty arrayomitLargeFields:trueexcludeTopic: empty arrayincludeAllManageNeuronProposals:nullincludeStatus: empty array
Integration with GovernanceService
TheProposalService relies on GovernanceService for low-level governance canister interactions:
- Fetching Functions: Uses
governanceService.getGovernanceFunctions()to retrieve valid topics for SNS governance - Listing Proposals: Uses
governanceService.listProposals()for paginated proposal retrieval - Pagination: Automatically handles pagination by making multiple calls to
listProposals()with appropriatebefore_proposalcursors
Constants
Maximum number of proposals to fetch in a single batch
The canister ID of the NNS governance canister
Related
- ProposalTypes - Type definitions for proposals
- GovernanceService - Low-level governance canister interactions