Beispiel #1
0
        private static void BuildZeroHashes()
        {
            Span <UInt256> concatenation = stackalloc UInt256[2];

            UInt256.CreateFromLittleEndian(out ZeroHashes[0], Hash32.Zero.Bytes);
            for (int i = 1; i < 64; i++)
            {
                var previous = ZeroHashes[i - 1];
                MemoryMarshal.CreateSpan(ref previous, 1).CopyTo(concatenation.Slice(0, 1));
                MemoryMarshal.CreateSpan(ref previous, 1).CopyTo(concatenation.Slice(1, 1));
                UInt256.CreateFromLittleEndian(out ZeroHashes[i], Sha256.Compute(MemoryMarshal.Cast <UInt256, byte>(concatenation)).Bytes);
            }
        }
Beispiel #2
0
        public static void Ize(out UInt256 root, Root value)
        {
            ReadOnlySpan <byte> readOnlyBytes = value.AsSpan();

            unsafe
            {
                fixed(byte *buffer = &readOnlyBytes.GetPinnableReference())
                {
                    Span <byte> apiNeedsWriteableEvenThoughOnlyReading = new Span <byte>(buffer, readOnlyBytes.Length);

                    UInt256.CreateFromLittleEndian(out root, apiNeedsWriteableEvenThoughOnlyReading);
                }
            }
        }
Beispiel #3
0
 public static void Ize(out UInt256 root, Hash32 value)
 {
     UInt256.CreateFromLittleEndian(out root, value.Bytes ?? Hash32.Zero.Bytes);
 }
Beispiel #4
0
 public void AsInt(out UInt256 intRoot)
 {
     UInt256.CreateFromLittleEndian(out intRoot, Bytes.AsSpan());
 }
Beispiel #5
0
 public static void Ize(out UInt256 root, Sha256 value)
 {
     UInt256.CreateFromLittleEndian(out root, value?.Bytes ?? Bytes.Zero32);
 }