Search in sources :

Example 21 with NulsException

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;
}
Also used : NulsException(io.nuls.core.exception.NulsException) PocMeetingRound(io.nuls.consensus.entity.meeting.PocMeetingRound) BlockRoundData(io.nuls.consensus.entity.block.BlockRoundData) Block(io.nuls.core.chain.entity.Block) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 22 with NulsException

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();
}
Also used : NulsException(io.nuls.core.exception.NulsException) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException)

Example 23 with NulsException

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();
}
Also used : NulsException(io.nuls.core.exception.NulsException) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException)

Example 24 with NulsException

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);
    }
}
Also used : VarInt(io.nuls.core.crypto.VarInt) NulsException(io.nuls.core.exception.NulsException)

Example 25 with NulsException

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);
    }
}
Also used : NulsException(io.nuls.core.exception.NulsException)

Aggregations

NulsException (io.nuls.core.exception.NulsException)69 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)32 IOException (java.io.IOException)17 ValidateResult (io.nuls.core.validate.ValidateResult)12 Account (io.nuls.account.entity.Account)11 Transaction (io.nuls.core.chain.entity.Transaction)8 BlockRoundData (io.nuls.consensus.entity.block.BlockRoundData)7 Block (io.nuls.core.chain.entity.Block)6 DbSession (io.nuls.db.transactional.annotation.DbSession)6 Coin (io.nuls.ledger.entity.params.Coin)6 CoinTransferData (io.nuls.ledger.entity.params.CoinTransferData)6 Result (io.nuls.core.chain.entity.Result)5 TransactionEvent (io.nuls.ledger.event.TransactionEvent)5 BlockHeader (io.nuls.core.chain.entity.BlockHeader)4 NulsDigestData (io.nuls.core.chain.entity.NulsDigestData)4 Address (io.nuls.account.entity.Address)3 PocMeetingRound (io.nuls.consensus.entity.meeting.PocMeetingRound)3 P2PKHScriptSig (io.nuls.core.script.P2PKHScriptSig)3 NulsByteBuffer (io.nuls.core.utils.io.NulsByteBuffer)3 AccountPo (io.nuls.db.entity.AccountPo)3