Search in sources :

Example 16 with Transaction

use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.

the class StopAgentTxProcessor method conflictDetect.

@Override
public ValidateResult conflictDetect(List<Transaction> txList) {
    if (txList == null || txList.isEmpty()) {
        return ValidateResult.getSuccessResult();
    }
    Set<NulsDigestData> hashSet = new HashSet<>();
    Set<String> addressSet = new HashSet<>();
    for (Transaction tx : txList) {
        if (tx.getType() == ConsensusConstant.TX_TYPE_RED_PUNISH) {
            RedPunishTransaction transaction = (RedPunishTransaction) tx;
            addressSet.add(AddressTool.getStringAddressByBytes(transaction.getTxData().getAddress()));
        }
    }
    for (Transaction tx : txList) {
        if (tx.getType() == ConsensusConstant.TX_TYPE_STOP_AGENT) {
            StopAgentTransaction transaction = (StopAgentTransaction) tx;
            if (!hashSet.add(transaction.getTxData().getCreateTxHash())) {
                ValidateResult result = ValidateResult.getFailedResult(this.getClass().getName(), TransactionErrorCode.TRANSACTION_REPEATED);
                result.setData(transaction);
                return result;
            }
            if (transaction.getTxData().getAddress() == null) {
                CreateAgentTransaction agentTransaction = (CreateAgentTransaction) ledgerService.getTx(transaction.getTxData().getCreateTxHash());
                if (null == agentTransaction) {
                    ValidateResult result = ValidateResult.getFailedResult(this.getClass().getName(), PocConsensusErrorCode.AGENT_NOT_EXIST);
                    result.setData(transaction);
                    return result;
                }
                transaction.getTxData().setAddress(agentTransaction.getTxData().getAgentAddress());
            }
            AgentPo po = agentStorageService.get(transaction.getTxData().getCreateTxHash());
            if (null == po || po.getDelHeight() > 0) {
                ValidateResult result = ValidateResult.getFailedResult(this.getClass().getName(), PocConsensusErrorCode.AGENT_STOPPED);
                result.setData(transaction);
                return result;
            }
            if (addressSet.contains(AddressTool.getStringAddressByBytes(transaction.getTxData().getAddress()))) {
                ValidateResult result = ValidateResult.getFailedResult(this.getClass().getName(), PocConsensusErrorCode.AGENT_STOPPED);
                result.setData(transaction);
                return result;
            }
        }
    }
    return ValidateResult.getSuccessResult();
}
Also used : StopAgentTransaction(io.nuls.consensus.poc.protocol.tx.StopAgentTransaction) CreateAgentTransaction(io.nuls.consensus.poc.protocol.tx.CreateAgentTransaction) RedPunishTransaction(io.nuls.consensus.poc.protocol.tx.RedPunishTransaction) Transaction(io.nuls.kernel.model.Transaction) RedPunishTransaction(io.nuls.consensus.poc.protocol.tx.RedPunishTransaction) ValidateResult(io.nuls.kernel.validate.ValidateResult) NulsDigestData(io.nuls.kernel.model.NulsDigestData) CreateAgentTransaction(io.nuls.consensus.poc.protocol.tx.CreateAgentTransaction) StopAgentTransaction(io.nuls.consensus.poc.protocol.tx.StopAgentTransaction) HashSet(java.util.HashSet) AgentPo(io.nuls.consensus.poc.storage.po.AgentPo)

Example 17 with Transaction

use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.

the class TransactionCacheStorageServiceImpl method getTx.

@Override
public Transaction getTx(NulsDigestData hash) {
    if (hash == null) {
        return null;
    }
    byte[] hashBytes = null;
    try {
        hashBytes = hash.serialize();
    } catch (IOException e) {
        Log.error(e);
        throw new NulsRuntimeException(e);
    }
    byte[] txBytes = dbService.get(TRANSACTION_CACHE_KEY_NAME, hashBytes);
    Transaction tx = null;
    if (null != txBytes) {
        try {
            tx = TransactionManager.getInstance(new NulsByteBuffer(txBytes, 0));
        } catch (Exception e) {
            Log.error(e);
            return null;
        }
    }
    return tx;
}
Also used : Transaction(io.nuls.kernel.model.Transaction) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) IOException(java.io.IOException) NulsException(io.nuls.kernel.exception.NulsException) NulsByteBuffer(io.nuls.kernel.utils.NulsByteBuffer)

Example 18 with Transaction

use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.

the class TemporaryCacheManagerTest method cacheTx.

/**
 * 测试交易的缓存处理流程:
 * 1. 先测试放入缓存,不出现异常视为成功
 * 2. 测试获取刚放入的交易,获取的结果不能为空且和刚仿佛的是相同内容
 * 3. 测试删除之前放入的交易,删除后再获取应该得到null
 * 4. 重新把交易放回缓存中,调用清理方法,清理后缓存中应该没有任何小区块或者交易
 * the cache processing flow of test transaction:
 * 1. The first test is put into the cache, and no exceptions are deemed to be successful.
 * 2. Test to obtain the newly placed transaction, the results obtained cannot be empty and the same content as the new one.
 * 3. Delete the transaction that was put in before the test is deleted, and then get null after deleting.
 * 4. Return the transaction to the cache, call the cleaning method, and there should be no blocks or transactions in the cache.
 */
@Test
public void cacheTx() {
    Transaction tx = new CacheTestTx();
    tx.setTime(1234567654L);
    try {
        tx.setHash(NulsDigestData.calcDigestData(tx.serializeForHash()));
    } catch (IOException e) {
        Log.error(e);
    }
    manager.cacheTx(tx);
    assertTrue(true);
    getTx(tx.getHash(), tx);
}
Also used : Transaction(io.nuls.kernel.model.Transaction) IOException(java.io.IOException) Test(org.junit.Test)

Example 19 with Transaction

use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.

the class TemporaryCacheManagerTest method getTx.

/**
 * 测试获取已存在缓存中的交易
 * <p>
 * The test gets the transaction in the cache.
 *
 * @param hash 已存入的交易的摘要对象,A quick summary of the transaction that has been deposited.
 * @param tx   已存入缓存的交易,The cached Transaction is fast.
 */
private void getTx(NulsDigestData hash, Transaction tx) {
    Transaction txGoted = manager.getTx(hash);
    assertNotNull(tx);
    assertEquals(tx.getTime(), txGoted.getTime());
}
Also used : Transaction(io.nuls.kernel.model.Transaction)

Example 20 with Transaction

use of io.nuls.kernel.model.Transaction in project nuls by nuls-io.

the class TxGroup method serializeToStream.

@Override
protected void serializeToStream(NulsOutputStreamBuffer stream) throws IOException {
    stream.writeNulsData(requestHash);
    stream.writeVarInt(txList.size());
    for (Transaction data : txList) {
        stream.writeNulsData(data);
    }
}
Also used : Transaction(io.nuls.kernel.model.Transaction)

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