Esempio n. 1
0
        public ResultWrapper <Transaction> eth_getTransactionByBlockHashAndIndex(Data blockHash, Quantity positionIndex)
        {
            var block = _blockchainBridge.FindBlock(new Keccak(blockHash.Value), false);

            if (block == null)
            {
                return(ResultWrapper <Transaction> .Fail($"Cannot find block for hash: {blockHash.Value}", ErrorType.NotFound));
            }

            var index = positionIndex.AsNumber();

            if (!index.HasValue)
            {
                return(ResultWrapper <Transaction> .Fail("Position Index is required", ErrorType.InvalidParams));
            }

            if (index.Value < 0 || index.Value > block.Transactions.Length - 1)
            {
                return(ResultWrapper <Transaction> .Fail("Position Index is incorrect", ErrorType.InvalidParams));
            }

            var transaction      = block.Transactions[(int)index.Value];
            var transactionModel = _modelMapper.MapTransaction(block.Hash, block.Number, (int)index.Value, transaction);

            if (Logger.IsDebug)
            {
                Logger.Debug($"eth_getTransactionByBlockHashAndIndex request {blockHash.ToJson()}, index: {positionIndex.ToJson()}, result: {GetJsonLog(transactionModel.ToJson())}");
            }
            return(ResultWrapper <Transaction> .Success(transactionModel));
        }
Esempio n. 2
0
        public void NetPeerCountTest()
        {
            INetModule netModule = Substitute.For <INetModule>();

            netModule.net_peerCount().ReturnsForAnyArgs(x => ResultWrapper <BigInteger> .Success(new BigInteger(2)));
            JsonRpcResponse response = TestRequest <INetModule>(netModule, "net_peerCount");
            Quantity        quantity = new Quantity();

            quantity.FromJson(response.Result.ToString());
            Assert.AreEqual(quantity.AsNumber(), new UInt256(2));
        }
Esempio n. 3
0
        public ResultWrapper <Block> eth_getUncleByBlockNumberAndIndex(BlockParameter blockParameter, Quantity positionIndex)
        {
            if (_blockchainBridge.Head == null)
            {
                return(ResultWrapper <Block> .Fail($"Incorrect head block: {(_blockchainBridge.Head != null ? "HeadBlock is null" : "HeadBlock header is null")}"));
            }

            var result = GetBlock(blockParameter);

            if (result.Result.ResultType == ResultType.Failure)
            {
                return(ResultWrapper <Block> .Fail(result.Result.Error, result.ErrorType));
            }

            var index = positionIndex.AsNumber();

            if (!index.HasValue)
            {
                return(ResultWrapper <Block> .Fail("Position Index is required", ErrorType.InvalidParams));
            }

            if (index.Value < 0 || index.Value > result.Data.Ommers.Length - 1)
            {
                return(ResultWrapper <Block> .Fail("Position Index is incorrect", ErrorType.InvalidParams));
            }

            var ommerHeader = result.Data.Ommers[(int)index.Value];
            var ommer       = _blockchainBridge.FindBlock(ommerHeader.Hash, false);

            if (ommer == null)
            {
                return(ResultWrapper <Block> .Fail($"Cannot find ommer for hash: {ommerHeader.Hash}", ErrorType.NotFound));
            }

            var blockModel = _modelMapper.MapBlock(ommer, false);

            if (Logger.IsDebug)
            {
                Logger.Debug($"eth_getUncleByBlockNumberAndIndex request {blockParameter}, index: {positionIndex.ToJson()}, result: {GetJsonLog(blockModel.ToJson())}");
            }
            return(ResultWrapper <Block> .Success(blockModel));
        }
