Search in sources :

Example 6 with PunishLogPo

use of io.nuls.consensus.poc.storage.po.PunishLogPo in project nuls by nuls-io.

the class YellowPunishTxProcessor method onRollback.

@Override
public Result onRollback(YellowPunishTransaction tx, Object secondaryData) {
    YellowPunishData punishData = tx.getTxData();
    List<byte[]> deletedList = new ArrayList<>();
    int deleteIndex = 1;
    for (byte[] address : punishData.getAddressList()) {
        boolean result = punishLogStorageService.delete(this.getPoKey(address, PunishType.YELLOW.getCode(), tx.getBlockHeight(), deleteIndex++));
        if (!result) {
            BlockHeader header = (BlockHeader) secondaryData;
            BlockExtendsData roundData = new BlockExtendsData(header.getExtend());
            int index = 1;
            for (byte[] bytes : deletedList) {
                PunishLogPo po = new PunishLogPo();
                po.setAddress(bytes);
                po.setHeight(tx.getBlockHeight());
                po.setRoundIndex(roundData.getRoundIndex());
                po.setTime(tx.getTime());
                po.setIndex(index++);
                po.setType(PunishType.YELLOW.getCode());
                punishLogStorageService.save(po);
            }
            throw new NulsRuntimeException(TransactionErrorCode.ROLLBACK_TRANSACTION_FAILED);
        } else {
            deletedList.add(address);
        }
    }
    return Result.getSuccess();
}
Also used : BlockExtendsData(io.nuls.consensus.poc.model.BlockExtendsData) YellowPunishData(io.nuls.consensus.poc.protocol.entity.YellowPunishData) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) BlockHeader(io.nuls.kernel.model.BlockHeader) PunishLogPo(io.nuls.consensus.poc.storage.po.PunishLogPo)

Example 7 with PunishLogPo

use of io.nuls.consensus.poc.storage.po.PunishLogPo in project nuls by nuls-io.

the class PocConsensusResource method getPunishList.

