use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.
the class MicroKernelBootstrap method init.
@Override
public void init() {
try {
NulsContext.NULS_CONFIG = ConfigLoader.loadIni(NulsConstant.USER_CONFIG_FILE);
NulsContext.MODULES_CONFIG = ConfigLoader.loadIni(NulsConstant.MODULES_CONFIG_FILE);
} catch (IOException e) {
Log.error("Client start failed", e);
throw new NulsRuntimeException(ErrorCode.FAILED, "Client start failed");
}
// set system language
try {
NulsContext.DEFAULT_ENCODING = NulsContext.NULS_CONFIG.getCfgValue(NulsConstant.CFG_SYSTEM_SECTION, NulsConstant.CFG_SYSTEM_DEFAULT_ENCODING);
String language = NulsContext.NULS_CONFIG.getCfgValue(NulsConstant.CFG_SYSTEM_SECTION, NulsConstant.CFG_SYSTEM_LANGUAGE);
I18nUtils.setLanguage(language);
} catch (NulsException e) {
Log.error(e);
}
SpringLiteContext.init("io.nuls", new ModularServiceMethodInterceptor());
try {
VersionManager.start();
} catch (NulsException e) {
Log.error(e);
}
}
use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.
the class TransactionManager method getInstance.
public static Transaction getInstance(NulsByteBuffer byteBuffer) throws Exception {
int txType = (int) new NulsByteBuffer(byteBuffer.getPayloadByCursor()).readVarInt();
Class<? extends Transaction> txClass = getTxClass(txType);
if (null == txClass) {
throw new NulsRuntimeException(ErrorCode.FAILED, "transaction type not exist!");
}
Transaction tx = byteBuffer.readNulsData(txClass.getConstructor().newInstance());
return tx;
}
use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.
the class PocConsensusResource method createAgent.
@POST
@Path("/agent")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Create an agent for consensus!")
public RpcResult createAgent(CreateAgentForm form) throws NulsException {
AssertUtil.canNotEmpty(form);
AssertUtil.canNotEmpty(form.getAgentAddress());
AssertUtil.canNotEmpty(form.getAgentName());
AssertUtil.canNotEmpty(form.getPackingAddress());
AssertUtil.canNotEmpty(form.getDeposit());
AssertUtil.canNotEmpty(form.getRemark());
AssertUtil.canNotEmpty(form.getPassword());
if (!Address.validAddress(form.getPackingAddress()) || !Address.validAddress(form.getAgentAddress())) {
throw new NulsRuntimeException(ErrorCode.PARAMETER_ERROR);
}
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("deposit", form.getDeposit());
paramsMap.put("packingAddress", form.getPackingAddress());
paramsMap.put("introduction", form.getRemark());
paramsMap.put("commissionRate", form.getCommissionRate());
paramsMap.put("agentName", form.getAgentName());
Transaction tx = consensusService.startConsensus(form.getAgentAddress(), form.getPassword(), paramsMap);
return RpcResult.getSuccess().setData(tx.getHash().getDigestHex());
}
use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.
the class TransactionResource method load.
@GET
@Path("/hash/{hash}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult load(@PathParam("hash") String hash) {
RpcResult result = null;
if (StringUtils.isBlank(hash)) {
return RpcResult.getFailed(ErrorCode.NULL_PARAMETER);
}
try {
Transaction tx = ledgerService.getTx(NulsDigestData.fromDigestHex(hash));
if (tx == null) {
result = RpcResult.getFailed("not found");
} else {
result = RpcResult.getSuccess();
result.setData(new TransactionDto(tx));
}
} catch (NulsRuntimeException re) {
Log.error(re);
result = new RpcResult(false, re.getCode(), re.getMessage());
} catch (Exception e) {
Log.error(e);
result = RpcResult.getFailed(ErrorCode.SYS_UNKOWN_EXCEPTION);
}
return result;
}
use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.
the class GenesisBlock method initGengsisTxs.
private void initGengsisTxs(Map<String, Object> jsonMap) {
List<Map<String, Object>> list = (List<Map<String, Object>>) jsonMap.get(CONFIG_FILED_TXS);
if (null == list || list.isEmpty()) {
throw new NulsRuntimeException(ErrorCode.CONFIG_ERROR);
}
CoinTransferData data = new CoinTransferData(OperationType.COIN_BASE, Na.ZERO);
data.setPriKey(Hex.decode(priKey));
Na total = Na.ZERO;
for (Map<String, Object> map : list) {
String address = (String) map.get(CONFIG_FILED_ADDRESS);
AssertUtil.canNotEmpty(address, ErrorCode.NULL_PARAMETER);
Integer nuls = (Integer) map.get(CONFIG_FILED_NULS);
AssertUtil.canNotEmpty(nuls, ErrorCode.NULL_PARAMETER);
Integer height = (Integer) map.get(CONFIG_FILED_UNLOCK_HEIGHT);
Coin coin = new Coin();
coin.setNa(Na.parseNuls(nuls));
coin.setUnlockTime(0);
if (height == null) {
coin.setUnlockTime(0);
} else {
coin.setUnlockHeight(height.longValue());
}
data.addTo(address, coin);
total = total.add(coin.getNa());
}
data.setTotalNa(total);
CoinBaseTransaction tx = null;
try {
tx = new CoinBaseTransaction(data, null);
} catch (NulsException e) {
Log.error(e);
throw new NulsRuntimeException(e);
}
tx.setTime(this.blockTime);
tx.setFee(Na.ZERO);
try {
tx.setHash(NulsDigestData.calcDigestData(tx.serialize()));
} catch (IOException e) {
Log.error(e);
throw new NulsRuntimeException(e);
}
P2PKHScriptSig p2PKHScriptSig = new P2PKHScriptSig();
Account account = null;
try {
account = AccountTool.createAccount(priKey);
} catch (NulsException e) {
e.printStackTrace();
}
AccountService accountService = NulsContext.getServiceBean(AccountService.class);
P2PKHScriptSig scriptSig = null;
try {
scriptSig = accountService.createP2PKHScriptSigFromDigest(tx.getHash(), account, "");
} catch (NulsException e) {
e.printStackTrace();
}
try {
tx.setScriptSig(scriptSig.serialize());
} catch (IOException e) {
e.printStackTrace();
}
List<Transaction> txlist = new ArrayList<>();
// tx.setStatus(TxStatusEnum.AGREED);
txlist.add(tx);
setTxs(txlist);
}
Aggregations