• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bmresearch / Solnet / 13115350420

03 Feb 2025 02:09PM UTC coverage: 72.123% (-5.4%) from 77.499%
13115350420

push

github

BifrostTitan
Updated Governance program -- Example uses legacy mango markets DAO

1118 of 1754 branches covered (63.74%)

Branch coverage included in aggregate %.

0 of 11 new or added lines in 6 files covered. (0.0%)

5130 of 6909 relevant lines covered (74.25%)

1222547.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Solnet.Programs/Governance/GovernanceClient.cs
1
using Solnet.Programs.Abstract;
2
using Solnet.Programs.Governance.Enums;
3
using Solnet.Programs.Governance.Models;
4
using Solnet.Programs.Models;
5
using Solnet.Rpc;
6
using Solnet.Rpc.Models;
7
using Solnet.Wallet;
8
using Solnet.Wallet.Utilities;
9
using System;
10
using System.Collections.Generic;
11
using System.Linq;
12
using System.Text;
13
using System.Threading.Tasks;
14

15
namespace Solnet.Programs.Governance
16
{
17
    /// <summary>
18
    /// Implements a client for the governance program.
19
    /// </summary>
20
    public class GovernanceClient : BaseClient
21
    {
22
        /// <summary>
23
        /// Initialize the governance client.
24
        /// </summary>
25
        /// <param name="rpcClient">An <see cref="IRpcClient"/> instance.</param>
NEW
26
        public GovernanceClient(IRpcClient rpcClient, PublicKey governanceProgramID) : base(rpcClient, null, governanceProgramID) { }
×
27

28
        /// <summary>
29
        /// Gets all <see cref="Realm"/>s for the given program id. This is an asynchronous operation.
30
        /// </summary>
31
        /// <param name="programId">The deployed governance program id.</param>
32
        /// <returns>A task which may return the list of program accounts and their decoded structures.</returns>
33
        public async Task<ProgramAccountsResultWrapper<List<Realm>>> GetRealmsAsync(string programId)
34
        {
35
            var filters = new List<MemCmp>
×
36
            {
×
37
                new MemCmp{ Bytes = Encoders.Base58.EncodeData(new byte[]{ (byte)GovernanceAccountType.Realm }), Offset = GovernanceProgramAccount.Layout.AccountTypeOffset }
×
38
            };
×
39
            return await GetProgramAccounts<Realm>(programId, filters);
×
40
        }
×
41

42
        /// <summary>
43
        /// Gets all <see cref="Realm"/>s for the given program id.
44
        /// </summary>
45
        /// <returns>The list of program accounts and their decoded structures.</returns>
46
        public ProgramAccountsResultWrapper<List<Realm>> GetRealms(string programId) => GetRealmsAsync(programId).Result;
×
47

48
        /// <summary>
49
        /// Gets all <see cref="GovernanceAccount"/>s for the given program id. This is an asynchronous operation.
50
        /// </summary>
51
        /// <param name="programId">The deployed governance program id.</param>
52
        /// <param name="realm">The realm the governances belong to.</param>
53
        /// <returns>A task which may return the list of program accounts and their decoded structures.</returns>
54
        public async Task<ProgramAccountsResultWrapper<List<GovernanceAccount>>> GetGovernancesAsync(string programId, string realm)
55
        {
56
            var filters = new List<MemCmp>
×
57
            {
×
58
                new MemCmp{ Bytes = realm, Offset = GovernanceAccount.ExtraLayout.RealmOffset }
×
59
            };
×
60
            return await GetProgramAccounts<GovernanceAccount>(programId, filters);
×
61
        }
×
62

63
        /// <summary>
64
        /// Gets all <see cref="GovernanceAccount"/>s for the given program id.
65
        /// </summary>
66
        /// <param name="programId">The deployed governance program id.</param>
67
        /// <param name="realm">The realm the governances belong to.</param>
68
        /// <returns>The list of program accounts and their decoded structures.</returns>
69
        public ProgramAccountsResultWrapper<List<GovernanceAccount>> GetGovernances(string programId, string realm) => GetGovernancesAsync(programId, realm).Result;
×
70

71

72
        /// <summary>
73
        /// Gets all <see cref="GovernanceAccount"/>s of the type <see cref="GovernanceAccountType.MintGovernance"/> for the given program id. This is an asynchronous operation.
74
        /// </summary>
75
        /// <param name="programId">The deployed governance program id.</param>
76
        /// <param name="realm">The realm the governances belong to.</param>
77
        /// <returns>A task which may return the list of program accounts and their decoded structures.</returns>
78
        public async Task<ProgramAccountsResultWrapper<List<GovernanceAccount>>> GetMintGovernanceAccountsAsync(string programId, string realm)
79
        {
80
            var filters = new List<MemCmp>
×
81
            {
×
82
                new MemCmp{ Bytes = Encoders.Base58.EncodeData(new byte[]{ (byte)GovernanceAccountType.MintGovernance }), Offset = GovernanceProgramAccount.Layout.AccountTypeOffset },
×
83
                new MemCmp{ Bytes = realm, Offset = GovernanceAccount.ExtraLayout.RealmOffset }
×
84
            };
×
85
            return await GetProgramAccounts<GovernanceAccount>(programId, filters);
×
86
        }
×
87

88
        /// <summary>
89
        /// Gets all <see cref="GovernanceAccount"/>s of the type <see cref="GovernanceAccountType.MintGovernance"/> for the given program id.
90
        /// </summary>
91
        /// <param name="programId">The deployed governance program id.</param>
92
        /// <param name="realm">The realm the governances belong to.</param>
93
        /// <returns>The list of program accounts and their decoded structures.</returns>
94
        public ProgramAccountsResultWrapper<List<GovernanceAccount>> GetMintGovernanceAccounts(string programId, string realm) => GetMintGovernanceAccountsAsync(programId, realm).Result;
×
95

96

97
        /// <summary>
98
        /// Gets all <see cref="GovernanceAccount"/>s of the type <see cref="GovernanceAccountType.ProgramGovernance"/> for the given program id. This is an asynchronous operation.
99
        /// </summary>
100
        /// <param name="programId">The deployed governance program id.</param>
101
        /// <param name="realm">The realm the governances belong to.</param>
102
        /// <returns>A task which may return the list of program accounts and their decoded structures.</returns>
103
        public async Task<ProgramAccountsResultWrapper<List<GovernanceAccount>>> GetProgramGovernanceAccountsAsync(string programId, string realm)
104
        {
105
            var filters = new List<MemCmp>
×
106
            {
×
107
                new MemCmp{ Bytes = Encoders.Base58.EncodeData(new byte[]{ (byte)GovernanceAccountType.ProgramGovernance }), Offset = GovernanceProgramAccount.Layout.AccountTypeOffset },
×
108
                new MemCmp{ Bytes = realm, Offset = GovernanceAccount.ExtraLayout.RealmOffset }
×
109
            };
×
110
            return await GetProgramAccounts<GovernanceAccount>(programId, filters);
×
111
        }
×
112

113
        /// <summary>
114
        /// Gets all <see cref="GovernanceAccount"/>s of the type <see cref="GovernanceAccountType.ProgramGovernance"/> for the given program id.
115
        /// </summary>
116
        /// <param name="programId">The deployed governance program id.</param>
117
        /// <param name="realm">The realm the governances belong to.</param>
118
        /// <returns>The list of program accounts and their decoded structures.</returns>
119
        public ProgramAccountsResultWrapper<List<GovernanceAccount>> GetProgramGovernanceAccounts(string programId, string realm) => GetProgramGovernanceAccountsAsync(programId, realm).Result;
×
120

121

122
        /// <summary>
123
        /// Gets all <see cref="GovernanceAccount"/>s of the type <see cref="GovernanceAccountType.TokenGovernance"/> for the given program id. This is an asynchronous operation.
124
        /// </summary>
125
        /// <param name="programId">The deployed governance program id.</param>
126
        /// <param name="realm">The realm the governances belong to.</param>
127
        /// <returns>A task which may return the list of program accounts and their decoded structures.</returns>
128
        public async Task<ProgramAccountsResultWrapper<List<GovernanceAccount>>> GetTokenGovernanceAccountsAsync(string programId, string realm)
129
        {
130
            var filters = new List<MemCmp>
×
131
            {
×
132
                new MemCmp{ Bytes = Encoders.Base58.EncodeData(new byte[]{ (byte)GovernanceAccountType.TokenGovernance }), Offset = GovernanceProgramAccount.Layout.AccountTypeOffset },
×
133
                new MemCmp{ Bytes = realm, Offset = GovernanceAccount.ExtraLayout.RealmOffset }
×
134
            };
×
135
            return await GetProgramAccounts<GovernanceAccount>(programId, filters);
×
136
        }
×
137

138
        /// <summary>
139
        /// Gets all <see cref="GovernanceAccount"/>s of the type <see cref="GovernanceAccountType.TokenGovernance"/> for the given program id.
140
        /// </summary>
141
        /// <param name="programId">The deployed governance program id.</param>
142
        /// <param name="realm">The realm the governances belong to.</param>
143
        /// <returns>The list of program accounts and their decoded structures.</returns>
144
        public ProgramAccountsResultWrapper<List<GovernanceAccount>> GetTokenGovernanceAccounts(string programId, string realm) => GetTokenGovernanceAccountsAsync(programId, realm).Result;
×
145

146

147
        /// <summary>
148
        /// Gets all <see cref="GovernanceAccount"/>s of the type <see cref="GovernanceAccountType.AccountGovernance"/> for the given program id. This is an asynchronous operation.
149
        /// </summary>
150
        /// <param name="programId">The deployed governance program id.</param>
151
        /// <param name="realm">The realm the governances belong to.</param>
152
        /// <returns>A task which may return the list of program accounts and their decoded structures.</returns>
153
        public async Task<ProgramAccountsResultWrapper<List<GovernanceAccount>>> GetGenericGovernanceAccountsAsync(string programId, string realm)
154
        {
155
            var filters = new List<MemCmp>
×
156
            {
×
157
                new MemCmp{ Bytes = Encoders.Base58.EncodeData(new byte[]{ (byte)GovernanceAccountType.AccountGovernance }), Offset = GovernanceProgramAccount.Layout.AccountTypeOffset },
×
158
                new MemCmp{ Bytes = realm, Offset = GovernanceAccount.ExtraLayout.RealmOffset }
×
159
            };
×
160
            return await GetProgramAccounts<GovernanceAccount>(programId, filters);
×
161
        }
×
162

163
        /// <summary>
164
        /// Gets all <see cref="GovernanceAccount"/>s of the type <see cref="GovernanceAccountType.AccountGovernance"/> for the given program id.
165
        /// </summary>
166
        /// <param name="programId">The deployed governance program id.</param>
167
        /// <param name="realm">The realm the governances belong to.</param>
168
        /// <returns>The list of program accounts and their decoded structures.</returns>
169
        public ProgramAccountsResultWrapper<List<GovernanceAccount>> GetGenericGovernanceAccounts(string programId, string realm) => GetGenericGovernanceAccountsAsync(programId, realm).Result;
×
170

171
        /// <summary>
172
        /// Gets all <see cref="TokenOwnerRecord"/>s of the given owner for the given program id. This is an asynchronous operation.
173
        /// </summary>
174
        /// <param name="programId">The deployed governance program id.</param>
175
        /// <param name="realm">The realm the governances belong to.</param>
176
        /// <param name="owner">The owner of the token owner records.</param>
177
        /// <returns>A task which may return the list of program accounts and their decoded structures.</returns>
178
        public async Task<ProgramAccountsResultWrapper<List<TokenOwnerRecord>>> GetTokenOwnerRecordsAsync(string programId, string realm, string owner)
179
        {
180
            var filters = new List<MemCmp>
×
181
            {
×
182
                new MemCmp{ Bytes = Encoders.Base58.EncodeData(new byte[]{ (byte)GovernanceAccountType.TokenOwnerRecord }), Offset = GovernanceProgramAccount.Layout.AccountTypeOffset },
×
183
                new MemCmp{ Bytes = realm, Offset = TokenOwnerRecord.ExtraLayout.RealmOffset },
×
184
                new MemCmp{ Bytes = owner, Offset = TokenOwnerRecord.ExtraLayout.GoverningTokenOwnerOffset }
×
185
            };
×
186
            return await GetProgramAccounts<TokenOwnerRecord>(programId, filters);
×
187
        }
×
188

189
        /// <summary>
190
        /// Gets all <see cref="TokenOwnerRecord"/>s of the given owner for the given program id.
191
        /// </summary>
192
        /// <param name="programId">The deployed governance program id.</param>
193
        /// <param name="realm">The realm the governances belong to.</param>
194
        /// <param name="owner">The owner of the token owner records.</param>
195
        /// <returns>The list of program accounts and their decoded structures.</returns>
196
        public ProgramAccountsResultWrapper<List<TokenOwnerRecord>> GetTokenOwnerRecords(string programId, string realm, string owner) => GetTokenOwnerRecordsAsync(programId, realm, owner).Result;
×
197

198
        /// <summary>
199
        /// Gets all <see cref="ProposalV1"/>s of the giuven governance for the given program id. This is an asynchronous operation.
200
        /// </summary>
201
        /// <param name="programId">The deployed governance program id.</param>
202
        /// <param name="governance">The governance the proposals belong to.</param>
203
        /// <returns>A task which may return the list of program accounts and their decoded structures.</returns>
204
        public async Task<ProgramAccountsResultWrapper<List<ProposalV1>>> GetProposalsV1Async(string programId, string governance)
205
        {
206
            var filters = new List<MemCmp>
×
207
            {
×
208
                new MemCmp{ Bytes = Encoders.Base58.EncodeData(new byte[]{ (byte)GovernanceAccountType.ProposalV1 }), Offset = GovernanceProgramAccount.Layout.AccountTypeOffset },
×
209
                new MemCmp{ Bytes = governance, Offset = ProposalV2.ExtraLayout.GovernanceOffset },
×
210
            };
×
211
            return await GetProgramAccounts<ProposalV1>(programId, filters);
×
212
        }
×
213

214
        /// <summary>
215
        /// Gets all <see cref="ProposalV1"/>s of the giuven governance for the given program id.
216
        /// </summary>
217
        /// <param name="programId">The deployed governance program id.</param>
218
        /// <param name="governance">The governance the proposals belong to.</param>
219
        /// <returns>The list of program accounts and their decoded structures.</returns>
220
        public ProgramAccountsResultWrapper<List<ProposalV1>> GetProposalsV1(string programId, string governance) => GetProposalsV1Async(programId, governance).Result;
×
221

222
        /// <summary>
223
        /// Gets all <see cref="ProposalV2"/>s of the giuven governance for the given program id. This is an asynchronous operation.
224
        /// </summary>
225
        /// <param name="programId">The deployed governance program id.</param>
226
        /// <param name="governance">The governance the proposals belong to.</param>
227
        /// <returns>A task which may return the list of program accounts and their decoded structures.</returns>
228
        public async Task<ProgramAccountsResultWrapper<List<ProposalV2>>> GetProposalsV2Async(string programId, string governance)
229
        {
230
            var filters = new List<MemCmp>
×
231
            {
×
232
                new MemCmp{ Bytes = Encoders.Base58.EncodeData(new byte[]{ (byte)GovernanceAccountType.ProposalV1 }), Offset = GovernanceProgramAccount.Layout.AccountTypeOffset },
×
233
                new MemCmp{ Bytes = governance, Offset = ProposalV2.ExtraLayout.GovernanceOffset },
×
234
            };
×
235
            return await GetProgramAccounts<ProposalV2>(programId, filters);
×
236
        }
×
237

238
        /// <summary>
239
        /// Gets all <see cref="ProposalV2"/>s of the giuven governance for the given program id.
240
        /// </summary>
241
        /// <param name="programId">The deployed governance program id.</param>
242
        /// <param name="governance">The governance the proposals belong to.</param>
243
        /// <returns>The list of program accounts and their decoded structures.</returns>
244
        public ProgramAccountsResultWrapper<List<ProposalV2>> GetProposalsV2(string programId, string governance) => GetProposalsV2Async(programId, governance).Result;
×
245

246
    }
247
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc