Search in sources :

Example 6 with TxResponse

use of org.aion.zero.impl.types.TxResponse in project aion by aionnetwork.

the class AionPendingStateImpl method processTxToTxPool.

private TxResponse processTxToTxPool(AionTransaction tx, int fetchLimit, List<AionTransaction> newPending) {
    TxResponse response = addPendingTransactionInner(tx);
    if (response.equals(TxResponse.SUCCESS)) {
        newPending.add(tx);
        addPendingTxToBackupDatabase(tx);
        Map<BigInteger, AionTransaction> cachedTxWithSender = pendingTxCache.getCacheTxBySender(tx.getSenderAddress());
        if (cachedTxWithSender != null) {
            LOGGER_TX.debug("add Transaction from cache, sender: {}, size: {}", tx.getSenderAddress(), cachedTxWithSender.size());
            BigInteger newCachedTxNonce = tx.getNonceBI().add(BigInteger.ONE);
            AionTransaction newCachedTx = cachedTxWithSender.get(newCachedTxNonce);
            while (response.equals(TxResponse.SUCCESS) && newCachedTx != null && fetchLimit-- > 0 && !txPool.isFull()) {
                LOGGER_TX.debug("add Transaction from cache, sender: {}, nonce: {}", newCachedTx.getSenderAddress(), newCachedTxNonce);
                response = addPendingTransactionInner(newCachedTx);
                if (response.equals(TxResponse.SUCCESS)) {
                    newPending.add(newCachedTx);
                    addPendingTxToBackupDatabase(newCachedTx);
                    pendingTxCache.removeTransaction(newCachedTx.getSenderAddress(), newCachedTxNonce);
                    newCachedTxNonce = newCachedTxNonce.add(BigInteger.ONE);
                    newCachedTx = cachedTxWithSender.get(newCachedTxNonce);
                }
            }
        }
    }
    return response;
}
Also used : BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) TxResponse(org.aion.zero.impl.types.TxResponse)

Example 7 with TxResponse

use of org.aion.zero.impl.types.TxResponse in project aion by aionnetwork.

the class TXValidatorTest method validateTxSignatureSwapForkEnabledReceiverAddressIsZeroTest.

@Test
public void validateTxSignatureSwapForkEnabledReceiverAddressIsZeroTest() {
    boolean signatureSwapEnabled = true;
    AionTransaction tx = AionTransaction.create(key, nonce, ZERO_ADDRESS, value, data, nrg, nrgPrice, type, null);
    TxResponse response = TXValidator.validateTx(tx, unityForkEnabled, signatureSwapEnabled);
    assertEquals(TxResponse.SUCCESS, response);
}
Also used : AionTransaction(org.aion.base.AionTransaction) TxResponse(org.aion.zero.impl.types.TxResponse) Test(org.junit.Test)

Example 8 with TxResponse

use of org.aion.zero.impl.types.TxResponse in project aion by aionnetwork.

the class TXValidatorTest method validateTxSignatureSwapForkDisabledReceiverAddressTest.

@Test
public void validateTxSignatureSwapForkDisabledReceiverAddressTest() {
    boolean signatureSwapEnabled = false;
    byte[] dest = RandomUtils.nextBytes(32);
    dest[0] = (byte) 0xa1;
    AionTransaction tx = AionTransaction.create(key, nonce, new AionAddress(dest), value, data, nrg, nrgPrice, type, null);
    TxResponse response = TXValidator.validateTx(tx, unityForkEnabled, signatureSwapEnabled);
    assertEquals(TxResponse.SUCCESS, response);
}
Also used : AionAddress(org.aion.types.AionAddress) AionTransaction(org.aion.base.AionTransaction) TxResponse(org.aion.zero.impl.types.TxResponse) Test(org.junit.Test)

Aggregations

TxResponse (org.aion.zero.impl.types.TxResponse)8 AionTransaction (org.aion.base.AionTransaction)7 Test (org.junit.Test)4 AionAddress (org.aion.types.AionAddress)3 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)1 PooledTransaction (org.aion.base.PooledTransaction)1 ECKey (org.aion.crypto.ECKey)1 ContractInfo (org.aion.precompiled.ContractInfo)1