use of io.nuls.consensus.poc.model.BlockExtendsData in project nuls by nuls-io.
the class ConsensusTool method createYellowPunishTx.
public static YellowPunishTransaction createYellowPunishTx(Block preBlock, MeetingMember self, MeetingRound round) throws NulsException, IOException {
BlockExtendsData preBlockRoundData = new BlockExtendsData(preBlock.getHeader().getExtend());
if (self.getRoundIndex() - preBlockRoundData.getRoundIndex() > 1) {
return null;
}
int yellowCount = 0;
if (self.getRoundIndex() == preBlockRoundData.getRoundIndex() && self.getPackingIndexOfRound() != preBlockRoundData.getPackingIndexOfRound() + 1) {
yellowCount = self.getPackingIndexOfRound() - preBlockRoundData.getPackingIndexOfRound() - 1;
}
if (self.getRoundIndex() != preBlockRoundData.getRoundIndex() && (self.getPackingIndexOfRound() != 1 || preBlockRoundData.getPackingIndexOfRound() != preBlockRoundData.getConsensusMemberCount())) {
yellowCount = self.getPackingIndexOfRound() + preBlockRoundData.getConsensusMemberCount() - preBlockRoundData.getPackingIndexOfRound() - 1;
}
if (yellowCount == 0) {
return null;
}
List<byte[]> addressList = new ArrayList<>();
for (int i = 1; i <= yellowCount; i++) {
int index = self.getPackingIndexOfRound() - i;
if (index > 0) {
MeetingMember member = round.getMember(index);
if (member.getAgent() == null) {
continue;
} else if (member.getAgent().getDelHeight() > 0) {
continue;
}
addressList.add(member.getAgentAddress());
} else {
MeetingRound preRound = round.getPreRound();
MeetingMember member = preRound.getMember(index + preRound.getMemberCount());
if (member.getAgent() == null || member.getAgent().getDelHeight() > 0) {
continue;
}
addressList.add(member.getAgentAddress());
}
}
if (addressList.isEmpty()) {
return null;
}
YellowPunishTransaction punishTx = new YellowPunishTransaction();
YellowPunishData data = new YellowPunishData();
data.setAddressList(addressList);
punishTx.setTxData(data);
punishTx.setTime(self.getPackEndTime());
punishTx.setHash(NulsDigestData.calcDigestData(punishTx.serializeForHash()));
return punishTx;
}
Aggregations