Search in sources :

Example 16 with AgentPo

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();
}
Also used : DepositPo(io.nuls.consensus.poc.storage.po.DepositPo) StopAgentTransaction(io.nuls.consensus.poc.protocol.tx.StopAgentTransaction) DepositTransaction(io.nuls.consensus.poc.protocol.tx.DepositTransaction) RedPunishTransaction(io.nuls.consensus.poc.protocol.tx.RedPunishTransaction) Transaction(io.nuls.kernel.model.Transaction) CancelDepositTransaction(io.nuls.consensus.poc.protocol.tx.CancelDepositTransaction) RedPunishTransaction(io.nuls.consensus.poc.protocol.tx.RedPunishTransaction) CancelDepositTransaction(io.nuls.consensus.poc.protocol.tx.CancelDepositTransaction) NulsDigestData(io.nuls.kernel.model.NulsDigestData) StopAgentTransaction(io.nuls.consensus.poc.protocol.tx.StopAgentTransaction) HashSet(java.util.HashSet) AgentPo(io.nuls.consensus.poc.storage.po.AgentPo)

Example 17 with AgentPo

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;
}
Also used : AgentPo(io.nuls.consensus.poc.storage.po.AgentPo)

Example 18 with AgentPo

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);
}
Also used : NulsDigestData(io.nuls.kernel.model.NulsDigestData) AgentPo(io.nuls.consensus.poc.storage.po.AgentPo) BaseTest(io.nuls.consensus.poc.storage.BaseTest) Test(org.junit.Test)

Example 19 with 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);
}
Also used : NulsDigestData(io.nuls.kernel.model.NulsDigestData) AgentPo(io.nuls.consensus.poc.storage.po.AgentPo) BaseTest(io.nuls.consensus.poc.storage.BaseTest) Test(org.junit.Test)

Example 20 with AgentPo

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);
}
Also used : NulsDigestData(io.nuls.kernel.model.NulsDigestData) AgentPo(io.nuls.consensus.poc.storage.po.AgentPo) BaseTest(io.nuls.consensus.poc.storage.BaseTest) Test(org.junit.Test)

Aggregations

AgentPo (io.nuls.consensus.poc.storage.po.AgentPo)21 NulsDigestData (io.nuls.kernel.model.NulsDigestData)8 DepositPo (io.nuls.consensus.poc.storage.po.DepositPo)7 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)6 ValidateResult (io.nuls.kernel.validate.ValidateResult)6 BaseTest (io.nuls.consensus.poc.storage.BaseTest)4 NulsException (io.nuls.kernel.exception.NulsException)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Agent (io.nuls.consensus.poc.protocol.entity.Agent)3 RedPunishData (io.nuls.consensus.poc.protocol.entity.RedPunishData)3 RedPunishTransaction (io.nuls.consensus.poc.protocol.tx.RedPunishTransaction)3 StopAgentTransaction (io.nuls.consensus.poc.protocol.tx.StopAgentTransaction)3 BlockHeader (io.nuls.kernel.model.BlockHeader)3 HashSet (java.util.HashSet)3 DepositTransaction (io.nuls.consensus.poc.protocol.tx.DepositTransaction)2 Coin (io.nuls.kernel.model.Coin)2 Na (io.nuls.kernel.model.Na)2 Transaction (io.nuls.kernel.model.Transaction)2 TransactionSignature (io.nuls.kernel.script.TransactionSignature)2