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