コード例 #1
0
        public void should_ignore_already_known()
        {
            _transactionPool = CreatePool(_noTransactionStorage);
            Transaction          tx      = Build.A.Transaction.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA, RopstenSpecProvider.ByzantiumBlockNumber).TestObject;
            AddTransactionResult result1 = _transactionPool.AddTransaction(tx, 1);
            AddTransactionResult result2 = _transactionPool.AddTransaction(tx, 1);

            _transactionPool.GetPendingTransactions().Length.Should().Be(1);
            result1.Should().Be(AddTransactionResult.Added);
            result2.Should().Be(AddTransactionResult.AlreadyKnown);
        }
コード例 #2
0
        private void TimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            _timer.Interval = RandomizeDelay().TotalMilliseconds;
            _logger.Debug($"Generating a test transaction for testing ({_count}).");

            Transaction tx = new Transaction();

            tx.GasPrice      = 1;
            tx.GasLimit      = 21000;
            tx.To            = new Address(0x0f.ToBigEndianByteArray().PadLeft(20));
            tx.Nonce         = _nonce++;
            tx.Value         = 1;
            tx.Data          = new byte[0];
            tx.Nonce         = _count++;
            tx.SenderAddress = SenderAddress;
            _ecdsa.Sign(_privateKey, tx, 1);
            Address address = _ecdsa.RecoverAddress(tx, 1);

            if (address != tx.SenderAddress)
            {
                throw new InvalidDataException($"{nameof(TestTransactionsGenerator)} producing invalid transactions");
            }

            tx.Hash = Transaction.CalculateHash(tx);

            _transactionPool.AddTransaction(tx, 1);
            _logger.Debug($"Generated a test transaction for testing ({_count - 1}).");
        }
コード例 #3
0
        public Keccak SendTransaction(Transaction transaction)
        {
            try
            {
                _readerWriterLockSlim.EnterWriteLock();
                _stateProvider.StateRoot = _blockTree.Head.StateRoot;

                if (transaction.SenderAddress == null)
                {
                    transaction.SenderAddress = _wallet.GetAccounts()[0];
                }

                transaction.Nonce = _stateProvider.GetNonce(transaction.SenderAddress);
                _wallet.Sign(transaction, _blockTree.ChainId);
                transaction.Hash = Transaction.CalculateHash(transaction);

                if (_stateProvider.GetNonce(transaction.SenderAddress) != transaction.Nonce)
                {
                    throw new InvalidOperationException("Invalid nonce");
                }

                _transactionPool.AddTransaction(transaction, _blockTree.Head.Number);

                _stateProvider.Reset();
                return(transaction.Hash);
            }
            finally
            {
                _readerWriterLockSlim.ExitWriteLock();
            }
        }
コード例 #4
0
        public void should_ignore_old_scheme_signatures()
        {
            _transactionPool = CreatePool(_noTransactionStorage);
            Transaction          tx     = Build.A.Transaction.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA, 1).TestObject;
            AddTransactionResult result = _transactionPool.AddTransaction(tx, 1);

            _transactionPool.GetPendingTransactions().Length.Should().Be(0);
            result.Should().Be(AddTransactionResult.OldScheme);
        }
コード例 #5
0
        public void should_add_valid_transactions()
        {
            _transactionPool = CreatePool(_noTransactionStorage);
            Transaction          tx     = Build.A.Transaction.SignedAndResolved(_ethereumSigner, TestItem.PrivateKeyA, RopstenSpecProvider.ByzantiumBlockNumber).TestObject;
            AddTransactionResult result = _transactionPool.AddTransaction(tx, 1);

            _transactionPool.GetPendingTransactions().Length.Should().Be(1);
            result.Should().Be(AddTransactionResult.Added);
        }
コード例 #6
0
 private void Handle(TransactionsMessage msg)
 {
     for (int i = 0; i < msg.Transactions.Length; i++)
     {
         var transaction = msg.Transactions[i];
         transaction.DeliveredBy = NodeId.PublicKey;
         transaction.Timestamp   = _timestamp.EpochSeconds;
         _transactionPool.AddTransaction(transaction, _blockTree.Head.Number);
     }
 }
コード例 #7
0
        public void should_ignore_transactions_with_different_chain_id()
        {
            _transactionPool = CreatePool(_noTransactionStorage);
            EthereumEcdsa        ecdsa  = new EthereumEcdsa(MainNetSpecProvider.Instance, _logManager);
            Transaction          tx     = Build.A.Transaction.SignedAndResolved(ecdsa, TestItem.PrivateKeyA, MainNetSpecProvider.ByzantiumBlockNumber).TestObject;
            AddTransactionResult result = _transactionPool.AddTransaction(tx, 1);

            _transactionPool.GetPendingTransactions().Length.Should().Be(0);
            result.Should().Be(AddTransactionResult.InvalidChainId);
        }
コード例 #8
0
        public Keccak SendTransaction(Transaction transaction)
        {
            _stateProvider.StateRoot = _blockTree.Head.StateRoot;

            transaction.Hash      = Transaction.CalculateHash(transaction);
            transaction.Timestamp = _timestamp.EpochSeconds;

            _transactionPool.AddTransaction(transaction, _blockTree.Head.Number);

            _stateProvider.Reset();
            return(transaction.Hash);
        }
コード例 #9
0
        private void Handle(TransactionsMessage msg)
        {
            for (int i = 0; i < msg.Transactions.Length; i++)
            {
                var transaction = msg.Transactions[i];
                transaction.DeliveredBy = NodeId.PublicKey;
                transaction.Timestamp   = _timestamp.EpochSeconds;
                AddTransactionResult result = _transactionPool.AddTransaction(transaction, _blockTree.Head.Number);
                if (result == AddTransactionResult.AlreadyKnown)
                {
                    _notAcceptedTxsSinceLastCheck++;
                }

                if (Logger.IsTrace)
                {
                    Logger.Trace($"{NodeId} sent {transaction.Hash} and it was {result} (chain ID = {transaction.Signature.GetChainId})");
                }
            }
        }