Exemple #1
0
        public ResultWrapper <byte[]> eth_call(TransactionForRpc transactionCall, BlockParameter blockParameter = null)
        {
            BlockHeader block = _blockchainBridge.GetHeader(blockParameter ?? BlockParameter.Latest);

            var tx = transactionCall.ToTransaction();

            tx.GasPrice = 0;
            if (tx.GasLimit < 21000)
            {
                tx.GasLimit = 10000000;
            }

            if (tx.To == null)
            {
                return(ResultWrapper <byte[]> .Fail($"Recipient address not specified on the transaction.", ErrorType.InvalidParams));
            }

            BlockchainBridge.CallOutput result = _blockchainBridge.Call(block, tx);

            if (result.Error != null)
            {
                return(ResultWrapper <byte[]> .Fail($"VM Exception while processing transaction: {result.Error}", ErrorType.ExecutionError, result.OutputData));
            }

            return(ResultWrapper <byte[]> .Success(result.OutputData));
        }
        public static BlockHeader GetHeader(this IBlockchainBridge blockchainBridge, BlockParameter blockParameter, bool allowNulls = false)
        {
            BlockHeader header;

            switch (blockParameter.Type)
            {
            case BlockParameterType.BlockNumber:
            {
                if (blockParameter.BlockNumber == null)
                {
                    throw new JsonRpcException(ErrorType.InvalidParams, $"Block number is required for {BlockParameterType.BlockNumber}");
                }

                header = blockchainBridge.GetHeader(blockParameter.ToFilterBlock());
                break;
            }

            case BlockParameterType.Pending:
            case BlockParameterType.Latest:
            case BlockParameterType.Earliest:
            {
                header = blockchainBridge.GetHeader(blockParameter.ToFilterBlock());
                break;
            }

            default:
                throw new ArgumentException($"{nameof(BlockParameterType)} not supported: {blockParameter.Type}");
            }

            if (header == null && !allowNulls)
            {
                throw new JsonRpcException(ErrorType.NotFound, $"Cannot find block {blockParameter}");
            }

            return(header);
        }
Exemple #3
0
        public ResultWrapper <string> eth_call(TransactionForRpc transactionCall, BlockParameter blockParameter = null)
        {
            BlockHeader block = _blockchainBridge.GetHeader(blockParameter ?? BlockParameter.Latest);

            var tx = transactionCall.ToTransaction();

            tx.GasPrice = 0;
            if (tx.GasLimit < 21000)
            {
                tx.GasLimit = 10000000;
            }

            BlockchainBridge.CallOutput result = _blockchainBridge.Call(block, tx);

            if (result.Error != null)
            {
                return(ResultWrapper <string> .Fail("VM execution error.", ErrorType.ExecutionError, result.Error));
            }

            return(ResultWrapper <string> .Success(result.OutputData.ToHexString(true)));
        }