use of io.nuls.kernel.exception.NulsException in project nuls by nuls-io.
the class SpringLiteContext method loadBean.
// /**
// * 初始化该类型的实例,由参数决定是否使用动态代理的方式进行实例化,将实例化后的对象加入对象池
// * Instantiate an instance of this type by instantiating the instantiated object
// * into the object pool by determining whether the dynamic proxy is used.
// *
// * @param beanName 对象名称
// * @param clazz 对象类型
// * @param proxy 是否返回动态代理的对象
// */
private static Object loadBean(String beanName, Class clazz, boolean proxy) throws NulsException {
if (BEAN_OK_MAP.containsKey(beanName)) {
Log.error("bean name repetition (" + beanName + "):" + clazz.getName());
return BEAN_OK_MAP.get(beanName);
}
if (BEAN_TEMP_MAP.containsKey(beanName)) {
Log.error("bean name repetition (" + beanName + "):" + clazz.getName());
return BEAN_TEMP_MAP.get(beanName);
}
Object bean = null;
if (proxy) {
bean = createProxy(clazz, interceptor);
} else {
try {
bean = clazz.newInstance();
} catch (InstantiationException e) {
Log.error(e);
throw new NulsException(e);
} catch (IllegalAccessException e) {
Log.error(e);
throw new NulsException(e);
}
}
BEAN_TEMP_MAP.put(beanName, bean);
BEAN_TYPE_MAP.put(beanName, clazz);
addClassNameMap(clazz, beanName);
return bean;
}
use of io.nuls.kernel.exception.NulsException in project nuls by nuls-io.
the class AccountBaseServiceTest method setPassword.
@Test
public void setPassword() {
List<Account> accounts = this.accountService.createAccount(1, "").getData();
Account account = accounts.get(0);
accountBaseService.setPassword(account.getAddress().toString(), "nuls123456");
Account acc = accountService.getAccount(account.getAddress()).getData();
try {
assertTrue(acc.unlock("nuls123456"));
assertArrayEquals(acc.getPriKey(), account.getPriKey());
} catch (NulsException e) {
e.printStackTrace();
}
}
use of io.nuls.kernel.exception.NulsException in project nuls by nuls-io.
the class CommandHandler method main.
public static void main(String[] args) {
/**
* 如果操作系统是windows, 可能会使控制台读取部分处于死循环,可以设置为false,绕过本地Windows API,直接使用Java IO流输出
* If the operating system is windows, it may cause the console to read part of the loop, can be set to false,
* bypass the native Windows API, use the Java IO stream output directly
*/
if (System.getProperties().getProperty("os.name").toUpperCase().indexOf("WINDOWS") != -1) {
System.setProperty("jline.WindowsTerminal.directConsole", "false");
}
NULSParams.BOOTSTRAP.init(args);
CommandHandler instance = new CommandHandler();
instance.init();
try {
I18nUtils.setLanguage("en");
} catch (NulsException e) {
e.printStackTrace();
}
try {
CONSOLE_READER = new ConsoleReader();
List<Completer> completers = new ArrayList<Completer>();
completers.add(new StringsCompleter(PROCESSOR_MAP.keySet()));
CONSOLE_READER.addCompleter(new ArgumentCompleter(completers));
String line;
do {
line = CONSOLE_READER.readLine(CommandConstant.COMMAND_PS1);
if (StringUtils.isBlank(line)) {
continue;
}
String[] cmdArgs = parseArgs(line);
System.out.print(instance.processCommand(cmdArgs) + "\n");
} while (line != null);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (!CONSOLE_READER.delete()) {
CONSOLE_READER.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of io.nuls.kernel.exception.NulsException in project nuls by nuls-io.
the class PocConsensusResource method withdraw.
@POST
@Path("/withdraw")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "退出共识 [3.6.11]", notes = "返回退出成功的交易hash")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = String.class) })
public RpcClientResult withdraw(@ApiParam(name = "form", value = "退出共识表单数据", required = true) WithdrawForm form) throws NulsException, IOException {
AssertUtil.canNotEmpty(form);
AssertUtil.canNotEmpty(form.getTxHash());
if (!NulsDigestData.validHash(form.getTxHash())) {
return Result.getFailed(KernelErrorCode.PARAMETER_ERROR).toRpcClientResult();
}
AssertUtil.canNotEmpty(form.getAddress());
if (!AddressTool.validAddress(form.getAddress())) {
return Result.getFailed(AccountErrorCode.ADDRESS_ERROR).toRpcClientResult();
}
Account account = accountService.getAccount(form.getAddress()).getData();
if (null == account) {
return Result.getFailed(AccountErrorCode.ACCOUNT_NOT_EXIST).toRpcClientResult();
}
if (account.isEncrypted() && account.isLocked()) {
AssertUtil.canNotEmpty(form.getPassword(), "password is wrong");
if (!account.validatePassword(form.getPassword())) {
return Result.getFailed(AccountErrorCode.PASSWORD_IS_WRONG).toRpcClientResult();
}
}
CancelDepositTransaction tx = new CancelDepositTransaction();
CancelDeposit cancelDeposit = new CancelDeposit();
NulsDigestData hash = NulsDigestData.fromDigestHex(form.getTxHash());
DepositTransaction depositTransaction = null;
try {
depositTransaction = (DepositTransaction) ledgerService.getTx(hash);
} catch (Exception e) {
return Result.getFailed(KernelErrorCode.PARAMETER_ERROR).toRpcClientResult();
}
if (null == depositTransaction) {
return Result.getFailed(TransactionErrorCode.TX_NOT_EXIST).toRpcClientResult();
}
cancelDeposit.setAddress(AddressTool.getAddress(form.getAddress()));
cancelDeposit.setJoinTxHash(hash);
tx.setTxData(cancelDeposit);
CoinData coinData = new CoinData();
List<Coin> toList = new ArrayList<>();
toList.add(new Coin(cancelDeposit.getAddress(), depositTransaction.getTxData().getDeposit(), 0));
coinData.setTo(toList);
List<Coin> fromList = new ArrayList<>();
for (int index = 0; index < depositTransaction.getCoinData().getTo().size(); index++) {
Coin coin = depositTransaction.getCoinData().getTo().get(index);
if (coin.getLockTime() == -1L && coin.getNa().equals(depositTransaction.getTxData().getDeposit())) {
coin.setOwner(ArraysTool.concatenate(hash.serialize(), new VarInt(index).encode()));
fromList.add(coin);
break;
}
}
if (fromList.isEmpty()) {
return Result.getFailed(KernelErrorCode.DATA_ERROR).toRpcClientResult();
}
coinData.setFrom(fromList);
tx.setCoinData(coinData);
Na fee = TransactionFeeCalculator.getMaxFee(108 + tx.size());
coinData.getTo().get(0).setNa(coinData.getTo().get(0).getNa().subtract(fee));
RpcClientResult result1 = this.txProcessing(tx, null, account, form.getPassword());
if (!result1.isSuccess()) {
return result1;
}
Map<String, String> valueMap = new HashMap<>();
valueMap.put("value", tx.getHash().getDigestHex());
return Result.getSuccess().setData(valueMap).toRpcClientResult();
}
use of io.nuls.kernel.exception.NulsException in project nuls by nuls-io.
the class AgentStorageServiceImpl method getList.
@Override
public List<AgentPo> getList() {
List<Entry<byte[], byte[]>> list = dbService.entryList(ConsensusStorageConstant.DB_NAME_CONSENSUS_AGENT);
List<AgentPo> resultList = new ArrayList<>();
if (list == null) {
return resultList;
}
for (Entry<byte[], byte[]> entry : list) {
AgentPo agentPo = new AgentPo();
try {
agentPo.parse(entry.getValue(), 0);
} catch (NulsException e) {
Log.error(e);
throw new NulsRuntimeException(e);
}
NulsDigestData hash = new NulsDigestData();
try {
hash.parse(entry.getKey(), 0);
} catch (NulsException e) {
Log.error(e);
}
agentPo.setHash(hash);
resultList.add(agentPo);
}
return resultList;
}
Aggregations