Search in sources :

Example 66 with AionTransaction

use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.

the class PendingTxCacheTest method maxPendingSizeTest7.

@Test
public void maxPendingSizeTest7() {
    PendingTxCache cache = new PendingTxCache(1);
    List<AionTransaction> txn = getMockTransaction(0, 659, 0);
    List<AionTransaction> newCache = new ArrayList<>();
    for (AionTransaction tx : txn) {
        newCache.add(cache.addCacheTx(tx).get(0));
    }
    assertTrue(newCache.size() == 659);
    Map<BigInteger, AionTransaction> cacheMap = cache.geCacheTx(Address.wrap(key.get(0).getAddress()));
    assertTrue(cacheMap.size() == 659);
    AionTransaction tx = getMockBigTransaction(100, 1, 0, 199_500).get(0);
    newCache = cache.addCacheTx(tx);
    assertTrue(newCache.size() == 659);
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction) Test(org.junit.Test)

Example 67 with AionTransaction

use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.

the class PendingTxCacheTest method getMockTransaction.

private List<AionTransaction> getMockTransaction(int startNonce, int num, int keyIndex) {
    List<AionTransaction> txn = new ArrayList<>();
    for (int i = startNonce; i < startNonce + num; i++) {
        AionTransaction tx = new AionTransaction(BigInteger.valueOf(i).toByteArray(), Address.wrap(key.get(keyIndex).getAddress()), Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
        tx.sign(key.get(keyIndex));
        txn.add(tx);
    }
    return txn;
}
Also used : ArrayList(java.util.ArrayList) AionTransaction(org.aion.zero.types.AionTransaction)

Example 68 with AionTransaction

use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.

the class PendingTxCacheTest method maxPendingSizeTest3.

@Test
public void maxPendingSizeTest3() {
    PendingTxCache cache = new PendingTxCache(1);
    List<AionTransaction> txn = getMockTransaction(0, 659, 0);
    List<AionTransaction> newCache = new ArrayList<>();
    for (AionTransaction tx : txn) {
        newCache.add(cache.addCacheTx(tx).get(0));
    }
    assertTrue(newCache.size() == 659);
    AionTransaction tx = getMockBigTransaction(50, 1, 0, 200).get(0);
    newCache = cache.addCacheTx(tx);
    assertTrue(newCache.size() == 658);
    Map<BigInteger, AionTransaction> cacheMap = cache.geCacheTx(Address.wrap(key.get(0).getAddress()));
    assertTrue(cacheMap.size() == 658);
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction) Test(org.junit.Test)

Example 69 with AionTransaction

use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.

the class ApiAion method getTransactionCount.

public long getTransactionCount(Address addr, long blkNr) {
    AionBlock pBlk = this.getBlock(blkNr);
    if (pBlk == null) {
        LOG.error("ApiAion.getTransactionByBlockNumberAndIndex - can't find the block by the block number");
        return -1;
    }
    long cnt = 0;
    List<AionTransaction> txList = pBlk.getTransactionsList();
    for (AionTransaction tx : txList) {
        if (addr.equals(tx.getFrom())) {
            cnt++;
        }
    }
    return cnt;
}
Also used : AionTransaction(org.aion.zero.types.AionTransaction) AionBlock(org.aion.zero.impl.types.AionBlock)

Example 70 with AionTransaction

use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.

the class ApiAion method sendTransaction.

public byte[] sendTransaction(ArgTxCall _params) {
    Address from = _params.getFrom();
    if (from == null || from.equals(Address.EMPTY_ADDRESS())) {
        LOG.error("<send-transaction msg=invalid-from-address>");
        return null;
    }
    ECKey key = this.getAccountKey(from.toString());
    if (key == null) {
        LOG.error("<send-transaction msg=account-not-found>");
        return null;
    }
    try {
        synchronized (pendingState) {
            // TODO : temp set nrg & price to 1
            byte[] nonce = (!_params.getNonce().equals(BigInteger.ZERO)) ? _params.getNonce().toByteArray() : pendingState.bestNonce(Address.wrap(key.getAddress())).toByteArray();
            AionTransaction tx = new AionTransaction(nonce, _params.getTo(), _params.getValue().toByteArray(), _params.getData(), _params.getNrg(), _params.getNrgPrice());
            tx.sign(key);
            pendingState.addPendingTransaction(tx);
            return tx.getHash();
        }
    } catch (Exception ex) {
        return null;
    }
}
Also used : Address(org.aion.base.type.Address) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.zero.types.AionTransaction)

Aggregations

AionTransaction (org.aion.zero.types.AionTransaction)75 Test (org.junit.Test)44 BigInteger (java.math.BigInteger)30 ITransaction (org.aion.base.type.ITransaction)26 Address (org.aion.base.type.Address)23 TxPoolA0 (org.aion.txpool.zero.TxPoolA0)21 AionBlock (org.aion.zero.impl.types.AionBlock)17 ArrayList (java.util.ArrayList)16 ECKey (org.aion.crypto.ECKey)12 AionTxReceipt (org.aion.zero.types.AionTxReceipt)7 TxRecpt (org.aion.api.server.types.TxRecpt)4 ImportResult (org.aion.mcf.core.ImportResult)4 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)4 ByteString (com.google.protobuf.ByteString)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ByteBuffer (java.nio.ByteBuffer)2 java.util (java.util)2 Entry (java.util.Map.Entry)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 Collectors (java.util.stream.Collectors)2