Skip to content

Commit 1e0981a

Browse files
committed
Updated Governance program -- Example uses legacy mango markets DAO
1 parent 3c3d7f5 commit 1e0981a

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

src/Solnet.Examples/GovernanceProgramExamples.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public class GovernanceProgramExamples : IExample
1616

1717
public GovernanceProgramExamples()
1818
{
19-
governanceClient = new GovernanceClient(mRpcClient, GovernanceProgram.MainNetProgramIdKey);
19+
governanceClient = new GovernanceClient(mRpcClient, GovernanceProgram.MangoGovernanceProgramIdKey);
2020
}
2121

2222
public void Run()
2323
{
24-
var realms = governanceClient.GetRealms();
24+
var realms = governanceClient.GetRealms(GovernanceProgram.MangoGovernanceProgramIdKey);
2525

2626
for(int i = 0; i < realms.ParsedResult.Count; i++)
2727
{
@@ -32,18 +32,18 @@ public void Run()
3232
$"Council Mint: {realms.ParsedResult[i].Config?.CouncilMint}\n" +
3333
$"Vote Weight Source: {realms.ParsedResult[i].Config.CommunityMintMaxVoteWeightSource}\n");
3434

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);
35+
var progGovernances = governanceClient.GetProgramGovernanceAccounts(realms.OriginalRequest.Result[i].PublicKey, realms.ParsedResult[i].Name);
36+
var mintGovernances = governanceClient.GetMintGovernanceAccounts(GovernanceProgram.MangoGovernanceProgramIdKey, realms.OriginalRequest.Result[i].PublicKey);
37+
var tokenGovernances = governanceClient.GetTokenGovernanceAccounts(GovernanceProgram.MangoGovernanceProgramIdKey, realms.OriginalRequest.Result[i].PublicKey);
38+
var genericGovernances = governanceClient.GetGenericGovernanceAccounts(GovernanceProgram.MangoGovernanceProgramIdKey, realms.OriginalRequest.Result[i].PublicKey);
3939
Console.WriteLine($"Program Governance Accounts: {progGovernances.ParsedResult?.Count}\n" +
4040
$"Mint Governance Accounts: {mintGovernances.ParsedResult?.Count}\n" +
4141
$"Token Governance Accounts: {tokenGovernances.ParsedResult?.Count}\n" +
4242
$"Generic Governance Accounts: {genericGovernances.ParsedResult?.Count}\n");
4343

4444
for(int j = 0; j < progGovernances.ParsedResult?.Count; j++)
4545
{
46-
var proposals = governanceClient.GetProposalsV1(progGovernances.OriginalRequest.Result[j].PublicKey);
46+
var proposals = governanceClient.GetProposalsV1(GovernanceProgram.MangoGovernanceProgramIdKey, progGovernances.OriginalRequest.Result[j].PublicKey);
4747
Console.WriteLine($"Program Governance: {progGovernances.OriginalRequest.Result[j].PublicKey}\n" +
4848
$"Proposals: {proposals.OriginalRequest.Result.Count}");
4949
for(int k = 0; k < proposals.ParsedResult?.Count; k++)

src/Solnet.Programs/Governance/GovernanceClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class GovernanceClient : BaseClient
2323
/// Initialize the governance client.
2424
/// </summary>
2525
/// <param name="rpcClient">An <see cref="IRpcClient"/> instance.</param>
26-
public GovernanceClient(IRpcClient rpcClient) : base(rpcClient, null) { }
26+
public GovernanceClient(IRpcClient rpcClient, PublicKey governanceProgramID) : base(rpcClient, null, governanceProgramID) { }
2727

2828
/// <summary>
2929
/// Gets all <see cref="Realm"/>s for the given program id. This is an asynchronous operation.

src/Solnet.Programs/Governance/GovernanceProgram.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,11 @@ private void WithVoterWeightAccounts(List<AccountMeta> accounts, PublicKey realm
562562
/// <returns>The public key of the realm config.</returns>
563563
public static PublicKey GetRealmConfigAddress(PublicKey programId, PublicKey realm)
564564
{
565-
bool success = AddressExtensions.TryFindProgramAddress(
565+
bool success = PublicKey.TryFindProgramAddress(
566566
new List<byte[]> { Encoding.UTF8.GetBytes(RealmConfigSeed), realm },
567-
programId, out byte[] realmConfigAddressBytes, out _);
567+
programId, out PublicKey realmConfigAddressBytes, out _);
568568

569-
return success ? new PublicKey(realmConfigAddressBytes) : null;
569+
return success ? realmConfigAddressBytes : null;
570570
}
571571

572572
}

src/Solnet.Programs/Governance/Models/ProposalOption.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static class Layout
7171
/// <returns>The <see cref="ProposalOption"/> structure.</returns>
7272
public static ProposalOption Deserialize(ReadOnlySpan<byte> data)
7373
{
74-
int labelLength = data.GetString(Layout.LabelOffset, out string label);
74+
int labelLength = data.GetBorshString(Layout.LabelOffset, out string label);
7575

7676
return new ProposalOption
7777
{

src/Solnet.Programs/Governance/Models/ProposalV1.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ public static ProposalV1 Deserialize(byte[] data)
162162
offset += sizeof(byte);
163163
}
164164

165-
int nameLength = span.GetString(offset, out string name);
166-
_ = span.GetString(offset + nameLength, out string descriptionLink);
165+
int nameLength = span.GetBorshString(offset, out string name);
166+
_ = span.GetBorshString(offset + nameLength, out string descriptionLink);
167167

168168
return new ProposalV1
169169
{

src/Solnet.Programs/Governance/Models/ProposalV2.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ public static ProposalV2 Deserialize(byte[] data)
171171
offset += sizeof(byte);
172172
}
173173

174-
int nameLength = span.GetString(offset, out string name);
175-
_ = span.GetString(offset + nameLength, out string descriptionLink);
174+
int nameLength = span.GetBorshString(offset, out string name);
175+
_ = span.GetBorshString(offset + nameLength, out string descriptionLink);
176176

177177
return new ProposalV2
178178
{

src/Solnet.Programs/Governance/Models/Realm.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static Realm Deserialize(byte[] data)
9090
nameOffset -= PublicKey.PublicKeyLength;
9191
}
9292

93-
_ = span.GetString(nameOffset, out realmName);
93+
_ = span.GetBorshString(nameOffset, out realmName);
9494
}
9595
else
9696
{
@@ -107,7 +107,7 @@ public static Realm Deserialize(byte[] data)
107107
nameOffset -= (2 * PublicKey.PublicKeyLength);
108108
}
109109

110-
_ = span.GetString(nameOffset, out realmName);
110+
_ = span.GetBorshString(nameOffset, out realmName);
111111
}
112112

113113
return new Realm

0 commit comments

Comments
 (0)