Search in sources :

Example 6 with AccountPo

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;
}
Also used : Account(io.nuls.account.entity.Account) AccountPo(io.nuls.db.entity.AccountPo)

Example 7 with AccountPo

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");
}
Also used : Account(io.nuls.account.entity.Account) AccountPo(io.nuls.db.entity.AccountPo) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) ValidateResult(io.nuls.core.validate.ValidateResult) Result(io.nuls.core.chain.entity.Result)

Example 8 with AccountPo

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);
    }
}
Also used : AccountPo(io.nuls.db.entity.AccountPo) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) AliasPo(io.nuls.db.entity.AliasPo) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) DbSession(io.nuls.db.transactional.annotation.DbSession)

Example 9 with AccountPo

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");
}
Also used : AccountPo(io.nuls.db.entity.AccountPo) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) Result(io.nuls.core.chain.entity.Result) DbSession(io.nuls.db.transactional.annotation.DbSession)

Example 10 with AccountPo

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);
        }
    }
}
Also used : AccountPo(io.nuls.db.entity.AccountPo) TransactionLocalPo(io.nuls.db.entity.TransactionLocalPo) DbSession(io.nuls.db.transactional.annotation.DbSession)

Aggregations

AccountPo (io.nuls.db.entity.AccountPo)10 Account (io.nuls.account.entity.Account)7 DbSession (io.nuls.db.transactional.annotation.DbSession)6 Result (io.nuls.core.chain.entity.Result)5 NulsException (io.nuls.core.exception.NulsException)5 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)5 ValidateResult (io.nuls.core.validate.ValidateResult)4 AliasPo (io.nuls.db.entity.AliasPo)3 IOException (java.io.IOException)3 TransactionLocalPo (io.nuls.db.entity.TransactionLocalPo)2 AliasTransaction (io.nuls.account.entity.tx.AliasTransaction)1 Transaction (io.nuls.core.chain.entity.Transaction)1