Beispiel #1
0
        void IInteroperable.FromStackItem(StackItem stackItem)
        {
            Array array = (Array)stackItem;

            Id            = (int)array[0].GetInteger();
            UpdateCounter = (ushort)array[1].GetInteger();
            Hash          = new UInt160(array[2].GetSpan());
            Nef           = array[3].GetSpan().AsSerializable <NefFile>();
            Manifest      = array[4].ToInteroperable <ContractManifest>();
        }
Beispiel #2
0
        void IInteroperable.FromReplica(IInteroperable replica)
        {
            ContractState from = (ContractState)replica;

            Id            = from.Id;
            UpdateCounter = from.UpdateCounter;
            Hash          = from.Hash;
            Nef           = from.Nef;
            Manifest      = from.Manifest;
        }
Beispiel #3
0
        /// <summary>
        /// Compute checksum for a file
        /// </summary>
        /// <param name="file">File</param>
        /// <returns>Return checksum</returns>
        unsafe public static uint ComputeChecksum(NefFile file)
        {
            Span <byte> header = stackalloc byte[HeaderSize];

            fixed(byte *p = header)
            using (UnmanagedMemoryStream ms = new UnmanagedMemoryStream(p, HeaderSize, HeaderSize, FileAccess.Write))
                using (BinaryWriter wr = new BinaryWriter(ms, Utility.StrictUTF8, false))
                {
                    file.SerializeHeader(wr);
                    wr.Flush();
                }
            return(BitConverter.ToUInt32(Crypto.Hash256(header), 0));
        }
Beispiel #4
0
        /// <summary>
        /// Compute checksum for a file
        /// </summary>
        /// <param name="file">File</param>
        /// <returns>Return checksum</returns>
        public static uint ComputeChecksum(NefFile file)
        {
            using (var ms = new MemoryStream())
                using (var wr = new BinaryWriter(ms))
                {
                    file.Serialize(wr);
                    wr.Flush();

                    // Read header without CRC

                    var buffer = new byte[HeaderSize - sizeof(uint)];
                    ms.Seek(0, SeekOrigin.Begin);
                    ms.Read(buffer, 0, buffer.Length);

                    return(BitConverter.ToUInt32(buffer.Sha256(), 0));
                }
        }
Beispiel #5
0
 /// <summary>
 /// Compute checksum for a file
 /// </summary>
 /// <param name="file">File</param>
 /// <returns>Return checksum</returns>
 public static uint ComputeChecksum(NefFile file)
 {
     return(BitConverter.ToUInt32(Crypto.Hash256(file.ToArray().AsSpan(..^ sizeof(int)))));
 }
Beispiel #6
0
 /// <summary>
 /// Computes the checksum for the specified nef file.
 /// </summary>
 /// <param name="file">The specified nef file.</param>
 /// <returns>The checksum of the nef file.</returns>
 public static uint ComputeChecksum(NefFile file)
 {
     return(BinaryPrimitives.ReadUInt32LittleEndian(Crypto.Hash256(file.ToArray().AsSpan(..^ sizeof(uint)))));
 }