Search in sources :

Example 26 with NulsRuntimeException

use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.

the class NetworkModuleBootstrap method init.

@Override
public void init() {
    this.registerEvent();
    try {
        NetworkContext.setNetworkConfig(ConfigLoader.loadProperties(NetworkConstant.NETWORK_PROPERTIES));
    } catch (IOException e) {
        Log.error(e);
        throw new NulsRuntimeException(ErrorCode.IO_ERROR);
    }
    this.registerService(NetworkServiceImpl.class);
    networkService = NulsContext.getServiceBean(NetworkService.class);
}
Also used : NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NetworkService(io.nuls.network.service.NetworkService) IOException(java.io.IOException)

Example 27 with NulsRuntimeException

use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.

the class NetworkServiceImpl method start.

@Override
public void start() {
    try {
        connectionManager.start();
        nodesManager.start();
    } catch (Exception e) {
        Log.error(e);
        throw new NulsRuntimeException(ErrorCode.NET_SERVER_START_ERROR);
    }
}
Also used : NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 28 with NulsRuntimeException

use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.

the class BlockMaintenanceThread method checkGenesisBlock.

public void checkGenesisBlock() throws Exception {
    Block genesisBlock = NulsContext.getInstance().getGenesisBlock();
    ValidateResult result = genesisBlock.verify();
    if (result.isFailed()) {
        throw new NulsRuntimeException(ErrorCode.DATA_ERROR, result.getMessage());
    }
    Block localGenesisBlock = this.blockService.getGengsisBlock();
    if (null == localGenesisBlock) {
        for (Transaction tx : genesisBlock.getTxs()) {
            ledgerService.approvalTx(tx);
        }
        this.blockService.saveBlock(genesisBlock);
        return;
    }
    localGenesisBlock.verify();
    String logicHash = genesisBlock.getHeader().getHash().getDigestHex();
    String localHash = localGenesisBlock.getHeader().getHash().getDigestHex();
    if (!logicHash.equals(localHash)) {
        throw new NulsRuntimeException(ErrorCode.DATA_ERROR);
    }
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) ValidateResult(io.nuls.core.validate.ValidateResult) Block(io.nuls.core.chain.entity.Block) BestCorrectBlock(io.nuls.consensus.entity.block.BestCorrectBlock) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 29 with NulsRuntimeException

use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.

the class ConsensusMeetingRunner method coinBaseTx.

private void coinBaseTx(List<Transaction> txList, PocMeetingMember self) throws NulsException, IOException {
    CoinTransferData data = new CoinTransferData(OperationType.COIN_BASE, this.ledgerService.getTxFee(TransactionConstant.TX_TYPE_COIN_BASE));
    data.setFee(Na.ZERO);
    List<ConsensusReward> rewardList = calcReward(txList, self);
    Na total = Na.ZERO;
    for (ConsensusReward reward : rewardList) {
        Coin coin = new Coin();
        coin.setNa(reward.getReward());
        data.addTo(reward.getAddress(), coin);
        total = total.add(reward.getReward());
    }
    data.setTotalNa(total);
    CoinBaseTransaction tx;
    try {
        tx = new CoinBaseTransaction(data, null);
    } catch (NulsException e) {
        Log.error(e);
        throw new NulsRuntimeException(e);
    }
    tx.setFee(Na.ZERO);
    tx.setHash(NulsDigestData.calcDigestData(tx));
    tx.setScriptSig(accountService.createP2PKHScriptSigFromDigest(tx.getHash(), consensusManager.getConsensusStatusInfo().getAccount(), NulsContext.CACHED_PASSWORD_OF_WALLET).serialize());
    ValidateResult validateResult = tx.verify();
    confirmingTxCacheManager.putTx(tx);
    if (null == validateResult || validateResult.isFailed()) {
        throw new NulsRuntimeException(ErrorCode.CONSENSUS_EXCEPTION);
    }
    try {
        ledgerService.approvalTx(tx);
    } catch (NulsException e) {
        throw new NulsRuntimeException(e);
    }
    txList.add(0, tx);
}
Also used : Coin(io.nuls.ledger.entity.params.Coin) CoinTransferData(io.nuls.ledger.entity.params.CoinTransferData) Na(io.nuls.core.chain.entity.Na) ConsensusReward(io.nuls.consensus.entity.meeting.ConsensusReward) CoinBaseTransaction(io.nuls.ledger.entity.tx.CoinBaseTransaction) NulsException(io.nuls.core.exception.NulsException) ValidateResult(io.nuls.core.validate.ValidateResult) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 30 with NulsRuntimeException

use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.

the class ConsensusTool method createBlock.

public static Block createBlock(BlockData blockData, Account account) throws NulsException {
    if (null == account) {
        throw new NulsRuntimeException(ErrorCode.ACCOUNT_NOT_EXIST);
    }
    Block block = new Block();
    block.setTxs(blockData.getTxList());
    BlockHeader header = new BlockHeader();
    block.setHeader(header);
    try {
        block.getHeader().setExtend(blockData.getRoundData().serialize());
    } catch (IOException e) {
        Log.error(e);
    }
    header.setHeight(blockData.getHeight());
    header.setTime(TimeService.currentTimeMillis());
    header.setPreHash(blockData.getPreHash());
    header.setTxCount(blockData.getTxList().size());
    List<NulsDigestData> txHashList = new ArrayList<>();
    for (int i = 0; i < blockData.getTxList().size(); i++) {
        Transaction tx = blockData.getTxList().get(i);
        txHashList.add(tx.getHash());
    }
    header.setPackingAddress(account.getAddress().toString());
    header.setMerkleHash(NulsDigestData.calcMerkleDigestData(txHashList));
    header.setHash(NulsDigestData.calcDigestData(block.getHeader()));
    P2PKHScriptSig scriptSig = new P2PKHScriptSig();
    NulsSignData signData = accountService.signDigest(header.getHash(), account, NulsContext.CACHED_PASSWORD_OF_WALLET);
    scriptSig.setSignData(signData);
    scriptSig.setPublicKey(account.getPubKey());
    header.setScriptSig(scriptSig);
    return block;
}
Also used : P2PKHScriptSig(io.nuls.core.script.P2PKHScriptSig) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) IOException(java.io.IOException)

Aggregations

NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)64 NulsException (io.nuls.core.exception.NulsException)26 IOException (java.io.IOException)11 Transaction (io.nuls.core.chain.entity.Transaction)10 ArrayList (java.util.ArrayList)9 Account (io.nuls.account.entity.Account)7 AbstractNulsQueue (io.nuls.core.utils.queue.intf.AbstractNulsQueue)7 DbSession (io.nuls.db.transactional.annotation.DbSession)6 CoinTransferData (io.nuls.ledger.entity.params.CoinTransferData)5 ValidateResult (io.nuls.core.validate.ValidateResult)4 Coin (io.nuls.ledger.entity.params.Coin)4 TransactionEvent (io.nuls.ledger.event.TransactionEvent)4 AccountService (io.nuls.account.service.intf.AccountService)3 Block (io.nuls.core.chain.entity.Block)3 AccountPo (io.nuls.db.entity.AccountPo)3 AbstractCoinTransaction (io.nuls.ledger.entity.tx.AbstractCoinTransaction)3 BlockHashResponse (io.nuls.consensus.entity.BlockHashResponse)2 RedPunishData (io.nuls.consensus.entity.RedPunishData)2 BestCorrectBlock (io.nuls.consensus.entity.block.BestCorrectBlock)2 Agent (io.nuls.consensus.entity.member.Agent)2