Example #1
0
        /// <summary>
        /// Calls the function in contract, state modification is allowed.
        /// </summary>
        /// <param name="header">Header in which context the call is done.</param>
        /// <param name="function">Function in contract that is being called.</param>
        /// <param name="sender">Sender of the transaction - caller of the function.</param>
        /// <param name="arguments">Arguments to the function.</param>
        /// <returns>Deserialized return value of the <see cref="function"/> based on its definition.</returns>
        protected object[] Call(BlockHeader header, AbiFunctionDescription function, Address sender, params object[] arguments)
        {
            var transaction = GenerateTransaction <SystemTransaction>(function, sender, arguments);
            var result      = Call(header, transaction);
            var objects     = AbiEncoder.Decode(function.GetReturnInfo(), result);

            return(objects);
        }
        public UInt256?BlockGasLimit(BlockHeader parentHeader)
        {
            this.BlockActivationCheck(parentHeader);
            var function = Definition.GetFunction(nameof(BlockGasLimit));
            var bytes    = Constant.CallRaw(parentHeader, function, Address.Zero);

            return((bytes?.Length ?? 0) == 0 ? (UInt256?)null : (UInt256)AbiEncoder.Decode(function.GetReturnInfo(), bytes)[0]);
        }
Example #3
0
        /// <summary>
        /// Calls the function in contract, state modification is allowed.
        /// </summary>
        /// <param name="header">Header in which context the call is done.</param>
        /// <param name="functionName"></param>
        /// <param name="sender">Sender of the transaction - caller of the function.</param>
        /// <param name="gasLimit">Gas limit for generated transaction.</param>
        /// <param name="arguments">Arguments to the function.</param>
        /// <returns>Deserialized return value of the <see cref="functionName"/> based on its definition.</returns>
        protected object[] Call(BlockHeader header, string functionName, Address sender, long gasLimit, params object[] arguments)
        {
            var function    = AbiDefinition.GetFunction(functionName);
            var transaction = GenerateTransaction <SystemTransaction>(functionName, sender, gasLimit, header, arguments);
            var result      = Call(header, transaction);
            var objects     = AbiEncoder.Decode(function.GetReturnInfo(), result);

            return(objects);
        }
Example #4
0
 protected object[] DecodeData(AbiEncodingInfo abiEncodingInfo, byte[] data)
 {
     try
     {
         return(AbiEncoder.Decode(abiEncodingInfo, data));
     }
     catch (Exception e)
     {
         throw new AbiException($"Cannot decode return data for function {abiEncodingInfo.Signature} for contract {ContractAddress}.", e);
     }
 }
Example #5
0
        /// <summary>
        /// Same as <see cref="Call(Nethermind.Core.BlockHeader,AbiFunctionDescription,Address,object[])"/> but returns false instead of throwing <see cref="AuRaException"/>.
        /// </summary>
        /// <param name="header">Header in which context the call is done.</param>
        /// <param name="function">Function in contract that is being called.</param>
        /// <param name="sender">Sender of the transaction - caller of the function.</param>
        /// <param name="result">Deserialized return value of the <see cref="function"/> based on its definition.</param>
        /// <param name="arguments">Arguments to the function.</param>
        /// <returns>true if function was <see cref="StatusCode.Success"/> otherwise false.</returns>
        protected bool TryCall(BlockHeader header, AbiFunctionDescription function, Address sender, out object[] result, params object[] arguments)
        {
            var transaction = GenerateTransaction <SystemTransaction>(function, sender, arguments);

            if (TryCall(header, transaction, out var bytes))
            {
                result = AbiEncoder.Decode(function.GetReturnInfo(), bytes);
                return(true);
            }

            result = null;
            return(false);
        }
Example #6
0
        /// <summary>
        /// Same as <see cref="Call(Nethermind.Core.BlockHeader,AbiFunctionDescription,Address,object[])"/> but returns false instead of throwing <see cref="AbiException"/>.
        /// </summary>
        /// <param name="header">Header in which context the call is done.</param>
        /// <param name="functionName"></param>
        /// <param name="sender">Sender of the transaction - caller of the function.</param>
        /// <param name="gasLimit">Gas limit for generated transaction.</param>
        /// <param name="result">Deserialized return value of the <see cref="functionName"/> based on its definition.</param>
        /// <param name="arguments">Arguments to the function.</param>
        /// <returns>true if function was <see cref="StatusCode.Success"/> otherwise false.</returns>
        protected bool TryCall(BlockHeader header, string functionName, Address sender, long gasLimit, out object[] result, params object[] arguments)
        {
            var function    = AbiDefinition.GetFunction(functionName);
            var transaction = GenerateTransaction <SystemTransaction>(functionName, sender, gasLimit, header, arguments);

            if (TryCall(header, transaction, out var bytes))
            {
                result = AbiEncoder.Decode(function.GetReturnInfo(), bytes);
                return(true);
            }

            result = null;
            return(false);
        }
Example #7
0
        public void Dynamic_array_of_dynamic_array_of_uint(AbiEncodingStyle encodingStyle)
        {
            AbiType      type      = new AbiArray(new AbiArray(AbiType.UInt256));
            AbiSignature signature = new AbiSignature("abc", type);

            BigInteger[]   element   = { 1, 2, 3 };
            BigInteger[][] data      = { element, element };
            byte[]         encoded   = _abiEncoder.Encode(encodingStyle, signature, new object[] { data });
            object[]       arguments = _abiEncoder.Decode(encodingStyle, signature, encoded);
            Assert.AreEqual(arguments[0], data);
        }
Example #8
0
 protected object[] DecodeData(AbiEncodingInfo abiEncodingInfo, byte[] data) => AbiEncoder.Decode(abiEncodingInfo, data);
Example #9
0
 protected object[] DecodeReturnData(string functionName, byte[] data)
 {
     return(AbiEncoder.Decode(AbiDefinition.GetFunction(functionName).GetReturnInfo(), data));
 }