|
| 1 | +using Solnet.Programs.Governance; |
| 2 | +using Solnet.Rpc; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Linq; |
| 6 | +using System.Text; |
| 7 | +using System.Threading.Tasks; |
| 8 | + |
| 9 | +namespace Solnet.Examples |
| 10 | +{ |
| 11 | + public class GovernanceProgramExamples : IExample |
| 12 | + { |
| 13 | + |
| 14 | + private static readonly IRpcClient mRpcClient = ClientFactory.GetClient(Cluster.MainNet); |
| 15 | + private GovernanceClient governanceClient; |
| 16 | + |
| 17 | + public GovernanceProgramExamples() |
| 18 | + { |
| 19 | + governanceClient = new GovernanceClient(mRpcClient, GovernanceProgram.MainNetProgramIdKey); |
| 20 | + } |
| 21 | + |
| 22 | + public void Run() |
| 23 | + { |
| 24 | + var realms = governanceClient.GetRealms(); |
| 25 | + |
| 26 | + for(int i = 0; i < realms.ParsedResult.Count; i++) |
| 27 | + { |
| 28 | + Console.WriteLine($"--------------------------------------\n" + |
| 29 | + $"Realm: {realms.ParsedResult[i].Name}\n" + |
| 30 | + $"Community Mint: {realms.ParsedResult[i].CommunityMint}\n" + |
| 31 | + $"Authority: {realms.ParsedResult[i]?.Authority}\n" + |
| 32 | + $"Council Mint: {realms.ParsedResult[i].Config?.CouncilMint}\n" + |
| 33 | + $"Vote Weight Source: {realms.ParsedResult[i].Config.CommunityMintMaxVoteWeightSource}\n"); |
| 34 | + |
| 35 | + var progGovernances = governanceClient.GetProgramGovernanceAccounts(realms.OriginalRequest.Result[i].PublicKey); |
| 36 | + var mintGovernances = governanceClient.GetMintGovernanceAccounts(realms.OriginalRequest.Result[i].PublicKey); |
| 37 | + var tokenGovernances = governanceClient.GetTokenGovernanceAccounts(realms.OriginalRequest.Result[i].PublicKey); |
| 38 | + var genericGovernances = governanceClient.GetGenericGovernanceAccounts(realms.OriginalRequest.Result[i].PublicKey); |
| 39 | + Console.WriteLine($"Program Governance Accounts: {progGovernances.ParsedResult?.Count}\n" + |
| 40 | + $"Mint Governance Accounts: {mintGovernances.ParsedResult?.Count}\n" + |
| 41 | + $"Token Governance Accounts: {tokenGovernances.ParsedResult?.Count}\n" + |
| 42 | + $"Generic Governance Accounts: {genericGovernances.ParsedResult?.Count}\n"); |
| 43 | + |
| 44 | + for(int j = 0; j < progGovernances.ParsedResult?.Count; j++) |
| 45 | + { |
| 46 | + var proposals = governanceClient.GetProposalsV1(progGovernances.OriginalRequest.Result[j].PublicKey); |
| 47 | + Console.WriteLine($"Program Governance: {progGovernances.OriginalRequest.Result[j].PublicKey}\n" + |
| 48 | + $"Proposals: {proposals.OriginalRequest.Result.Count}"); |
| 49 | + for(int k = 0; k < proposals.ParsedResult?.Count; k++) |
| 50 | + { |
| 51 | + Console.WriteLine($"Proposal: {proposals.ParsedResult[k].Name}\n" + |
| 52 | + $"Link: {proposals.ParsedResult[k].DescriptionLink}"); |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments