use of io.nuls.db.entity.AccountPo in project nuls by nuls-io.
the class AccountServiceImpl method getAccountList.
@Override
public List<Account> getAccountList() {
List<Account> list = this.accountCacheService.getAccountList();
if (null != list && !list.isEmpty()) {
return list;
}
list = new ArrayList<>();
List<AccountPo> poList = this.accountDao.getList();
Set<String> addressList = new HashSet<>();
if (null == poList || poList.isEmpty()) {
return list;
}
for (AccountPo po : poList) {
Account account = new Account();
AccountTool.toBean(po, account);
list.add(account);
addressList.add(account.getAddress().getBase58());
}
this.accountCacheService.putAccountList(list);
NulsContext.LOCAL_ADDRESS_LIST = addressList;
return list;
}
use of io.nuls.db.entity.AccountPo in project nuls by nuls-io.
the class AccountServiceImpl method encryptAccount.
@Override
public Result encryptAccount(String password) {
if (!StringUtils.validPassword(password)) {
return new Result(false, "Length between 8 and 20, the combination of characters and numbers");
}
List<Account> accounts = this.getAccountList();
if (accounts == null || accounts.isEmpty()) {
return new Result(false, "No account was found");
}
try {
List<AccountPo> accountPoList = new ArrayList<>();
for (Account account : accounts) {
if (account.isEncrypted()) {
return new Result(false, "password has been set up");
} else {
account.encrypt(password);
AccountPo po = new AccountPo();
AccountTool.toPojo(account, po);
accountPoList.add(po);
}
}
if (accountPoList.size() > 0) {
accountDao.update(accountPoList);
}
accountCacheService.putAccountList(accounts);
} catch (Exception e) {
Log.error(e);
return new Result(false, "set password failed");
}
return new Result(true, "OK");
}
use of io.nuls.db.entity.AccountPo in project nuls by nuls-io.
the class AccountTxDaoImpl method rollbackAlias.
@Override
@DbSession
public void rollbackAlias(AliasPo aliasPo) {
try {
AliasPo po = aliasDao.get(aliasPo.getAlias());
if (po != null && po.getAddress().equals(aliasPo.getAddress())) {
aliasDao.delete(aliasPo.getAlias());
AccountPo accountPo = new AccountPo();
po.setAddress(aliasPo.getAddress());
po.setAlias("");
accountDao.updateAlias(accountPo);
}
} catch (Exception e) {
throw new NulsRuntimeException(ErrorCode.DB_ROLLBACK_ERROR);
}
}
use of io.nuls.db.entity.AccountPo in project nuls by nuls-io.
the class AccountTxDaoImpl method saveAlias.
@DbSession
@Override
public Result saveAlias(AliasPo alias) {
try {
aliasDao.save(alias);
AccountPo po = new AccountPo();
po.setAddress(alias.getAddress());
po.setAlias(alias.getAlias());
accountDao.updateAlias(po);
} catch (Exception e) {
throw new NulsRuntimeException(ErrorCode.DB_SAVE_ERROR);
}
return new Result(true, "OK");
}
use of io.nuls.db.entity.AccountPo in project nuls by nuls-io.
the class AccountTxDaoImpl method importAccount.
@DbSession
@Override
public void importAccount(List<AccountPo> accountPoList) {
for (AccountPo account : accountPoList) {
accountDao.save(account);
for (int i = 0; i < account.getMyTxs().size(); i++) {
TransactionLocalPo tx = account.getMyTxs().get(i);
txDao.save(tx);
}
}
}
Aggregations