use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.
the class TransactionManager method getProcessorList.
public static List<TransactionProcessor> getProcessorList(Class<? extends Transaction> txClass) {
List<TransactionProcessor> list = new ArrayList<>();
Class clazz = txClass;
while (!clazz.equals(Transaction.class)) {
TransactionProcessor txService = TransactionManager.getProcessor(clazz);
if (null != txService) {
list.add(0, txService);
}
clazz = clazz.getSuperclass();
}
return list;
}
use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.
the class PerformanceTest method initData.
private void initData() throws IOException {
this.txList = new ArrayList<>();
for (int i = 0; i < 200000; i++) {
Transaction tx = new TestTransaction();
tx.setTime(1);
tx.setRemark("sdfsdfsdfsdfsdfsdfaaadsfasdfsadfsdfasdfasdfasdfasdfasdfsadfaaaaaaaaaaaaaaaaaaaaaabsdsadfsadfsdfsdfsdfsdfsdfsdfsdfaaadsfasdfsadfsdfasdfasdfasdfasdfasdfsadfaaaaaaaaaaaaaaaaaaaaaabsdsadfsadfsdfsdfsdfsdfsdfsdfsdfaa".getBytes());
txList.add(tx);
}
long start = System.currentTimeMillis();
for (Transaction tx : txList) {
dbService.putModel(areaName, tx.getHash().serialize(), tx);
}
System.out.println("存入20万条用时:" + (System.currentTimeMillis() - start) + "ms");
start = System.currentTimeMillis();
for (int i = 0; i < 200000; i = i + 2) {
dbService.getModel(areaName, txList.get(i).getHash().serialize());
}
System.out.println("查询10万次用时:" + (System.currentTimeMillis() - start) + "ms");
start = System.currentTimeMillis();
for (int i = 0; i < 200000; i = i + 2) {
dbService.delete(areaName, txList.get(i).getHash().serialize());
}
System.out.println("删除10万次用时:" + (System.currentTimeMillis() - start) + "ms");
}
use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.
the class UnconfiredmTransactionStorageImpl method loadAllUnconfirmedList.
@Override
public Result<List<Transaction>> loadAllUnconfirmedList() {
Result result;
List<UnconfirmedTxPo> tmpList = new ArrayList<>();
List<Entry<byte[], byte[]>> txs = dbService.entryList(AccountLedgerStorageConstant.DB_NAME_ACCOUNT_LEDGER_TX);
for (Entry<byte[], byte[]> txEntry : txs) {
try {
UnconfirmedTxPo tmpTx = new UnconfirmedTxPo(txEntry.getValue());
if (tmpTx != null) {
NulsByteBuffer buffer = new NulsByteBuffer(txEntry.getKey(), 0);
tmpTx.getTx().setHash(buffer.readHash());
tmpList.add(tmpTx);
}
} catch (Exception e) {
Log.warn("parse local tx error", e);
}
}
tmpList.sort(new Comparator<UnconfirmedTxPo>() {
@Override
public int compare(UnconfirmedTxPo o1, UnconfirmedTxPo o2) {
return (int) (o1.getSequence() - o2.getSequence());
}
});
List<Transaction> resultList = new ArrayList<>();
for (UnconfirmedTxPo po : tmpList) {
resultList.add(po.getTx());
}
return Result.getSuccess().setData(resultList);
}
use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.
the class UnconfiredmTransactionStorageImpl method getUnconfirmedTx.
@Override
public Result<Transaction> getUnconfirmedTx(NulsDigestData hash) {
try {
byte[] txBytes = dbService.get(AccountLedgerStorageConstant.DB_NAME_ACCOUNT_LEDGER_TX, hash.serialize());
if (txBytes == null) {
return Result.getSuccess();
}
UnconfirmedTxPo po = new UnconfirmedTxPo(txBytes);
Transaction tx = po.getTx();
return Result.getSuccess().setData(tx);
} catch (Exception e) {
return Result.getFailed();
}
}
use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.
the class TxMemoryPoolTest method test.
@Test
public void test() {
assertNotNull(txMemoryPool);
Transaction tx = new TestTransaction();
boolean success = txMemoryPool.add(tx, false);
assertTrue(success);
Transaction tempTx = txMemoryPool.get();
assertEquals(tx, tempTx);
tempTx = txMemoryPool.get();
assertNull(tempTx);
// tempTx = txMemoryPool.get(tx.getTx().getHash());
// assertNull(tempTx);
//
// txMemoryPool.add(tx, false);
// tempTx = txMemoryPool.get(tx.getTx().getHash());
// assertEquals(tempTx, tx);
//
// tempTx = txMemoryPool.get(tx.getTx().getHash());
// assertEquals(tempTx, tx);
Transaction tx2 = new TestTransaction();
txMemoryPool.add(tx2, true);
tempTx = txMemoryPool.get();
assertNotNull(tempTx);
assertEquals(tempTx, tx);
tempTx = txMemoryPool.get();
assertNotNull(tempTx);
assertEquals(tempTx, tx2);
tempTx = txMemoryPool.get();
assertNull(tempTx);
txMemoryPool.add(tx2, true);
List<Transaction> list = txMemoryPool.getAll();
assertEquals(list.size(), 0);
list = txMemoryPool.getAllOrphan();
assertEquals(list.size(), 1);
success = txMemoryPool.exist(tx.getHash());
assertFalse(success);
success = txMemoryPool.exist(tx2.getHash());
assertTrue(success);
success = txMemoryPool.remove(tx2.getHash());
assertTrue(success);
success = txMemoryPool.exist(tx2.getHash());
assertFalse(success);
}
Aggregations