• 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/Models/ProposalV2.cs
1
using Solnet.Programs.Governance.Enums;
2
using Solnet.Programs.Utilities;
3
using Solnet.Wallet;
4
using System;
5
using System.Collections.Generic;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9

10
namespace Solnet.Programs.Governance.Models
11
{
12
    /// <summary>
13
    /// Governance Proposal v2
14
    /// </summary>
15
    public class ProposalV2 : Proposal
16
    {
17
        /// <summary>
18
        /// Additional layout info for <see cref="ProposalV2"/>.
19
        /// </summary>
20
        public static class AdditionalLayout
21
        {
22
            /// <summary>
23
            /// The offset at which the vote type enum begins.
24
            /// </summary>
25
            public const int VoteTypeOffset = 100;
26
        }
27

28
        /// <summary>
29
        /// Vote type
30
        /// </summary>
31
        public VoteType VoteType;
32

33
        /// <summary>
34
        /// The number of max options in case <c>VoteType</c> is <see cref="VoteType.MultiChoice"/>.
35
        /// </summary>
36
        public ushort MultiChoiceMaxOptions;
37

38
        /// <summary>
39
        /// Proposal options
40
        /// </summary>
41
        public List<ProposalOption> Options;
42

43
        /// <summary>
44
        /// The weight of the Proposal rejection votes
45
        /// If the proposal has no deny option then the weight is None
46
        /// Only proposals with the deny option can have executable instructions attached to them
47
        /// Without the deny option a proposal is only non executable survey
48
        /// </summary>
49
        public ulong DenyVoteWeight;
50

51
        /// <summary>
52
        /// Deserialize the data into the <see cref="Proposal"/> structure.
53
        /// </summary>
54
        /// <param name="data">The data to deserialize.</param>
55
        /// <returns>The <see cref="Proposal"/>.</returns>
56
        public static ProposalV2 Deserialize(byte[] data)
57
        {
58
            ReadOnlySpan<byte> span = data.AsSpan();
×
59

60
            int offset = AdditionalLayout.VoteTypeOffset;
×
61
            VoteType voteType = (VoteType)Enum.Parse(typeof(VoteType), span.GetU8(offset).ToString());
×
62
            ushort multiChoiceMaxOpts = 0;
×
63

64
            if(voteType == VoteType.MultiChoice)
×
65
            {
66
                multiChoiceMaxOpts = span.GetU16(offset + 1);
×
67
            }
68

69
            // adjust offset, increase by 3 in case vote type is multi choice and 1 in case it is single choice
70
            offset += voteType == VoteType.MultiChoice ? 3 : 1;
×
71
            List<ProposalOption> proposalOptions = new();
×
72
            int numProposalOptions = (int)span.GetU32(offset);
×
73
            offset += sizeof(uint);
×
74

75
            for(int i = 0; i<numProposalOptions; i++)
×
76
            {
77
                ProposalOption proposalOption = ProposalOption.Deserialize(span.Slice(offset));
×
78
                proposalOptions.Add(proposalOption);
×
79
                // adjust offset by taking into account the proposal option's label length and the remainder of the structure
80
                offset += proposalOption.LabelLength + ProposalOption.Layout.LengthWithoutLabel;
×
81
            }
82
            
83
            // the following data is predominantly optional so we'll have to check if it exists and adjust offsets accordingly
84
            bool denyVoteWeightExists = span.GetBool(offset);
×
85
            ulong denyVoteWeight = 0;
×
86
            offset += sizeof(byte);
×
87
            if (denyVoteWeightExists)
×
88
            {
89
                denyVoteWeight = span.GetU64(offset);
×
90
                offset += sizeof(ulong);
×
91
            }
92

93
            ulong draftAtTimestamp = span.GetU64(offset);
×
94
            offset += sizeof(ulong);
×
95

96
            bool signingOffAtTimestampExists = span.GetBool(offset);
×
97
            ulong signingOffAtTimestamp = 0;
×
98
            offset += sizeof(byte);
×
99
            if (signingOffAtTimestampExists)
×
100
            {
101
                signingOffAtTimestamp = span.GetU64(offset);
×
102
                offset += sizeof(ulong);
×
103
            }
104

105
            bool votingAtTimestampExists = span.GetBool(offset);
×
106
            ulong votingAtTimestamp = 0;
×
107
            offset += sizeof(byte);
×
108
            if (votingAtTimestampExists)
×
109
            {
110
                votingAtTimestamp = span.GetU64(offset);
×
111
                offset += sizeof(ulong);
×
112
            }
113

114
            bool votingAtSlotExists = span.GetBool(offset);
×
115
            ulong votingAtSlot = 0;
×
116
            offset += sizeof(byte);
×
117
            if (votingAtSlotExists)
×
118
            {
119
                votingAtSlot = span.GetU64(offset);
×
120
                offset += sizeof(ulong);
×
121
            }
122

123
            bool votingCompletedAtTimestampExists = span.GetBool(offset);
×
124
            ulong votingCompletedAtTimestamp = 0;
×
125
            offset += sizeof(byte);
×
126
            if (votingCompletedAtTimestampExists)
×
127
            {
128
                votingCompletedAtTimestamp = span.GetU64(offset);
×
129
                offset += sizeof(ulong);
×
130
            }
131

132
            bool executingAtTimestampExists = span.GetBool(offset);
×
133
            ulong executingAtTimestamp = 0;
×
134
            offset += sizeof(byte);
×
135
            if (executingAtTimestampExists)
×
136
            {
137
                executingAtTimestamp = span.GetU64(offset);
×
138
                offset += sizeof(ulong);
×
139
            }
140

141
            bool closedAtTimestampExists = span.GetBool(offset);
×
142
            ulong closedAtTimestamp = 0;
×
143
            offset += sizeof(byte);
×
144
            if (closedAtTimestampExists)
×
145
            {
146
                closedAtTimestamp = span.GetU64(offset);
×
147
                offset += sizeof(ulong);
×
148
            }
149

150
            InstructionExecutionFlags ixExecutionFlags = (InstructionExecutionFlags)Enum.Parse(typeof(InstructionExecutionFlags), span.GetU8(offset).ToString());
×
151
            offset += sizeof(byte);
×
152

153
            bool maxVoteWeightExists = span.GetBool(offset);
×
154
            ulong maxVoteWeight = 0;
×
155
            offset += sizeof(byte);
×
156
            if (maxVoteWeightExists)
×
157
            {
158
                maxVoteWeight = span.GetU64(offset);
×
159
                offset += sizeof(ulong);
×
160
            }
161

162
            bool voteThresholdPercentageTypeExists = span.GetBool(offset);
×
163
            VoteThresholdPercentage voteThresholdPercentageType = Enums.VoteThresholdPercentage.YesVote;
×
164
            byte voteThresholdPercentage = 0;
×
165
            offset += sizeof(byte);
×
166
            if (voteThresholdPercentageTypeExists)
×
167
            {
168
                voteThresholdPercentageType = (VoteThresholdPercentage)Enum.Parse(typeof(VoteThresholdPercentage), span.GetU8(offset).ToString());
×
169
                offset += sizeof(byte);
×
170
                voteThresholdPercentage = span.GetU8(offset);
×
171
                offset += sizeof(byte);
×
172
            }
173

NEW
174
            int nameLength = span.GetBorshString(offset, out string name);
×
NEW
175
            _ = span.GetBorshString(offset + nameLength, out string descriptionLink);
×
176

177
            return new ProposalV2
×
178
            {
×
179
                AccountType = (GovernanceAccountType)Enum.Parse(typeof(GovernanceAccountType), span.GetU8(Layout.AccountTypeOffset).ToString()),
×
180
                Governance = span.GetPubKey(ExtraLayout.GovernanceOffset),
×
181
                GoverningTokenMint = span.GetPubKey(ExtraLayout.GoverningTokenMintOffset),
×
182
                State = (ProposalState)Enum.Parse(typeof(ProposalState), span.GetU8(ExtraLayout.StateOffset).ToString()),
×
183
                TokenOwnerRecord = span.GetPubKey(ExtraLayout.TokenOwnerRecordOffset),
×
184
                SignatoriesCount = span.GetU8(ExtraLayout.SignatoriesOffset),
×
185
                SignatoriesSignedOffCount = span.GetU8(ExtraLayout.SignatoriesSignedOffOffset),
×
186
                VoteType = voteType,
×
187
                MultiChoiceMaxOptions = multiChoiceMaxOpts,
×
188
                Options = proposalOptions,
×
189
                DenyVoteWeight = denyVoteWeight,
×
190
                DraftAt = draftAtTimestamp,
×
191
                SigningOffAt = signingOffAtTimestamp,
×
192
                VotingAt = votingAtTimestamp,
×
193
                VotingAtSlot = votingAtSlot,
×
194
                VotingCompletedAt = votingCompletedAtTimestamp,
×
195
                ExecutingAt = executingAtTimestamp,
×
196
                ClosedAt = closedAtTimestamp,
×
197
                InstructionExecutionFlags = ixExecutionFlags,
×
198
                MaxVoteWeight = maxVoteWeight,
×
199
                VoteThresholdPercentageType = voteThresholdPercentageType,
×
200
                VoteThresholdPercentage = voteThresholdPercentage,
×
201
                Name = name,
×
202
                DescriptionLink = descriptionLink
×
203
            };
×
204
        }
205
    }
206
}
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

© 2026 Coveralls, Inc