blockListeners.addListener(new Listener<Block>() {
final class Entry implements Comparable<Entry> {
final Account account;
final long time;
Entry(Account account, long time) {
this.account = account;
this.time = time;
}
@Override
public int compareTo(Entry entry) {
if (this.time < entry.time) {
return -1;
} else if (this.time > entry.time) {
return 1;
} else {
long thisAccountId = this.account.getId(), thatAccountId = entry.account.getId();
if (thisAccountId < thatAccountId) {
return -1;
} else if (thisAccountId > thatAccountId) {
return 1;
} else {
return 0;
}
}
}
}
@Override
public void notify(Block block) {
List<Entry> entries = new LinkedList<>();
Block curBlock = Nxt.getBlockchain().getLastBlock();
for (Account account : Account.getAllAccounts(0, Integer.MAX_VALUE)) {
if (account.getEffectiveBalanceNXT() > 0) {
if (account.getPublicKey() != null) {
long time = Generator.getHitTime(account, curBlock);
entries.add(new Entry(account, time));
}
}
}
Entry[] sortedEntries = entries.toArray(new Entry[entries.size()]);
Arrays.sort(sortedEntries);
StringBuilder sb = new StringBuilder("Block "+block.getHeight());
sb.append(", forger: " + Convert.rsAccount(block.getGeneratorId()));
sb.append("\t\tNext 10 forgers: ");
for(int i=0; i<10; i++){
sb.append(Convert.rsAccount(sortedEntries[i].account.getId()));
if(i<9) {
sb.append(",");
}
}
System.out.println(sb);
}
}, Event.AFTER_BLOCK_APPLY);