use of io.nuls.db.entity.AliasPo in project nuls by nuls-io.
the class AccountServiceImpl method importAccount.
@Override
@DbSession
public Result importAccount(String priKey, String password) {
Account account = null;
try {
account = AccountTool.createAccount(priKey);
} catch (NulsException e) {
return Result.getFailed("invalid prikey");
}
// maybe account has been imported
AccountPo accountPo = accountDao.get(account.getAddress().getBase58());
if (accountPo != null) {
return Result.getFailed(ErrorCode.ACCOUNT_EXIST);
} else {
accountPo = new AccountPo();
}
Account defaultAcct = getDefaultAccount();
if (defaultAcct != null) {
try {
if (!defaultAcct.unlock(password)) {
return Result.getFailed(ErrorCode.PASSWORD_IS_WRONG);
}
defaultAcct.lock();
} catch (NulsException e) {
e.printStackTrace();
return Result.getFailed("ErrorCode.PASSWORD_IS_WRONG");
}
}
try {
account.encrypt(password);
} catch (NulsException e) {
e.printStackTrace();
}
// save db
AccountTool.toPojo(account, accountPo);
AliasPo aliasPo = aliasDataService.getByAddress(accountPo.getAddress());
if (aliasPo != null) {
account.setAlias(aliasPo.getAlias());
accountPo.setAlias(aliasPo.getAlias());
}
accountDao.save(accountPo);
ledgerService.saveTxInLocal(accountPo.getAddress());
// save cache
accountCacheService.putAccount(account);
NulsContext.LOCAL_ADDRESS_LIST.add(accountPo.getAddress());
ledgerService.getBalance(accountPo.getAddress());
if (getDefaultAccount() == null) {
setDefaultAccount(account.getAddress().getBase58());
}
AccountImportedNotice notice = new AccountImportedNotice();
notice.setEventBody(account);
eventBroadcaster.publishToLocal(notice);
Result result = Result.getSuccess();
result.setObject(accountPo.getAddress());
return result;
}
use of io.nuls.db.entity.AliasPo in project nuls by nuls-io.
the class AccountServiceImpl method importAccounts.
@Override
@DbSession
public Result importAccounts(List<String> keys, String password) {
Account account = null;
AccountPo accountPo = null;
AliasPo aliasPo = null;
Account defaultAcct = getDefaultAccount();
if (defaultAcct != null) {
try {
if (!defaultAcct.decrypt(password)) {
return Result.getFailed(ErrorCode.PASSWORD_IS_WRONG);
}
defaultAcct.encrypt(password);
} catch (NulsException e) {
}
}
for (String priKey : keys) {
try {
account = AccountTool.createAccount(priKey);
account.encrypt(password);
} catch (NulsException e) {
return Result.getFailed("invalid prikey");
}
accountPo = accountDao.get(account.getAddress().getBase58());
if (accountPo != null) {
continue;
} else {
accountPo = new AccountPo();
}
// save db
AccountTool.toPojo(account, accountPo);
aliasPo = aliasDataService.getByAddress(accountPo.getAddress());
if (aliasPo != null) {
account.setAlias(aliasPo.getAlias());
accountPo.setAlias(aliasPo.getAlias());
}
accountDao.save(accountPo);
ledgerService.saveTxInLocal(accountPo.getAddress());
// save cache
accountCacheService.putAccount(account);
NulsContext.LOCAL_ADDRESS_LIST.add(accountPo.getAddress());
ledgerService.getBalance(accountPo.getAddress());
}
return Result.getSuccess();
}
use of io.nuls.db.entity.AliasPo in project nuls by nuls-io.
the class AccountServiceImpl method getAlias.
@Override
public Alias getAlias(String address) {
AliasPo aliasPo = aliasDataService.getByAddress(address);
if (aliasPo == null) {
return null;
}
Alias alias = new Alias(aliasPo.getAddress(), aliasPo.getAlias());
return alias;
}
use of io.nuls.db.entity.AliasPo in project nuls by nuls-io.
the class AliasTxService method onApproval.
@Override
public void onApproval(AliasTransaction tx) throws NulsException {
Alias alias = tx.getTxData();
AliasPo po = getAliasDataService().getAlias(alias.getAlias());
if (po != null) {
throw new NulsException(ErrorCode.ALIAS_EXIST);
}
}
use of io.nuls.db.entity.AliasPo in project nuls by nuls-io.
the class AliasTxService method onRollback.
@Override
public void onRollback(AliasTransaction tx) throws NulsException {
AliasPo po = AccountTool.toAliasPojo(tx.getTxData());
getAliasDataService().rollbackAlias(po);
}
Aggregations