Esempio n. 4
0
        public ResultWrapper <Block> eth_getUncleByBlockHashAndIndex(Data blockHashData, Quantity positionIndex)
        {
            Keccak blockHash = new Keccak(blockHashData.Value);
            var    block     = _blockchainBridge.FindBlock(blockHash, false);

            if (block == null)
            {
                return(ResultWrapper <Block> .Fail($"Cannot find block for hash: {blockHash}", ErrorType.NotFound));
            }

            var index = positionIndex.AsNumber();

            if (!index.HasValue)
            {
                return(ResultWrapper <Block> .Fail("Position Index is required", ErrorType.InvalidParams));
            }

            if (index.Value < 0 || index.Value > block.Ommers.Length - 1)
            {
                return(ResultWrapper <Block> .Fail("Position Index is incorrect", ErrorType.InvalidParams));
            }

            var ommerHeader = block.Ommers[(int)index.Value];
            var ommer       = _blockchainBridge.FindBlock(ommerHeader.Hash, false);

            if (ommer == null)
            {
                return(ResultWrapper <Block> .Fail($"Cannot find ommer for hash: {ommerHeader.Hash}", ErrorType.NotFound));
            }

            var blockModel = _modelMapper.MapBlock(ommer, false);

            if (Logger.IsTrace)
            {
                Logger.Trace($"eth_getUncleByBlockHashAndIndex request {blockHashData.ToJson()}, index: {positionIndex.ToJson()}, result: {GetJsonLog(blockModel.ToJson())}");
            }
            return(ResultWrapper <Block> .Success(blockModel));
        }
Esempio n. 5
0
        public ResultWrapper <Transaction> eth_getTransactionByBlockNumberAndIndex(BlockParameter blockParameter, Quantity positionIndex)
        {
            if (_blockchainBridge.Head == null)
            {
                return(ResultWrapper <Transaction> .Fail($"Incorrect head block: {(_blockchainBridge.Head != null ? "HeadBlock is null" : "HeadBlock header is null")}"));
            }

            var result = GetBlock(blockParameter);

            if (result.Result.ResultType == ResultType.Failure)
            {
                return(ResultWrapper <Transaction> .Fail(result.Result.Error, result.ErrorType));
            }

            var index = positionIndex.AsNumber();

            if (!index.HasValue)
            {
                return(ResultWrapper <Transaction> .Fail("Position Index is required", ErrorType.InvalidParams));
            }

            if (index.Value < 0 || index.Value > result.Data.Transactions.Length - 1)
            {
                return(ResultWrapper <Transaction> .Fail("Position Index is incorrect", ErrorType.InvalidParams));
            }

            Core.Block block            = result.Data;
            var        transaction      = block.Transactions[(int)index.Value];
            var        transactionModel = _modelMapper.MapTransaction(block.Hash, block.Number, (int)index.Value, transaction);

            if (Logger.IsDebug)
            {
                Logger.Debug($"eth_getTransactionByBlockNumberAndIndex request {blockParameter}, index: {positionIndex.ToJson()}, result: {GetJsonLog(transactionModel.ToJson())}");
            }
            return(ResultWrapper <Transaction> .Success(transactionModel));
        }
Esempio n. 6
0
        public ResultWrapper <BlockTraceItem[]> debug_traceBlockByNumber(Quantity blockNumber)
        {
            UInt256?blockNo = blockNumber.AsNumber();

            if (!blockNo.HasValue)
            {
                throw new InvalidDataException("Expected block number value");
            }

            var blockTrace = _debugBridge.GetBlockTrace(blockNo.Value);

            if (blockTrace == null)
            {
                return(ResultWrapper <BlockTraceItem[]> .Fail($"Trace is null for block {blockNo}", ErrorType.NotFound));
            }

            var blockTraceModel = _modelMapper.MapBlockTrace(blockTrace);

            if (Logger.IsTrace)
            {
                Logger.Trace($"{nameof(debug_traceBlockByNumber)} request {blockNumber}, result: {GetJsonLog(blockTraceModel.Select(btm => btm.ToJson()))}");
            }
            return(ResultWrapper <BlockTraceItem[]> .Success(blockTraceModel));
        }