Search in sources :

Example 11 with Transaction

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;
}
Also used : Transaction(io.nuls.kernel.model.Transaction) TransactionProcessor(io.nuls.kernel.processor.TransactionProcessor) ArrayList(java.util.ArrayList)

Example 12 with Transaction

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");
}
Also used : TestTransaction(io.nuls.db.entity.TestTransaction) Transaction(io.nuls.kernel.model.Transaction) TestTransaction(io.nuls.db.entity.TestTransaction)

Example 13 with Transaction

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);
}
Also used : ArrayList(java.util.ArrayList) UnconfirmedTxPo(io.nuls.account.ledger.storage.po.UnconfirmedTxPo) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) NulsException(io.nuls.kernel.exception.NulsException) Result(io.nuls.kernel.model.Result) Entry(io.nuls.db.model.Entry) Transaction(io.nuls.kernel.model.Transaction) NulsByteBuffer(io.nuls.kernel.utils.NulsByteBuffer)

Example 14 with Transaction

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();
    }
}
Also used : Transaction(io.nuls.kernel.model.Transaction) UnconfirmedTxPo(io.nuls.account.ledger.storage.po.UnconfirmedTxPo) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) NulsException(io.nuls.kernel.exception.NulsException)

Example 15 with Transaction

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);
}
Also used : TestTransaction(io.nuls.consensus.poc.TestTransaction) Transaction(io.nuls.kernel.model.Transaction) TestTransaction(io.nuls.consensus.poc.TestTransaction) Test(org.junit.Test)

Aggregations

Transaction (io.nuls.kernel.model.Transaction)38 NulsDigestData (io.nuls.kernel.model.NulsDigestData)12 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)8 NulsException (io.nuls.kernel.exception.NulsException)7 ValidateResult (io.nuls.kernel.validate.ValidateResult)7 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 Result (io.nuls.kernel.model.Result)4 TransferTransaction (io.nuls.protocol.model.tx.TransferTransaction)4 CreateAgentTransaction (io.nuls.consensus.poc.protocol.tx.CreateAgentTransaction)3 RedPunishTransaction (io.nuls.consensus.poc.protocol.tx.RedPunishTransaction)3 NulsByteBuffer (io.nuls.kernel.utils.NulsByteBuffer)3 UnconfirmedTxPo (io.nuls.account.ledger.storage.po.UnconfirmedTxPo)2 StopAgentTransaction (io.nuls.consensus.poc.protocol.tx.StopAgentTransaction)2 AgentPo (io.nuls.consensus.poc.storage.po.AgentPo)2 Coin (io.nuls.kernel.model.Coin)2 TransactionProcessor (io.nuls.kernel.processor.TransactionProcessor)2 Alias (io.nuls.account.model.Alias)1