コード例 #1
0
ファイル: EthModule.cs プロジェクト: angelinai/nethermind
        public ResultWrapper <Transaction> eth_getTransactionByHash(Data transactionHash)
        {
            var transaction = _blockchainBridge.GetTransaction(new Keccak(transactionHash.Value));

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

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

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

            var transactionModel = _modelMapper.MapTransaction(transaction, block);

            if (Logger.IsTrace)
            {
                Logger.Trace($"eth_getTransactionByHash request {transactionHash.ToJson()}, result: {GetJsonLog(transactionModel.ToJson())}");
            }
            return(ResultWrapper <Transaction> .Success(transactionModel));
        }
コード例 #2
0
    public Task <ResultWrapper <TransactionForRpc> > eth_getTransactionByHash(Keccak transactionHash)
    {
        UInt256?baseFee = null;

        _txPoolBridge.TryGetPendingTransaction(transactionHash, out Transaction transaction);
        TxReceipt receipt = null; // note that if transaction is pending then for sure no receipt is known

        if (transaction == null)
        {
            (receipt, transaction, baseFee) = _blockchainBridge.GetTransaction(transactionHash);
            if (transaction == null)
            {
                return(Task.FromResult(ResultWrapper <TransactionForRpc> .Success(null)));
            }
        }

        RecoverTxSenderIfNeeded(transaction);
        TransactionForRpc transactionModel =
            new(receipt?.BlockHash, receipt?.BlockNumber, receipt?.Index, transaction, baseFee);

        if (_logger.IsTrace)
        {
            _logger.Trace($"eth_getTransactionByHash request {transactionHash}, result: {transactionModel.Hash}");
        }
        return(Task.FromResult(ResultWrapper <TransactionForRpc> .Success(transactionModel)));
    }
コード例 #3
0
        public async Task TryConfirmAsync(DepositDetails deposit)
        {
            if (deposit.Confirmed || deposit.Rejected)
            {
                return;
            }

            var head            = _blockchainBridge.Head;
            var transactionHash = deposit.TransactionHash;

            var(receipt, transaction) = _blockchainBridge.GetTransaction(deposit.TransactionHash);
            if (transaction is null)
            {
                if (_logger.IsInfo)
                {
                    _logger.Info($"Transaction was not found for hash: '{transactionHash}' for deposit: '{deposit.Id}' to be confirmed.");
                }
                return;
            }

            var(confirmations, rejected) = await VerifyDepositConfirmationsAsync(deposit, receipt, head.Hash);

            if (rejected)
            {
                deposit.Reject();
                await _depositRepository.UpdateAsync(deposit);

                await _consumerNotifier.SendDepositRejectedAsync(deposit.Id);

                return;
            }

            if (_logger.IsInfo)
            {
                _logger.Info($"Deposit: '{deposit.Id}' has {confirmations} confirmations (required at least {_requiredBlockConfirmations}) for transaction hash: '{transactionHash}' to be confirmed.");
            }
            var confirmed = confirmations >= _requiredBlockConfirmations;

            if (confirmed)
            {
                if (_logger.IsInfo)
                {
                    _logger.Info($"Deposit with id: '{deposit.Deposit.Id}' has been confirmed.");
                }
            }

            if (confirmations != deposit.Confirmations || confirmed)
            {
                deposit.SetConfirmations(confirmations);
                await _depositRepository.UpdateAsync(deposit);
            }

            await _consumerNotifier.SendDepositConfirmationsStatusAsync(deposit.Id, deposit.DataAsset.Name,
                                                                        confirmations, _requiredBlockConfirmations, deposit.ConfirmationTimestamp, confirmed);
        }
コード例 #4
0
        public Task <NdmTransaction> GetTransactionAsync(Keccak transactionHash)
        {
            var(receipt, transaction) = _blockchainBridge.GetTransaction(transactionHash);
            if (receipt is null || transaction is null)
            {
                return(Task.FromResult <NdmTransaction>(null));
            }

            return(Task.FromResult(new NdmTransaction(transaction, receipt.BlockNumber, receipt.BlockHash,
                                                      receipt.GasUsed)));
        }
