Ejemplo n.º 1
0
    private async Task <ResultWrapper <Keccak> > SendTx(Transaction tx,
                                                        TxHandlingOptions txHandlingOptions = TxHandlingOptions.None)
    {
        try
        {
            (Keccak txHash, AcceptTxResult? acceptTxResult) =
                await _txSender.SendTransaction(tx, txHandlingOptions | TxHandlingOptions.PersistentBroadcast);

            return(acceptTxResult.Equals(AcceptTxResult.Accepted)
                ? ResultWrapper <Keccak> .Success(txHash)
                : ResultWrapper <Keccak> .Fail(acceptTxResult?.ToString() ?? string.Empty, ErrorCodes.TransactionRejected));
        }
        catch (SecurityException e)
        {
            return(ResultWrapper <Keccak> .Fail(e.Message, ErrorCodes.AccountLocked));
        }
        catch (Exception e)
        {
            if (_logger.IsError)
            {
                _logger.Error("Failed to send transaction.", e);
            }
            return(ResultWrapper <Keccak> .Fail(e.Message, ErrorCodes.TransactionRejected));
        }
    }
Ejemplo n.º 2
0
        public void Timestamp_is_set_on_transactions()
        {
            Transaction tx = Build.A.Transaction.Signed(new EthereumEcdsa(ChainId.Mainnet, LimboLogs.Instance), TestItem.PrivateKeyA).TestObject;

            _txSender.SendTransaction(tx, TxHandlingOptions.PersistentBroadcast);
            _txPool.Received().SubmitTx(Arg.Is <Transaction>(tx => tx.Timestamp != UInt256.Zero), TxHandlingOptions.PersistentBroadcast);
        }
Ejemplo n.º 3
0
        public Keccak SendTransaction(Transaction tx, TxHandlingOptions txHandlingOptions)
        {
            // TODO: Move to Uint256 when we support division
            ulong minGasPrice = (ulong)CurrentMinGasPrice();

            tx.GasPrice = minGasPrice * _percentDelta / 100;
            return(_txSender.SendTransaction(tx, txHandlingOptions));
        }
Ejemplo n.º 4
0
        public ValueTask <Keccak> SendTransaction(Transaction tx, TxHandlingOptions txHandlingOptions)
        {
            UInt256 minGasPrice = CurrentMinGasPrice();
            UInt256 txGasPrice  = minGasPrice * _percentDelta / 100;

            tx.GasPrice = UInt256.Max(txGasPrice, _miningConfig.MinGasPrice);
            return(_txSender.SendTransaction(tx, txHandlingOptions));
        }
Ejemplo n.º 5
0
        public ValueTask <(Keccak, AcceptTxResult?)> SendTransaction(Transaction tx, TxHandlingOptions txHandlingOptions)
        {
            UInt256 gasPriceEstimated = _gasPriceOracle.GetGasPriceEstimate() * _percentDelta / 100;

            tx.DecodedMaxFeePerGas = gasPriceEstimated;
            tx.GasPrice            = gasPriceEstimated;
            return(_txSender.SendTransaction(tx, txHandlingOptions));
        }
Ejemplo n.º 6
0
        private static void SendTransaction(ReportType reportType, ITxSender txSender, Transaction transaction)
        {
            TxHandlingOptions handlingOptions = reportType switch
            {
                ReportType.Benign => TxHandlingOptions.ManagedNonce,
                ReportType.Malicious => TxHandlingOptions.ManagedNonce | TxHandlingOptions.PersistentBroadcast,
                _ => TxHandlingOptions.ManagedNonce
            };

            txSender.SendTransaction(transaction, handlingOptions);
        }
Ejemplo n.º 7
0
        public async Task send_own_transaction_should_invoke_blockchain_bridge_send_transaction_and_return_hash()
        {
            var transaction = Build.A.Transaction.TestObject;
            var hash        = TestItem.KeccakA;

            _txSender.SendTransaction(transaction, TxHandlingOptions.PersistentBroadcast | TxHandlingOptions.ManagedNonce).Returns(hash);
            var result = await _ndmBridge.SendOwnTransactionAsync(transaction);

            _txSender.Received().SendTransaction(transaction, TxHandlingOptions.PersistentBroadcast | TxHandlingOptions.ManagedNonce);
            result.Should().Be(hash);
        }
Ejemplo n.º 8
0
 public Keccak SendTransaction(Transaction tx, TxHandlingOptions txHandlingOptions)
 {
     try
     {
         return(_txSender.SendTransaction(tx, txHandlingOptions));
     }
     catch (SecurityException e)
     {
         throw new SecurityException("Your account is locked. Unlock the account via CLI, personal_unlockAccount or use Trusted Signer.", e);
     }
 }
Ejemplo n.º 9
0
        public ValueTask <Keccak> SendTransaction(Transaction tx, TxHandlingOptions txHandlingOptions)
        {
            (UInt256 minFeeCap, UInt256 minGasPremium) = CurrentMinGas();
            UInt256 txFeeCap     = minFeeCap * _percentDelta / 100;
            UInt256 txGasPremium = minGasPremium * _percentDelta / 100;

            tx.DecodedFeeCap = UInt256.Max(txFeeCap, _miningConfig.MinGasPrice);
            tx.GasPrice      = txGasPremium;
            tx.Type          = TxType.EIP1559;
            return(_txSender.SendTransaction(tx, txHandlingOptions));
        }
Ejemplo n.º 10
0
        private async Task <Keccak> DeployBytecode(Address address, string contractType, byte[] bytecode)
        {
            Transaction tx = new();

            tx.Value         = 0;
            tx.Data          = bytecode;
            tx.GasLimit      = 1000000;
            tx.GasPrice      = 20.GWei();
            tx.SenderAddress = address;

            Keccak txHash = await _txSender.SendTransaction(tx, TxHandlingOptions);

            _logger.Info($"Sent transaction at price {tx.GasPrice} to {tx.SenderAddress}");
            _logger.Info($"Contract {contractType} has been deployed");
            return(txHash);
        }
Ejemplo n.º 11
0
        private async Task <ResultWrapper <Keccak> > SendTx(Transaction tx)
        {
            try
            {
                Keccak txHash = await _txSender.SendTransaction(tx, TxHandlingOptions.PersistentBroadcast);

                return(ResultWrapper <Keccak> .Success(txHash));
            }
            catch (SecurityException e)
            {
                return(ResultWrapper <Keccak> .Fail(e.Message, ErrorCodes.AccountLocked));
            }
            catch (Exception e)
            {
                return(ResultWrapper <Keccak> .Fail(e.Message, ErrorCodes.TransactionRejected));
            }
        }
Ejemplo n.º 12
0
 public ValueTask <Keccak?> SendOwnTransactionAsync(Transaction transaction)
 => _txSender.SendTransaction(transaction, TxHandlingOptions.ManagedNonce | TxHandlingOptions.PersistentBroadcast);
Ejemplo n.º 13
0
 private static void SendTransaction(ITxSender txSender, Transaction transaction)
 {
     txSender.SendTransaction(transaction, TxHandlingOptions.ManagedNonce | TxHandlingOptions.PersistentBroadcast);
 }