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);
}
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;
}
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);
}
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;
}
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;
}
}
Aggregations