コード例 #5
0
        public Task <NdmTransaction?> GetTransactionAsync(Keccak transactionHash)
        {
            (TxReceipt receipt, Transaction transaction) = _blockchainBridge.GetTransaction(transactionHash);
            if (transaction is null)
            {
                return(Task.FromResult <NdmTransaction?>(null));
            }

            var isPending = receipt is null;

            return(Task.FromResult <NdmTransaction?>(new NdmTransaction(transaction, isPending, receipt?.BlockNumber ?? 0,
                                                                        receipt?.BlockHash, receipt?.GasUsed ?? 0)));
        }
コード例 #6
0
ファイル: EthModule.cs プロジェクト: aboussetta/nethermind
        public ResultWrapper <Transaction> eth_getTransactionByHash(Data transactionHash)
        {
            (Core.TransactionReceipt receipt, Core.Transaction transaction) = _blockchainBridge.GetTransaction(new Keccak(transactionHash.Value));
            if (transaction == null)
            {
                return(ResultWrapper <Transaction> .Fail($"Cannot find transaction for hash: {transactionHash.Value}", ErrorType.NotFound));
            }

            var transactionModel = _modelMapper.MapTransaction(receipt, transaction);

            if (Logger.IsTrace)
            {
                Logger.Trace($"eth_getTransactionByHash request {transactionHash.ToJson()}, result: {GetJsonLog(transactionModel.ToJson())}");
            }
            return(ResultWrapper <Transaction> .Success(transactionModel));
        }
コード例 #7
0
        private async Task TryConfirmClaimAsync(DepositDetails deposit, string type)
        {
            var depositId       = deposit.Id;
            var transactionHash = deposit.TransactionHash;

            var(receipt, transaction) = _blockchainBridge.GetTransaction(transactionHash);
            if (transaction is null)
            {
                if (_logger.IsInfo)
                {
                    _logger.Info($"Transaction was not found for hash: '{transactionHash}' for deposit: '{depositId}' to claim the {type}refund.");
                }
                return;
            }

            if (_logger.IsInfo)
            {
                _logger.Info($"Trying to claim the {type}refund (transaction hash: '{transactionHash}') for deposit: '{depositId}'.");
            }
            var verifierResult = _transactionVerifier.Verify(receipt);

            if (!verifierResult.BlockFound)
            {
                if (_logger.IsWarn)
                {
                    _logger.Warn($"Block number: {receipt.BlockNumber}, hash: '{receipt.BlockHash}' was not found for transaction hash: '{transactionHash}' - {type}refund claim for deposit: '{depositId}' will not confirmed.");
                }
                return;
            }

            if (_logger.IsInfo)
            {
                _logger.Info($"The {type}refund claim (transaction hash: '{transactionHash}') for deposit: '{depositId}' has {verifierResult.Confirmations} confirmations (required at least {verifierResult.RequiredConfirmations}).");
            }
            if (!verifierResult.Confirmed)
            {
                return;
            }

            deposit.SetRefundClaimed();
            await _depositRepository.UpdateAsync(deposit);

            if (_logger.IsInfo)
            {
                _logger.Info($"The {type}refund claim (transaction hash: '{transactionHash}') for deposit: '{depositId}' has been confirmed.");
            }
        }
コード例 #8
0
        public async Task get_transaction_should_invoke_blockchain_bridge_get_transaction_and_return_ndm_transaction()
        {
            var receipt     = Build.A.Receipt.TestObject;
            var transaction = Build.A.Transaction.TestObject;
            var tuple       = (receipt, transaction);
            var hash        = TestItem.KeccakA;

            _blockchainBridge.GetTransaction(hash).Returns(tuple);
            var result = await _ndmBridge.GetTransactionAsync(hash);

            result.Should().NotBeNull();
            _blockchainBridge.Received().GetTransaction(hash);
            result.Transaction.Should().Be(transaction);
            result.BlockNumber.Should().Be(receipt.BlockNumber);
            result.BlockHash.Should().Be(receipt.BlockHash);
            result.GasUsed.Should().Be(receipt.GasUsed);
        }
