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

bmresearch / Solnet / 13116309488

03 Feb 2025 02:58PM UTC coverage: 71.215%. Remained the same
13116309488

push

github

BifrostTitan
Update Governance & AddressLookupTable program comments

Warning cleanup from latest PRs

1113 of 1754 branches covered (63.45%)

Branch coverage included in aggregate %.

5114 of 6990 relevant lines covered (73.16%)

1208320.57 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"></param>
26
        /// <param name="governanceProgramID"></param>
27
        public GovernanceClient(IRpcClient rpcClient, PublicKey governanceProgramID) : base(rpcClient, null, governanceProgramID) { }
×
28

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

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

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

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

72

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

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

97

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

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

122

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

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

147

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

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

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

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

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

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

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

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

247
    }
248
}
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