• 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/Realm.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 Realm Account
14
    /// Account PDA seeds" ['governance', name]
15
    /// </summary>
16
    public class Realm : GovernanceProgramAccount
17
    {
18
        /// <summary>
19
        /// The layout of the <see cref="Governance"/> structure.
20
        /// </summary>
21
        public static class ExtraLayout
22
        {
23
            /// <summary>
24
            /// The offset at which the community mint public key begins.
25
            /// </summary>
26
            public const int CommunityMintOffset = 1;
27

28
            /// <summary>
29
            /// The offset at which the <see cref="RealmConfig"/> structure begins.
30
            /// </summary>
31
            public const int ConfigOffset = 33;
32

33
            /// <summary>
34
            /// The offset at which the authority public key begins.
35
            /// </summary>
36
            public const int AuthorityOffset = 99;
37

38
            /// <summary>
39
            /// The offset at which the name string begins.
40
            /// </summary>
41
            public const int NameOffset = 132;
42
        }
43

44
        /// <summary>
45
        /// Community mint
46
        /// </summary>
47
        public PublicKey CommunityMint;
48

49
        /// <summary>
50
        /// Configuration of the Realm
51
        /// </summary>
52
        public RealmConfig Config;
53

54
        /// <summary>
55
        /// Realm authority. The authority must sign transactions which update the realm config
56
        /// The authority can be transferer to Realm Governance and hence make the Realm self governed through proposals
57
        /// </summary>
58
        public PublicKey Authority;
59

60
        /// <summary>
61
        /// Governance Realm name
62
        /// </summary>
63
        public string Name;
64

65
        /// <summary>
66
        /// Deserialize the data into the <see cref="Realm"/> structure.
67
        /// </summary>
68
        /// <param name="data">The data to deserialize.</param>
69
        /// <returns>The <see cref="Realm"/> structure.</returns>
70
        public static Realm Deserialize(byte[] data)
71
        {
72
            ReadOnlySpan<byte> span = data.AsSpan();
×
73

74
            RealmConfig config = RealmConfig.Deserialize(span.GetSpan(ExtraLayout.ConfigOffset, RealmConfig.Layout.Length));
×
75
            PublicKey authority = null;
×
76
            bool authorityExists;
77
            string realmName;
78

79
            // council mint public key exists in realm config structure
80
            if (config.CouncilMint != null)
×
81
            {
82
                int nameOffset = ExtraLayout.NameOffset;
×
83
                authorityExists = span.GetBool(ExtraLayout.AuthorityOffset);
×
84
                if (authorityExists)
×
85
                {
86
                    authority = span.GetPubKey(ExtraLayout.AuthorityOffset + 1);
×
87
                }
88
                else
89
                {
90
                    nameOffset -= PublicKey.PublicKeyLength;
×
91
                }
92

NEW
93
                _ = span.GetBorshString(nameOffset, out realmName);
×
94
            }
95
            else
96
            {
97
                // council mint public key does not exist in realm config structure so offsets differ from static values
98
                int nameOffset = ExtraLayout.NameOffset;
×
99
                authorityExists = span.GetBool(ExtraLayout.AuthorityOffset - (PublicKey.PublicKeyLength));
×
100
                if (authorityExists)
×
101
                {
102
                    authority = span.GetPubKey(ExtraLayout.AuthorityOffset + 1 - (PublicKey.PublicKeyLength));
×
103
                    nameOffset -= PublicKey.PublicKeyLength;
×
104
                }
105
                else
106
                {
107
                    nameOffset -= (2 * PublicKey.PublicKeyLength);
×
108
                }
109

NEW
110
                _ = span.GetBorshString(nameOffset, out realmName);
×
111
            }
112

113
            return new Realm
×
114
            {
×
115
                AccountType = (GovernanceAccountType)Enum.Parse(typeof(GovernanceAccountType), span.GetU8(Layout.AccountTypeOffset).ToString()), 
×
116
                CommunityMint = span.GetPubKey(ExtraLayout.CommunityMintOffset),
×
117
                Config = config,
×
118
                Authority = authorityExists ? authority : null,
×
119
                Name = realmName
×
120
            };
×
121
        }
122
    }
123
}
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