Search in sources :

Example 6 with TransactionLocalPo

use of io.nuls.db.entity.TransactionLocalPo in project nuls by nuls-io.

the class UtxoLedgerServiceImpl method getLocalTxList.

public List<Transaction> getLocalTxList(Long blockHeight, String address, int txType, int pageNumber, int pageSize) throws Exception {
    List<Transaction> txList = new ArrayList<>();
    List<Transaction> cacheTxList = getCacheTxList(address, txType);
    txList.addAll(cacheTxList);
    List<TransactionLocalPo> poList;
    if (pageNumber == 0 && pageSize == 0) {
        poList = txDao.getLocalTxs(blockHeight, address, txType, 0, 0);
        for (TransactionLocalPo po : poList) {
            txList.add(UtxoTransferTool.toTransaction(po));
        }
        return txList;
    }
    int start = (pageNumber - 1) * pageSize;
    if (txList.size() >= start + pageSize) {
        return txList.subList(start, start + pageSize);
    } else if (start < txList.size()) {
        txList = txList.subList(start, txList.size());
        start = 0;
        pageSize = pageSize - txList.size();
    } else {
        start = start - txList.size();
    }
    poList = txDao.getLocalTxs(blockHeight, address, txType, start, pageSize);
    for (TransactionLocalPo po : poList) {
        txList.add(UtxoTransferTool.toTransaction(po));
    }
    return txList;
}
Also used : TransferTransaction(io.nuls.ledger.entity.tx.TransferTransaction) AbstractCoinTransaction(io.nuls.ledger.entity.tx.AbstractCoinTransaction) LockNulsTransaction(io.nuls.ledger.entity.tx.LockNulsTransaction) TransactionLocalPo(io.nuls.db.entity.TransactionLocalPo) ArrayList(java.util.ArrayList)

Example 7 with TransactionLocalPo

use of io.nuls.db.entity.TransactionLocalPo in project nuls by nuls-io.

the class UtxoLedgerServiceImpl method getTxList.

@Override
public List<Transaction> getTxList(String address, int txType) throws Exception {
    if (StringUtils.isBlank(address) && txType == 0) {
        throw new NulsRuntimeException(ErrorCode.PARAMETER_ERROR);
    }
    List<Transaction> txList = new ArrayList<>();
    List<Transaction> cacheTxList = getCacheTxList(address, txType);
    txList.addAll(cacheTxList);
    if (StringUtils.isNotBlank(address) && NulsContext.LOCAL_ADDRESS_LIST.contains(address)) {
        List<TransactionLocalPo> poList = txDao.getLocalTxs(null, address, txType, 0, 0);
        for (TransactionLocalPo po : poList) {
            txList.add(UtxoTransferTool.toTransaction(po));
        }
    } else {
        List<TransactionPo> poList = txDao.getTxs(null, address, txType, 0, 0);
        for (TransactionPo po : poList) {
            txList.add(UtxoTransferTool.toTransaction(po));
        }
    }
    return txList;
}
Also used : TransferTransaction(io.nuls.ledger.entity.tx.TransferTransaction) AbstractCoinTransaction(io.nuls.ledger.entity.tx.AbstractCoinTransaction) LockNulsTransaction(io.nuls.ledger.entity.tx.LockNulsTransaction) TransactionLocalPo(io.nuls.db.entity.TransactionLocalPo) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) TransactionPo(io.nuls.db.entity.TransactionPo)

Example 8 with TransactionLocalPo

use of io.nuls.db.entity.TransactionLocalPo 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)

Example 9 with TransactionLocalPo

use of io.nuls.db.entity.TransactionLocalPo in project nuls by nuls-io.

the class TransactionLocalDaoImpl method getTxs.

@Override
public List<TransactionLocalPo> getTxs(Long blockHeight, String address, int type, int start, int limit) {
    Searchable searchable = new Searchable();
    // searchable.addCondition(condition);
    if (type != 0) {
        searchable.addCondition("a.type", SearchOperator.eq, type);
    }
    if (blockHeight != null) {
        searchable.addCondition("a.block_height", SearchOperator.eq, blockHeight);
    }
    if (StringUtils.isNotBlank(address)) {
        searchable.addCondition("e.address", SearchOperator.eq, address);
    }
    if (start == 0 & limit == 0) {
        PageHelper.orderBy("a.create_time desc, b.in_index asc, c.out_index asc");
        return getMapper().selectByAddress(searchable);
    }
    PageHelper.offsetPage(start, limit);
    PageHelper.orderBy("a.create_time desc");
    List<String> txHashList = getMapper().selectTxHashListRelation(searchable);
    searchable = new Searchable();
    searchable.addCondition("a.hash", SearchOperator.in, txHashList);
    PageHelper.orderBy("a.create_time desc, b.in_index asc, c.out_index asc");
    List<TransactionLocalPo> localPoList = getMapper().selectByAddress(searchable);
    return localPoList;
}
Also used : TransactionLocalPo(io.nuls.db.entity.TransactionLocalPo) Searchable(io.nuls.db.dao.impl.mybatis.util.Searchable)

Aggregations

TransactionLocalPo (io.nuls.db.entity.TransactionLocalPo)9 AbstractCoinTransaction (io.nuls.ledger.entity.tx.AbstractCoinTransaction)4 LockNulsTransaction (io.nuls.ledger.entity.tx.LockNulsTransaction)4 TransferTransaction (io.nuls.ledger.entity.tx.TransferTransaction)4 ArrayList (java.util.ArrayList)4 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)3 TransactionPo (io.nuls.db.entity.TransactionPo)3 DbSession (io.nuls.db.transactional.annotation.DbSession)3 NulsException (io.nuls.core.exception.NulsException)2 AccountPo (io.nuls.db.entity.AccountPo)2 Account (io.nuls.account.entity.Account)1 AliasTransaction (io.nuls.account.entity.tx.AliasTransaction)1 Transaction (io.nuls.core.chain.entity.Transaction)1 Searchable (io.nuls.db.dao.impl.mybatis.util.Searchable)1 UtxoInputPo (io.nuls.db.entity.UtxoInputPo)1 IOException (java.io.IOException)1