コード例 #9
0
ファイル: EthModule.cs プロジェクト: phahulin/nethermind
        public ResultWrapper <TransactionForRpc> eth_getTransactionByHash(Keccak transactionHash)
        {
            (TxReceipt receipt, Transaction transaction) = _blockchainBridge.GetTransaction(transactionHash);
            if (transaction == null)
            {
                return(ResultWrapper <TransactionForRpc> .Success(null));
            }

            _blockchainBridge.RecoverTxSender(transaction, receipt.BlockNumber);
            var transactionModel = new TransactionForRpc(receipt.BlockHash, receipt.BlockNumber, receipt.Index, transaction);

            if (_logger.IsTrace)
            {
                _logger.Trace($"eth_getTransactionByHash request {transactionHash}, result: {transactionModel.Hash}");
            }
            return(ResultWrapper <TransactionForRpc> .Success(transactionModel));
        }
コード例 #10
0
        public async Task get_transaction_should_invoke_blockchain_bridge_get_transaction_and_return_ndm_transaction()
        {
            TxReceipt   receipt     = Build.A.Receipt.TestObject;
            Transaction transaction = Build.A.Transaction.TestObject;
            UInt256?    baseFee     = null;

            (TxReceipt receipt, Transaction transaction, UInt256? baseFee)tuple = (receipt, transaction, baseFee);
            Keccak hash = TestItem.KeccakA;

            _blockchainBridge.GetTransaction(hash).Returns(tuple);
            NdmTransaction?result = await _ndmBridge.GetTransactionAsync(hash);

            result.Should().NotBeNull();
            _blockchainBridge.Received().GetTransaction(hash);
            result.Transaction.Should().Be(transaction);
            result.BlockNumber.Should().Be(receipt.BlockNumber);
            result.BlockHash.Should().Be(receipt.BlockHash);
            result.GasUsed.Should().Be(receipt.GasUsed);
        }
コード例 #11
0
ファイル: EthModule.cs プロジェクト: chidionyema/nethermind
        public ResultWrapper <TransactionForRpc> eth_getTransactionByHash(Keccak transactionHash)
        {
            try
            {
                _readerWriterLockSlim.EnterReadLock();
                (Core.TransactionReceipt receipt, Transaction transaction) = _blockchainBridge.GetTransaction(transactionHash);
                if (transaction == null)
                {
                    return(ResultWrapper <TransactionForRpc> .Fail($"Cannot find transaction for hash: {transactionHash}", ErrorType.NotFound));
                }

                var transactionModel = new TransactionForRpc(receipt.BlockHash, receipt.BlockNumber, receipt.Index, transaction);
                if (Logger.IsTrace)
                {
                    Logger.Trace($"eth_getTransactionByHash request {transactionHash}, result: {transactionModel.Hash}");
                }
                return(ResultWrapper <TransactionForRpc> .Success(transactionModel));
            }
            finally
            {
                _readerWriterLockSlim.ExitReadLock();
            }
        }
コード例 #12
0
        public ResultWrapper <TransactionForRpc> eth_getTransactionByHash(Keccak transactionHash)
        {
            try
            {
                _readerWriterLockSlim.EnterReadLock();
                (TxReceipt receipt, Transaction transaction) = _blockchainBridge.GetTransaction(transactionHash);
                if (transaction == null)
                {
                    return(ResultWrapper <TransactionForRpc> .Success(null));
                }

                _blockchainBridge.RecoverTxSender(transaction, receipt.BlockNumber);
                var transactionModel = new TransactionForRpc(receipt.BlockHash, receipt.BlockNumber, receipt.Index, transaction);
                if (Logger.IsTrace)
                {
                    Logger.Trace($"eth_getTransactionByHash request {transactionHash}, result: {transactionModel.Hash}");
                }
                return(ResultWrapper <TransactionForRpc> .Success(transactionModel));
            }
            finally
            {
                _readerWriterLockSlim.ExitReadLock();
            }
        }