@GET
@Path("/punish/{address}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "获取惩罚记录", notes = "获取惩罚记录")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = String.class) })
public RpcClientResult getPunishList(@ApiParam(name = "address", value = "查询地址", required = true) @PathParam("address") String address, @ApiParam(name = "type", value = "惩罚类型:yellow:0,red:1", required = true) @QueryParam("type") int type) {
    byte[] addressByte = AddressTool.getAddress(address);
    if (!AddressTool.validNormalAddress(addressByte)) {
        return Result.getFailed(KernelErrorCode.PARAMETER_ERROR).toRpcClientResult();
    }
    List<PunishLogPo> punishList = null;
    if (type == 0) {
        punishList = PocConsensusContext.getChainManager().getMasterChain().getChain().getYellowPunishList();
    } else if (1 == type) {
        punishList = PocConsensusContext.getChainManager().getMasterChain().getChain().getRedPunishList();
    } else {
        return Result.getFailed(KernelErrorCode.PARAMETER_ERROR).toRpcClientResult();
    }
    List<PunishLogDTO> list = new ArrayList<>();
    for (PunishLogPo po : punishList) {
        if (!ArraysTool.arrayEquals(po.getAddress(), addressByte)) {
            continue;
        }
        list.add(new PunishLogDTO(po));
    }
    Result result = Result.getSuccess();
    result.setData(list);
    return result.toRpcClientResult();
}
Also used : PunishLogPo(io.nuls.consensus.poc.storage.po.PunishLogPo) CoinDataResult(io.nuls.account.ledger.model.CoinDataResult)

Example 8 with PunishLogPo

use of io.nuls.consensus.poc.storage.po.PunishLogPo in project nuls by nuls-io.

the class PocConsensusResource method getRedPunishByAddress.

@GET
@Path("/redPunish/{address}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "根据地址查询该账户是否被红牌惩罚过")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = Boolean.class) })
public RpcClientResult getRedPunishByAddress(@ApiParam(name = "address", value = "账户地址", required = true) @PathParam("address") String address) {
    if (!AddressTool.validAddress(address)) {
        return Result.getFailed(AccountErrorCode.ADDRESS_ERROR).toRpcClientResult();
    }
    List<PunishLogPo> list = PocConsensusContext.getChainManager().getMasterChain().getChain().getRedPunishList();
    boolean rs = false;
    for (PunishLogPo po : list) {
        if (Arrays.equals(AddressTool.getAddress(address), po.getAddress())) {
            rs = true;
            break;
        }
    }
    return Result.getSuccess().setData(rs).toRpcClientResult();
}
Also used : PunishLogPo(io.nuls.consensus.poc.storage.po.PunishLogPo)

Example 9 with PunishLogPo

use of io.nuls.consensus.poc.storage.po.PunishLogPo in project nuls by nuls-io.

the class PunishLogStorageServiceImpl method getPunishList.

@Override
public List<PunishLogPo> getPunishList() {
    List<Entry<byte[], byte[]>> list = dbService.entryList(ConsensusStorageConstant.DB_NAME_CONSENSUS_PUNISH_LOG);
    List<PunishLogPo> polist = new ArrayList<>();
    for (Entry<byte[], byte[]> entry : list) {
        PunishLogPo po = new PunishLogPo();
        try {
            po.parse(entry.getValue(), 0);
        } catch (NulsException e) {
            throw new NulsRuntimeException(e);
        }
        polist.add(po);
    }
    return polist;
}
Also used : Entry(io.nuls.db.model.Entry) NulsException(io.nuls.kernel.exception.NulsException) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) PunishLogPo(io.nuls.consensus.poc.storage.po.PunishLogPo)

Example 10 with PunishLogPo

use of io.nuls.consensus.poc.storage.po.PunishLogPo in project nuls by nuls-io.

the class CacheLoader method loadRedPunishList.

public List<PunishLogPo> loadRedPunishList(List<PunishLogPo> allPunishList) {
    List<PunishLogPo> list = new ArrayList<>();
    for (PunishLogPo po : allPunishList) {
        if (po.getType() == PunishType.RED.getCode()) {
            list.add(po);
        }
    }
    Collections.sort(list, new PunishLogComparator());
    return list;
}
Also used : PunishLogComparator(io.nuls.consensus.poc.storage.utils.PunishLogComparator) ArrayList(java.util.ArrayList) PunishLogPo(io.nuls.consensus.poc.storage.po.PunishLogPo)

Aggregations

PunishLogPo (io.nuls.consensus.poc.storage.po.PunishLogPo)14 ArrayList (java.util.ArrayList)6 BlockExtendsData (io.nuls.consensus.poc.model.BlockExtendsData)5 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)5 BlockHeader (io.nuls.kernel.model.BlockHeader)5 Agent (io.nuls.consensus.poc.protocol.entity.Agent)4 Deposit (io.nuls.consensus.poc.protocol.entity.Deposit)4 Chain (io.nuls.consensus.poc.model.Chain)2 RedPunishData (io.nuls.consensus.poc.protocol.entity.RedPunishData)2 YellowPunishData (io.nuls.consensus.poc.protocol.entity.YellowPunishData)2 PunishLogComparator (io.nuls.consensus.poc.storage.utils.PunishLogComparator)2 CoinDataResult (io.nuls.account.ledger.model.CoinDataResult)1 ChainContainer (io.nuls.consensus.poc.container.ChainContainer)1 AgentPo (io.nuls.consensus.poc.storage.po.AgentPo)1 DepositPo (io.nuls.consensus.poc.storage.po.DepositPo)1 PunishLogStorageService (io.nuls.consensus.poc.storage.service.PunishLogStorageService)1 Entry (io.nuls.db.model.Entry)1 NulsException (io.nuls.kernel.exception.NulsException)1 Block (io.nuls.kernel.model.Block)1 SmallBlock (io.nuls.protocol.model.SmallBlock)1