use of io.nuls.core.exception.NulsException in project nuls by nuls-io.
the class ConsensusMeetingRunner method calcRound.
private PocMeetingRound calcRound() {
PocMeetingRound round = new PocMeetingRound(this.consensusManager.getCurrentRound());
Block bestBlock = context.getBestBlock();
BlockRoundData lastRoundData;
try {
lastRoundData = new BlockRoundData(bestBlock.getHeader().getExtend());
} catch (NulsException e) {
Log.error(e);
throw new NulsRuntimeException(e);
}
if (round.getPreviousRound() == null || round.getPreviousRound().getIndex() <= lastRoundData.getRoundIndex()) {
while (true) {
if (lastRoundData.getPackingIndexOfRound() == lastRoundData.getConsensusMemberCount() || lastRoundData.getRoundEndTime() <= TimeService.currentTimeMillis()) {
break;
}
try {
bestBlock = context.getBestBlock();
lastRoundData = new BlockRoundData(bestBlock.getHeader().getExtend());
} catch (NulsException e) {
Log.error(e);
}
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
Log.error(e);
}
}
PocMeetingRound preRound = new PocMeetingRound(null);
preRound.setIndex(lastRoundData.getRoundIndex());
preRound.setStartTime(lastRoundData.getRoundStartTime());
preRound.setMemberCount(lastRoundData.getConsensusMemberCount());
round.setPreviousRound(preRound);
}
round.setStartTime(round.getPreviousRound().getEndTime());
round.setIndex(lastRoundData.getRoundIndex() + 1);
return round;
}
use of io.nuls.core.exception.NulsException in project nuls by nuls-io.
the class StringFileLoader method readRealPath.
public static String readRealPath(String realPath, boolean format) throws NulsException {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(realPath));
} catch (FileNotFoundException e) {
Log.error(e);
throw new NulsException(e);
}
StringBuilder str = new StringBuilder();
String line;
try {
while ((line = br.readLine()) != null) {
if (format) {
str.append(line);
str.append("\n");
} else {
str.append(line.trim());
}
}
} catch (IOException e) {
Log.error(e);
throw new NulsException(e);
} finally {
try {
br.close();
} catch (IOException e) {
Log.error(e);
}
}
return str.toString();
}
use of io.nuls.core.exception.NulsException in project nuls by nuls-io.
the class TxGroup method parse.
@Override
protected void parse(NulsByteBuffer byteBuffer) throws NulsException {
this.blockHash = byteBuffer.readHash();
long txCount = byteBuffer.readVarInt();
this.txList = new ArrayList<>();
for (int i = 0; i < txCount; i++) {
try {
this.txList.add(byteBuffer.readTransaction());
} catch (Exception e) {
throw new NulsException(e);
}
}
initTxMap();
}
use of io.nuls.core.exception.NulsException in project nuls by nuls-io.
the class NulsByteBuffer method readVarInt.
public long readVarInt(int offset) throws NulsException {
try {
VarInt varint = new VarInt(payload, cursor + offset);
cursor += offset + varint.getOriginalSizeInBytes();
return varint.value;
} catch (ArrayIndexOutOfBoundsException e) {
throw new NulsException(ErrorCode.DATA_PARSE_ERROR, e);
}
}
use of io.nuls.core.exception.NulsException in project nuls by nuls-io.
the class NulsByteBuffer method readBytes.
public byte[] readBytes(int length) throws NulsException {
try {
byte[] b = new byte[length];
System.arraycopy(payload, cursor, b, 0, length);
cursor += length;
return b;
} catch (IndexOutOfBoundsException e) {
throw new NulsException(ErrorCode.DATA_PARSE_ERROR, e);
}
}
Aggregations