Exemple #1
0
        public UnspentTx(UInt256 blockHash, UInt32 txIndex, UInt256 txHash, ImmutableBitArray unspentOutputs)
        {
            this._blockHash = blockHash;
            this._txIndex = txIndex;
            this._txHash = txHash;
            this._unspentOutputs = unspentOutputs;

            this.hashCode = blockHash.GetHashCode() ^ txIndex.GetHashCode() ^ txHash.GetHashCode() ^ unspentOutputs.GetHashCode();
        }
Exemple #2
0
        public UnspentTx(UInt256 blockHash, UInt32 txIndex, UInt256 txHash, ImmutableBitArray unspentOutputs)
        {
            this._blockHash      = blockHash;
            this._txIndex        = txIndex;
            this._txHash         = txHash;
            this._unspentOutputs = unspentOutputs;

            this.notDefault = true;
            this.hashCode   = blockHash.GetHashCode() ^ txIndex.GetHashCode() ^ txHash.GetHashCode() ^ unspentOutputs.GetHashCode();
        }
Exemple #3
0
        /// <summary>
        /// Returns the <typeparamref name="T"/> derived instance corresponding to the
        /// <paramref name="bits"/>.
        /// </summary>
        /// <param name="bits"></param>
        /// <returns></returns>
        /// <see cref="FromBytesCtor"/>
        public static T FromBitArray(ImmutableBitArray bits)
        {
            // This seems a bit redundant since the value is its own key...
            var @default = FromBytesCtor(bits.ToBytes(false).ToArray());

            //TODO: dictionary would be preferred, but for some reason it's not "catching" on the correct values...
            // We either want the enumerated value itself or the factory created version.
            var result = Values.FirstOrDefault(x => x.Equals(@default));

            return(result ?? @default);
        }
Exemple #4
0
        /// <summary>
        /// Returns the <typeparamref name="T"/> instance derived from the <paramref name="bytes"/>.
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        /// <see cref="FromBitArray"/>
        public static T FromBytes(byte[] bytes)
        {
            // Rule out exceptional conditions up front.
            if (bytes == null)
            {
                throw new ArgumentNullException(nameof(bytes), $"Bytes values are required for an {typeof(T)}");
            }

            if (!bytes.Any())
            {
                throw new ArgumentException($"Bytes values are required for an {typeof(T)}", nameof(bytes));
            }

            // Make sure that the bytes are dealt with in LSB order.
            return(FromBitArray(ImmutableBitArray.FromBytes(bytes, false)));
        }
Exemple #5
0
        /// <summary>
        /// Initializes the <see cref="Enumeration{TKey}.Key" /> in the <paramref name="values"/>.
        /// Assumes that the intended order of initialization has been resolved approaching a call
        /// to this helper method.
        /// </summary>
        /// <param name="values"></param>
        /// <param name="value"></param>
        /// <param name="shiftCount"></param>
        protected static void InitializeKeys(IEnumerable <T> values, uint value = 0x1, int shiftCount = 0)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            const Elasticity expansion = Elasticity.Expansion;

            var starting = ImmutableBitArray.FromInts(new[] { value }).ShiftLeft(shiftCount, expansion);

            values.ToList().Aggregate(starting, (key, x) =>
            {
                x.Key = key;
                return(key.ShiftLeft(elasticity: expansion));
            });
        }
 public override void Enumeration_Value_Key_Correct(ImmutableBitArray key, string name, string displayName)
 => base.Enumeration_Value_Key_Correct(key, name, displayName);
Exemple #7
0
 /// <inheritdoc />
 /// <remarks>Comparable and Equality is already implemented at the base class
 /// level. The only thing we have to do here is specialize that for the
 /// <see cref="ImmutableBitArray"/>.</remarks>
 /// <see cref="ImmutableBitArray.CompareTo(ImmutableBitArray,ImmutableBitArray)"/>
 public override int CompareTo(ImmutableBitArray other) => ImmutableBitArray.CompareTo(Key, other);
Exemple #8
0
 public OutputStates(ImmutableBitArray bitArray)
 {
     this.bitArray = bitArray;
 }
Exemple #9
0
 public OutputStates(byte[] bytes, int length)
 {
     this.bitArray = new ImmutableBitArray(bytes, length);
 }
Exemple #10
0
 public OutputStates(int length, OutputState state)
 {
     this.bitArray = new ImmutableBitArray(length, Encode(state));
 }
Exemple #11
0
 /// <summary>
 /// Protected Default Constructor.
 /// </summary>
 /// <param name="bits"></param>
 protected Enumeration(ImmutableBitArray bits)
     : base(bits ?? DefaultKey, null, null)
 {
 }
Exemple #12
0
 /// <summary>
 /// Returns the <see cref="ImmutableBitArray"/> correlating to <paramref name="bytes"/>.
 /// </summary>
 /// <param name="bytes"></param>
 /// <returns></returns>
 /// <see cref="DefaultKeyBytes"/>
 private static ImmutableBitArray GetDefaultKey(IEnumerable <byte> bytes = null)
 => ImmutableBitArray.FromBytes(bytes ?? DefaultKeyBytes);
Exemple #13
0
 /// <summary>
 /// Protected Constructor.
 /// </summary>
 /// <param name="bits"></param>
 /// <param name="name"></param>
 /// <param name="displayName"></param>
 protected Enumeration(ImmutableBitArray bits, string name, string displayName)
     : base(bits ?? DefaultKey, name, displayName)
 {
 }
Exemple #14
0
 /// <summary>
 /// Protected Constructor.
 /// </summary>
 /// <param name="bits"></param>
 /// <param name="name"></param>
 protected Enumeration(ImmutableBitArray bits, string name)
     : base(bits ?? DefaultKey, name, null)
 {
 }