use of io.nuls.core.exception.NulsException 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.NulsException in project nuls by nuls-io.
the class AccountServiceImpl method unlockAccounts.
@Override
public Result unlockAccounts(final String password, int seconds) {
List<Account> accounts = this.getAccountList();
if (accounts == null || accounts.isEmpty()) {
return new Result(false, "No account was found");
}
Account acct = accounts.get(0);
if (!acct.isEncrypted()) {
return new Result(false, "No password has been set up yet");
}
if (!StringUtils.validPassword(password)) {
return new Result(false, "Length between 8 and 20, the combination of characters and numbers");
}
for (Account account : accounts) {
try {
if (!account.unlock(password)) {
return Result.getFailed(ErrorCode.PASSWORD_IS_WRONG);
}
} catch (NulsException e) {
return Result.getFailed(ErrorCode.PASSWORD_IS_WRONG);
}
}
isLockNow = false;
TaskManager.createAndRunThread(NulsConstant.MODULE_ID_ACCOUNT, "unlockAccountThread", new Runnable() {
@Override
public void run() {
isLockNow = true;
try {
Thread.sleep(seconds * 1000);
} catch (InterruptedException e) {
Log.error(e);
}
try {
resetKeys(password);
} catch (NulsException e) {
Log.error("unlockAccounts resetKey error", e);
}
isLockNow = false;
}
});
return new Result(true, "OK");
}
use of io.nuls.core.exception.NulsException in project nuls by nuls-io.
the class Account method decrypt.
public boolean decrypt(String password) throws NulsException {
try {
byte[] unencryptedPrivateKey = AESEncrypt.decrypt(this.getEncryptedPriKey(), password);
BigInteger newPriv = new BigInteger(1, unencryptedPrivateKey);
ECKey key = ECKey.fromPrivate(newPriv);
// todo pub key compress?
if (!Arrays.equals(key.getPubKey(), getPubKey())) {
return false;
}
key.setEncryptedPrivateKey(new EncryptedData(this.getEncryptedPriKey()));
this.setPriKey(key.getPrivKeyBytes());
this.setEcKey(key);
} catch (Exception e) {
throw new NulsException(ErrorCode.PASSWORD_IS_WRONG);
}
return true;
}
use of io.nuls.core.exception.NulsException in project nuls by nuls-io.
the class NewTxEventHandler method onEvent.
@Override
public void onEvent(TransactionEvent event, String fromId) {
Transaction tx = event.getEventBody();
if (null == tx) {
return;
}
boolean isMine = false;
try {
isMine = ledgerService.checkTxIsMine(tx);
} catch (NulsException e) {
Log.error(e);
}
ValidateResult result = tx.verify();
if (result.isFailed()) {
if (result.getErrorCode() == ErrorCode.ORPHAN_TX) {
orphanTxCacheManager.putTx(tx);
eventBroadcaster.broadcastHashAndCacheAysn(event, false, fromId);
return;
}
if (result.getLevel() == SeverityLevelEnum.NORMAL_FOUL) {
Log.info("-----------------------------------------------newTxHandler remove node:" + fromId);
networkService.removeNode(fromId);
} else if (result.getLevel() == SeverityLevelEnum.FLAGRANT_FOUL) {
networkService.blackNode(fromId, NodePo.BLACK);
}
return;
}
try {
if (isMine) {
ledgerService.approvalTx(tx);
}
cacheManager.putTx(tx);
eventBroadcaster.broadcastHashAndCacheAysn(event, false, fromId);
} catch (Exception e) {
Log.error(e);
}
}
use of io.nuls.core.exception.NulsException in project nuls by nuls-io.
the class CoinbaseValidator method validate.
@Override
public ValidateResult validate(Block block) {
if (null == block || block.getHeader() == null || null == block.getTxs() || block.getTxs().isEmpty()) {
return ValidateResult.getFailedResult(ErrorCode.DATA_FIELD_CHECK_ERROR);
}
Transaction tx = block.getTxs().get(0);
if (tx.getType() != TransactionConstant.TX_TYPE_COIN_BASE) {
return ValidateResult.getFailedResult("Coinbase transaction order wrong!");
}
for (int i = 1; i < block.getTxs().size(); i++) {
Transaction transaction = block.getTxs().get(i);
if (transaction.getType() == TransactionConstant.TX_TYPE_COIN_BASE) {
ValidateResult result = ValidateResult.getFailedResult("Coinbase transaction more than one!");
result.setLevel(SeverityLevelEnum.FLAGRANT_FOUL);
return result;
}
}
BlockRoundData blockRound = null;
try {
blockRound = new BlockRoundData(block.getHeader().getExtend());
} catch (NulsException e) {
Log.error(e);
}
if (null == blockRound) {
return ValidateResult.getFailedResult("Cann't get the round data!");
}
return ValidateResult.getSuccessResult();
}
Aggregations