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);
}
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);
}
}
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);
}
}
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);
}
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;
}
Aggregations