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

bmresearch / Solnet / 15456731198

05 Jun 2025 02:04AM UTC coverage: 66.052% (-4.7%) from 70.792%
15456731198

Pull #497

github

web-flow
Merge e0afe0e16 into 632c6bef2
Pull Request #497: Stakepool program

1161 of 2022 branches covered (57.42%)

Branch coverage included in aggregate %.

704 of 1521 new or added lines in 12 files covered. (46.29%)

5822 of 8550 relevant lines covered (68.09%)

987890.56 hits per line

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

5.88
/src/Solnet.Programs/StakePool/Models/ValidatorList.cs
1
using Solnet.Wallet;
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7

8
namespace Solnet.Programs.StakePool.Models
9
{
10
    /// <summary>
11
    /// Storage list for all validator stake accounts in the pool.
12
    /// </summary>
13
    public class ValidatorList
14
    {
15
        /// <summary>
16
        /// Data outside of the validator list, separated out for cheaper deserializations.
17
        /// </summary>
NEW
18
        public ValidatorListHeader Header { get; set; }
×
19

20
        /// <summary>
21
        /// List of stake info for each validator in the pool.
22
        /// </summary>
23
        public List<ValidatorStakeInfo> Validators { get; set; }
11✔
24

25
        /// <summary>
26
        /// Creates an empty instance containing space for <paramref name="maxValidators"/> validators.
27
        /// </summary>
28
        /// <param name="maxValidators">Maximum number of validators.</param>
29
        /// <returns>A new instance of <see cref="ValidatorList"/>.</returns>
30
        public static ValidatorList New(uint maxValidators)
31
        {
NEW
32
            return new ValidatorList
×
NEW
33
            {
×
NEW
34
                Header = new ValidatorListHeader
×
NEW
35
                {
×
NEW
36
                    AccountType = AccountType.ValidatorList,
×
NEW
37
                    MaxValidators = maxValidators
×
NEW
38
                },
×
NEW
39
                Validators = Enumerable.Repeat(new ValidatorStakeInfo(), (int)maxValidators).ToList()
×
NEW
40
            };
×
41
        }
42

43
        /// <summary>
44
        /// Calculate the number of validator entries that fit in the provided buffer length.
45
        /// Assumes that <see cref="ValidatorListHeader"/> defines a constant <c>LEN</c> for header length.
46
        /// </summary>
47
        /// <param name="bufferLength">The total buffer length.</param>
48
        /// <returns>The maximum number of validator entries.</returns>
49
        public static int CalculateMaxValidators(int bufferLength)
50
        {
51
            // Add 4 additional bytes to the serialized header length (as in the original Rust code).
NEW
52
            int headerSize = (new ValidatorListHeader()).GetSerializedLength() + 4;
×
NEW
53
            return (bufferLength - headerSize) / ValidatorStakeInfo.Length;
×
54
        }
55

56
        /// <summary>
57
        /// Checks if the list contains a validator with the given vote account address.
58
        /// </summary>
59
        /// <param name="voteAccountAddress">The vote account public key.</param>
60
        /// <returns><c>true</c> if found; otherwise, <c>false</c>.</returns>
61
        public bool Contains(PublicKey voteAccountAddress)
62
        {
NEW
63
            return Validators.Any(x => x.VoteAccountAddress.Equals(voteAccountAddress));
×
64
        }
65

66
        /// <summary>
67
        /// Finds a mutable reference to the <see cref="ValidatorStakeInfo"/> with the given vote account address.
68
        /// </summary>
69
        /// <param name="voteAccountAddress">The vote account public key.</param>
70
        /// <returns>
71
        /// A reference to the matching <see cref="ValidatorStakeInfo"/> if found; otherwise, <c>null</c>.
72
        /// </returns>
73
        public ValidatorStakeInfo FindMut(PublicKey voteAccountAddress)
74
        {
NEW
75
            return Validators.FirstOrDefault(x => x.VoteAccountAddress.Equals(voteAccountAddress));
×
76
        }
77

78
        /// <summary>
79
        /// Finds an immutable reference to the <see cref="ValidatorStakeInfo"/> with the given vote account address.
80
        /// </summary>
81
        /// <param name="voteAccountAddress">The vote account public key.</param>
82
        /// <returns>
83
        /// A reference to the matching <see cref="ValidatorStakeInfo"/> if found; otherwise, <c>null</c>.
84
        /// </returns>
85
        public ValidatorStakeInfo Find(PublicKey voteAccountAddress)
86
        {
NEW
87
            return Validators.FirstOrDefault(x => x.VoteAccountAddress.Equals(voteAccountAddress));
×
88
        }
89

90
        /// <summary>
91
        /// Checks if the list contains any validator with active stake.
92
        /// </summary>
93
        /// <returns><c>true</c> if any validator's active stake lamports are greater than zero; otherwise, <c>false</c>.</returns>
94
        public bool HasActiveStake()
95
        {
NEW
96
            return Validators.Any(x => x.ActiveStakeLamports > 0);
×
97
        }
98
    }
99
}
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