use of io.nuls.consensus.poc.storage.po.AgentPo in project nuls by nuls-io.
the class CancelDepositTxProcessor method conflictDetect.
@Override
public ValidateResult conflictDetect(List<Transaction> txList) {
if (txList == null || txList.size() <= 1) {
return ValidateResult.getSuccessResult();
}
Set<NulsDigestData> hashSet = new HashSet<>();
Set<NulsDigestData> agentHashSet = 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()));
} else if (tx.getType() == ConsensusConstant.TX_TYPE_STOP_AGENT) {
StopAgentTransaction transaction = (StopAgentTransaction) tx;
agentHashSet.add(transaction.getTxData().getCreateTxHash());
}
}
for (Transaction tx : txList) {
if (tx.getType() == ConsensusConstant.TX_TYPE_CANCEL_DEPOSIT) {
CancelDepositTransaction transaction = (CancelDepositTransaction) tx;
if (!hashSet.add(transaction.getTxData().getJoinTxHash())) {
return ValidateResult.getFailedResult(this.getClass().getName(), TransactionErrorCode.TRANSACTION_REPEATED);
}
if (agentHashSet.contains(transaction.getTxData().getJoinTxHash())) {
return ValidateResult.getFailedResult(this.getClass().getName(), PocConsensusErrorCode.AGENT_STOPPED);
}
DepositPo depositPo = depositStorageService.get(transaction.getTxData().getJoinTxHash());
if (depositPo.getDelHeight() > 0) {
return ValidateResult.getFailedResult(this.getClass().getName(), TransactionErrorCode.TRANSACTION_REPEATED);
}
AgentPo agentPo = agentStorageService.get(depositPo.getAgentHash());
if (null == agentPo || agentPo.getDelHeight() > 0) {
return ValidateResult.getFailedResult(this.getClass().getName(), PocConsensusErrorCode.AGENT_NOT_EXIST);
}
if (addressSet.contains(AddressTool.getStringAddressByBytes(agentPo.getAgentAddress()))) {
return ValidateResult.getFailedResult(this.getClass().getName(), PocConsensusErrorCode.AGENT_PUNISHED);
}
}
}
return ValidateResult.getSuccessResult();
}
use of io.nuls.consensus.poc.storage.po.AgentPo in project nuls by nuls-io.
the class DepositTxProcessor method getAgentByAddress.
private AgentPo getAgentByAddress(byte[] address) {
List<AgentPo> agentList = agentStorageService.getList();
long startBlockHeight = NulsContext.getInstance().getBestHeight();
for (AgentPo agent : agentList) {
if (agent.getDelHeight() != -1L && agent.getDelHeight() <= startBlockHeight) {
continue;
}
if (agent.getBlockHeight() > startBlockHeight || agent.getBlockHeight() < 0L) {
continue;
}
if (Arrays.equals(address, agent.getAgentAddress())) {
return agent;
}
}
return null;
}
use of io.nuls.consensus.poc.storage.po.AgentPo in project nuls by nuls-io.
the class AgentStorageServiceTest method testDelete.
@Test
public void testDelete() {
assertNotNull(agentStorageService);
testSave();
NulsDigestData hash = NulsDigestData.calcDigestData(new byte[23]);
boolean success = agentStorageService.delete(hash);
assert (success);
AgentPo agentPo = agentStorageService.get(hash);
assertNull(agentPo);
}
use of io.nuls.consensus.poc.storage.po.AgentPo in project nuls by nuls-io.
the class AgentStorageServiceTest method testList.
@Test
public void testList() {
assertNotNull(agentStorageService);
testSave();
NulsDigestData hash = NulsDigestData.calcDigestData(new byte[20]);
AgentPo agentPo = new AgentPo();
agentPo.setAgentAddress(new byte[23]);
agentPo.setRewardAddress(new byte[23]);
agentPo.setPackingAddress(new byte[23]);
agentPo.setDeposit(Na.ZERO);
agentPo.setHash(hash);
boolean success = agentStorageService.save(agentPo);
assert (success);
List<AgentPo> list = agentStorageService.getList();
assertEquals(list.size(), 2);
NulsDigestData hash1 = NulsDigestData.calcDigestData(new byte[23]);
assertEquals(hash1, list.get(0).getHash());
assertEquals(hash, list.get(1).getHash());
int size = agentStorageService.size();
assertEquals(size, 2);
success = agentStorageService.delete(hash);
assert (success);
success = agentStorageService.delete(hash1);
assert (success);
}
use of io.nuls.consensus.poc.storage.po.AgentPo in project nuls by nuls-io.
the class AgentStorageServiceTest method testSave.
@Test
public void testSave() {
assertNotNull(agentStorageService);
NulsDigestData hash = NulsDigestData.calcDigestData(new byte[23]);
AgentPo agentPo = new AgentPo();
agentPo.setAgentAddress(new byte[23]);
agentPo.setRewardAddress(new byte[23]);
agentPo.setPackingAddress(new byte[23]);
agentPo.setDeposit(Na.ZERO);
agentPo.setHash(hash);
boolean success = agentStorageService.save(agentPo);
assert (success);
}
Aggregations