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

bmresearch / Solnet / 15458437619

05 Jun 2025 04:27AM UTC coverage: 66.061% (-4.7%) from 70.792%
15458437619

Pull #497

github

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

1161 of 2022 branches covered (57.42%)

Branch coverage included in aggregate %.

705 of 1521 new or added lines in 12 files covered. (46.35%)

5823 of 8550 relevant lines covered (68.11%)

987890.44 hits per line

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

0.0
/src/Solnet.Programs/StakePool/Models/FutureEpoch.cs
1
using System;
2

3
namespace Solnet.Programs.StakePool.Models
4
{
5
    /// <summary>
6
    /// Wrapper type that "counts down" epochs, similar to Rust's Option, with three states.
7
    /// </summary>
8
    /// <typeparam name="T">The type of the value being wrapped.</typeparam>
9
    public abstract class FutureEpoch<T>
10
    {
NEW
11
        private FutureEpoch() { }
×
12

13
        /// <summary>
14
        /// Represents the None state (no value set).
15
        /// </summary>
16
        public sealed class None : FutureEpoch<T>
17
        {
NEW
18
            internal None() { }
×
19
        }
20

21
        /// <summary>
22
        /// Value is ready after the next epoch boundary.
23
        /// </summary>
24
        public sealed class One : FutureEpoch<T>
25
        {
26
            /// <summary>
27
            /// Gets the value stored in the current instance.
28
            /// </summary>
NEW
29
            public T Value { get; }
×
30
            /// <summary>
31
            /// Initializes a new instance of the <see cref="One{T}"/> class with the specified value.
32
            /// </summary>
33
            /// <param name="value">The value to be assigned to the instance.</param>
NEW
34
            public One(T value) => Value = value;
×
35
        }
36

37
        /// <summary>
38
        /// Value is ready after two epoch boundaries.
39
        /// </summary>
40
        public sealed class Two : FutureEpoch<T>
41
        {
42
            /// <summary>
43
            /// Gets the value stored in the current instance.
44
            /// </summary>
NEW
45
            public T Value { get; }
×
46
            /// <summary>
47
            /// Initializes a new instance of the <see cref="FutureEpoch{T}.Two"/> class with the specified value.
48
            /// </summary>
49
            /// <param name="value">The value to initialize the instance with.</param>
NEW
50
            public Two(T value) => Value = value;
×
51
        }
52

53
        /// <summary>
54
        /// Create a new value to be unlocked in two epochs.
55
        /// </summary>
NEW
56
        public static FutureEpoch<T> New(T value) => new Two(value);
×
57

58
        /// <summary>
59
        /// Returns the value if it's ready (i.e., in the One state), otherwise null.
60
        /// </summary>
61
        public T? Get()
62
        {
NEW
63
            return this is One one ? one.Value : default;
×
64
        }
65

66
        /// <summary>
67
        /// Update the epoch, to be done after getting the underlying value.
68
        /// </summary>
69
        public FutureEpoch<T> UpdateEpoch()
70
        {
NEW
71
            return this switch
×
NEW
72
            {
×
NEW
73
                None => this,
×
NEW
74
                One => new None(),
×
NEW
75
                Two two => new One(two.Value),
×
NEW
76
                _ => throw new InvalidOperationException()
×
NEW
77
            };
×
78
        }
79

80
        /// <summary>
81
        /// Converts the FutureEpoch to an Option-like value (null if None, value otherwise).
82
        /// </summary>
83
        public T? ToOption()
84
        {
NEW
85
            return this switch
×
NEW
86
            {
×
NEW
87
                None => default,
×
NEW
88
                One one => one.Value,
×
NEW
89
                Two two => two.Value,
×
NEW
90
                _ => default
×
NEW
91
            };
×
92
        }
93

94
        /// <summary>
95
        /// Returns a None instance.
96
        /// </summary>
NEW
97
        public static FutureEpoch<T> NoneValue { get; } = new None();
×
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

© 2026 Coveralls, Inc