Exemplo n.º 1
0
        public ResultWrapper <TransactionReceipt> eth_getTransactionReceipt(Data transactionHash)
        {
            var transactionReceipt = _blockchainBridge.GetTransactionReceipt(new Keccak(transactionHash.Value));

            if (transactionReceipt == null)
            {
                return(ResultWrapper <TransactionReceipt> .Fail($"Cannot find transactionReceipt for transaction hash: {transactionHash.Value}", ErrorType.NotFound));
            }
            var transaction = _blockchainBridge.GetTransaction(new Keccak(transactionHash.Value));

            if (transaction == null)
            {
                return(ResultWrapper <TransactionReceipt> .Fail($"Cannot find transaction for hash: {transactionHash.Value}", ErrorType.NotFound));
            }
            var blockHash = _blockchainBridge.GetBlockHash(new Keccak(transactionHash.Value));

            if (blockHash == null)
            {
                return(ResultWrapper <TransactionReceipt> .Fail($"Cannot find block hash for transaction: {transactionHash.Value}", ErrorType.NotFound));
            }
            var block = _blockchainBridge.FindBlock(blockHash, false);

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

            var transactionReceiptModel = _modelMapper.MapTransactionReceipt(transactionReceipt, transaction, block);

            if (Logger.IsTrace)
            {
                Logger.Trace($"eth_getTransactionReceipt request {transactionHash.ToJson()}, result: {GetJsonLog(transactionReceiptModel.ToJson())}");
            }
            return(ResultWrapper <TransactionReceipt> .Success(transactionReceiptModel));
        }
Exemplo n.º 2
0
        public void Eth_get_transaction_receipt_returns_null_on_missing_receipt()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.GetTransactionReceipt(Arg.Any <Keccak>()).Returns((TransactionReceipt)null);

            IEthModule module = new EthModule(new UnforgivingJsonSerializer(), Substitute.For <IConfigProvider>(), NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_getTransactionReceipt", TestObject.KeccakA.ToString());

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null}", serialized);
        }
Exemplo n.º 3
0
        public void Eth_get_transaction_receipt()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();
            var entries = new[]
            {
                Build.A.LogEntry.TestObject,
                Build.A.LogEntry.TestObject
            };

            bridge.GetTransactionReceipt(Arg.Any <Keccak>()).Returns(Build.A.Receipt.WithBloom(new Bloom(entries)).WithAllFieldsFilled.WithLogs(entries).TestObject);

            IEthModule module = new EthModule(new UnforgivingJsonSerializer(), Substitute.For <IConfigProvider>(), NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_getTransactionReceipt", TestObject.KeccakA.ToString());

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":{\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"transactionIndex\":\"0x2\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"cumulativeGasUsed\":\"0x3e8\",\"gasUsed\":\"0x64\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"contractAddress\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"logs\":[{\"removed\":false,\"logIndex\":\"0x0\",\"transactionIndex\":\"0x2\",\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"address\":\"0x0000000000000000000000000000000000000000\",\"data\":\"0x\",\"topics\":[\"0x0000000000000000000000000000000000000000000000000000000000000000\"]},{\"removed\":false,\"logIndex\":\"0x1\",\"transactionIndex\":\"0x2\",\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"address\":\"0x0000000000000000000000000000000000000000\",\"data\":\"0x\",\"topics\":[\"0x0000000000000000000000000000000000000000000000000000000000000000\"]}],\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"root\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"status\":\"0x0\",\"error\":\"error\"}}", serialized);
        }
Exemplo n.º 4
0
        public ResultWrapper <TransactionReceipt> eth_getTransactionReceipt(Data txHashData)
        {
            Keccak txHash             = new Keccak(txHashData.Value);
            var    transactionReceipt = _blockchainBridge.GetTransactionReceipt(txHash);

            if (transactionReceipt == null)
            {
                return(ResultWrapper <TransactionReceipt> .Fail($"Cannot find transactionReceipt for transaction hash: {txHash}", ErrorType.NotFound));
            }

            var transactionReceiptModel = _modelMapper.MapTransactionReceipt(txHash, transactionReceipt);

            if (Logger.IsTrace)
            {
                Logger.Trace($"eth_getTransactionReceipt request {txHashData.ToJson()}, result: {GetJsonLog(transactionReceiptModel.ToJson())}");
            }
            return(ResultWrapper <TransactionReceipt> .Success(transactionReceiptModel));
        }
Exemplo n.º 5
0
        public ResultWrapper <ReceiptForRpc> eth_getTransactionReceipt(Keccak txHash)
        {
            try
            {
                _readerWriterLockSlim.EnterReadLock();
                var transactionReceipt = _blockchainBridge.GetTransactionReceipt(txHash);
                if (transactionReceipt == null)
                {
                    return(ResultWrapper <ReceiptForRpc> .Success(null));
                }

                var transactionReceiptModel = new ReceiptForRpc(txHash, transactionReceipt);
                if (Logger.IsTrace)
                {
                    Logger.Trace($"eth_getTransactionReceipt request {txHash}, result: {txHash}");
                }
                return(ResultWrapper <ReceiptForRpc> .Success(transactionReceiptModel));
            }
            finally
            {
                _readerWriterLockSlim.ExitReadLock();
            }
        }