Exemple #1
0
 public static void DecodeBlockHashTxIndex(byte[] bytes, out UInt256 blockHash, out int txIndex)
 {
     if (bytes[0] == BLOCK_TX_PREFIX)
     {
         blockHash = UInt256.FromByteArrayBE(bytes, 1);
         txIndex   = DecodeInt32(bytes, 33);
     }
     else
     {
         blockHash = UInt256.Zero;
         txIndex   = -1;
     }
 }
Exemple #2
0
        private void DecodeTotalWorkKey(byte[] key, out UInt256 blockHash, out BigInteger totalWork)
        {
            if (key.Length != 97)
            {
                throw new ArgumentOutOfRangeException(nameof(key));
            }
            else if (key[0] != TOTAL_WORK_PREFIX)
            {
                throw new ArgumentOutOfRangeException(nameof(key));
            }

            var totalWorkBytes = new byte[64];

            Buffer.BlockCopy(key, 1, totalWorkBytes, 0, 64);
            Array.Reverse(totalWorkBytes);
            totalWork = new BigInteger(totalWorkBytes);

            blockHash = UInt256.FromByteArrayBE(key, 65);
        }
 /// <summary>
 /// Retrieves function hash from transaction data
 /// </summary>
 private void RetrieveFunctionHash()
 {
     Context.Append(UInt256.Zero); // offset for calldata
     Context.Append(EvmInstruction.CALLDATALOAD);
     Context.Append(UInt256.FromByteArrayBE(new byte[]
     {
         0, 0, 0, 1, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0
     })); //hardcoded bytes used to get first 4 bytes of transaction data
     Context.Append(EvmInstruction.SWAP1);
     Context.Append(EvmInstruction.DIV);
     Context.Append(UInt256.FromByteArrayBE(new byte[]
     {
         0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 255, 255, 255, 255
     })); //and here
     Context.Append(EvmInstruction.AND);
 }
Exemple #4
0
 public static UInt256 DecodeUInt256(byte[] value)
 {
     return(UInt256.FromByteArrayBE(value));
 }