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