Esempio n. 1
0
        public ResultWrapper <BlockForRpc> eth_getBlockByNumber(BlockParameter blockParameter, bool returnFullTransactionObjects)
        {
            if (_blockchainBridge.Head == null)
            {
                return(ResultWrapper <BlockForRpc> .Fail("Incorrect head block"));
            }

            Block block;

            try
            {
                block = _blockchainBridge.GetBlock(blockParameter, true, true);
            }
            catch (JsonRpcException ex)
            {
                return(ResultWrapper <BlockForRpc> .Fail(ex.Message, ex.ErrorType, null));
            }

            if (block != null && returnFullTransactionObjects)
            {
                _blockchainBridge.RecoverTxSenders(block);
            }

            return(ResultWrapper <BlockForRpc> .Success(block == null?null : new BlockForRpc(block, returnFullTransactionObjects)));
        }
        public static Block GetBlock(this IBlockchainBridge blockchainBridge, BlockParameter blockParameter, bool allowNulls = false, bool recoverTxSenders = false)
        {
            Block block;

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

                block = blockchainBridge.GetBlock(blockParameter.ToFilterBlock());
                break;
            }

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

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

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

//            if (block != null && recoverTxSenders)
//            {
//                blockchainBridge.RecoverTxSenders(block);
//            }

            return(block);
        }
Esempio n. 3
0
        public ResultWrapper <byte[]> eth_call(TransactionForRpc transactionCall, BlockParameter blockParameter = null)
        {
            try
            {
                _readerWriterLockSlim.EnterWriteLock();
                BlockHeader block = blockParameter == null ? _blockchainBridge.Head : _blockchainBridge.GetBlock(blockParameter).Header;
                BlockchainBridge.CallOutput result = _blockchainBridge.Call(block, transactionCall.ToTransaction());

                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));
            }
            finally
            {
                _readerWriterLockSlim.ExitWriteLock();
            }
        }
Esempio n. 4
0
        public ResultWrapper <byte[]> eth_call(TransactionForRpc transactionCall, BlockParameter blockParameter = null)
        {
            BlockHeader block = blockParameter == null ? _blockchainBridge.Head : _blockchainBridge.GetBlock(blockParameter).Header;

            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));
        }