| | 1 | | namespace NLightning.Domain.ValueObjects; |
| | 2 | |
|
| | 3 | | using Enums; |
| | 4 | | using Interfaces; |
| | 5 | |
|
| | 6 | | /// <summary> |
| | 7 | | /// Only the least-significant bit of channel_flags is currently defined: announce_channel. This indicates whether |
| | 8 | | /// the initiator of the funding flow wishes to advertise this channel publicly to the network |
| | 9 | | /// </summary> |
| | 10 | | public readonly struct ChannelFlags : IValueObject, IEquatable<ChannelFlags> |
| | 11 | | { |
| | 12 | | private readonly byte _value; |
| | 13 | |
|
| 16 | 14 | | public bool AnnounceChannel => ((ChannelFlag)_value).HasFlag(ChannelFlag.AnnounceChannel); |
| | 15 | |
|
| | 16 | | public ChannelFlags(byte value) |
| | 17 | | { |
| 40 | 18 | | _value = value; |
| 40 | 19 | | } |
| | 20 | | public ChannelFlags(ChannelFlag value) |
| | 21 | | { |
| 4 | 22 | | _value = (byte)value; |
| 4 | 23 | | } |
| | 24 | |
|
| | 25 | | #region Equality |
| | 26 | | public override bool Equals(object? obj) |
| | 27 | | { |
| 0 | 28 | | if (obj is ChannelFlags other) |
| | 29 | | { |
| 0 | 30 | | return _value == other._value; |
| | 31 | | } |
| 0 | 32 | | return false; |
| | 33 | | } |
| | 34 | |
|
| | 35 | | public bool Equals(ChannelFlags other) |
| | 36 | | { |
| 12 | 37 | | return _value == other._value; |
| | 38 | | } |
| | 39 | |
|
| | 40 | | public override int GetHashCode() |
| | 41 | | { |
| 0 | 42 | | return _value.GetHashCode(); |
| | 43 | | } |
| | 44 | |
|
| 0 | 45 | | public static bool operator ==(ChannelFlags left, ChannelFlags right) => left.Equals(right); |
| 0 | 46 | | public static bool operator !=(ChannelFlags left, ChannelFlags right) => !(left == right); |
| | 47 | | #endregion |
| | 48 | |
|
| | 49 | | #region Implicit Conversions |
| 24 | 50 | | public static implicit operator byte(ChannelFlags c) => c._value; |
| 4 | 51 | | public static implicit operator ChannelFlags(byte value) => new(value); |
| 4 | 52 | | public static implicit operator byte[](ChannelFlags c) => [c._value]; |
| 4 | 53 | | public static implicit operator ChannelFlags(byte[] value) => new(value[0]); |
| | 54 | | #endregion |
| | 55 | | } |