Search in sources :

Example 6 with TransactionPo

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

the class UtxoTransferTool method toTransactionPojo.

public static TransactionPo toTransactionPojo(Transaction tx) throws IOException {
    TransactionPo po = new TransactionPo();
    if (tx.getHash() != null) {
        po.setHash(tx.getHash().getDigestHex());
    }
    po.setType(tx.getType());
    po.setCreateTime(tx.getTime());
    po.setBlockHeight(tx.getBlockHeight());
    po.setTxIndex(tx.getIndex());
    po.setSize(tx.getSize());
    po.setScriptSig(tx.getScriptSig());
    if (null != tx.getTxData()) {
        po.setTxData(tx.getTxData().serialize());
    }
    if (null != tx.getRemark()) {
        po.setRemark(new String(tx.getRemark(), NulsContext.DEFAULT_ENCODING));
    }
    if (null != tx.getFee()) {
        po.setFee(tx.getFee().getValue());
    }
    return po;
}
Also used : TransactionPo(io.nuls.db.entity.TransactionPo)

Example 7 with TransactionPo

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

the class UtxoLedgerServiceImpl method getTxList.

@Override
public Page<Transaction> getTxList(Long height, int type, int pageNum, int pageSize) throws Exception {
    Page<TransactionPo> poPage = txDao.getTxs(height, type, pageNum, pageSize);
    Page<Transaction> txPage = new Page<>(poPage);
    List<Transaction> txList = new ArrayList<>();
    for (TransactionPo po : poPage.getList()) {
        txList.add(UtxoTransferTool.toTransaction(po));
    }
    txPage.setList(txList);
    return txPage;
}
Also used : TransferTransaction(io.nuls.ledger.entity.tx.TransferTransaction) AbstractCoinTransaction(io.nuls.ledger.entity.tx.AbstractCoinTransaction) LockNulsTransaction(io.nuls.ledger.entity.tx.LockNulsTransaction) ArrayList(java.util.ArrayList) Page(io.nuls.core.dto.Page) TransactionPo(io.nuls.db.entity.TransactionPo)

Example 8 with TransactionPo

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

the class UtxoLedgerServiceImpl method getTxList.

@Override
public List<Transaction> getTxList(Long blockHeight, String address, int txType, int pageNumber, int pageSize) throws Exception {
    List<Transaction> txList = null;
    if (StringUtils.isNotBlank(address) && NulsContext.LOCAL_ADDRESS_LIST.contains(address)) {
        txList = getLocalTxList(blockHeight, address, txType, pageNumber, pageSize);
    } else {
        txList = new ArrayList<>();
        List<Transaction> cacheTxList = getCacheTxList(address, txType);
        txList.addAll(cacheTxList);
        List<TransactionPo> poList;
        if (pageNumber == 0 && pageSize == 0) {
            poList = txDao.getTxs(blockHeight, address, txType, 0, 0);
            for (TransactionPo 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.getTxs(blockHeight, address, txType, start, pageSize);
        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) TransactionPo(io.nuls.db.entity.TransactionPo)

Example 9 with TransactionPo

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

the class UtxoLedgerServiceImpl method getTxList.

@Override
public List<Transaction> getTxList(String blockHash) throws Exception {
    List<Transaction> txList = new ArrayList<>();
    List<TransactionPo> poList = txDao.getTxs(blockHash);
    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) ArrayList(java.util.ArrayList) TransactionPo(io.nuls.db.entity.TransactionPo)

Example 10 with TransactionPo

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

the class UtxoLedgerServiceImpl method getTx.

@Override
public Transaction getTx(NulsDigestData hash) {
    Transaction tx = getTxFromCache(hash);
    if (tx != null) {
        return tx;
    }
    TransactionPo po = txDao.gettx(hash.getDigestHex());
    if (null == po) {
        return null;
    }
    try {
        return UtxoTransferTool.toTransaction(po);
    } catch (Exception e) {
        Log.error(e);
    }
    return null;
}
Also used : TransferTransaction(io.nuls.ledger.entity.tx.TransferTransaction) AbstractCoinTransaction(io.nuls.ledger.entity.tx.AbstractCoinTransaction) LockNulsTransaction(io.nuls.ledger.entity.tx.LockNulsTransaction) TransactionPo(io.nuls.db.entity.TransactionPo) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Aggregations

TransactionPo (io.nuls.db.entity.TransactionPo)12 AbstractCoinTransaction (io.nuls.ledger.entity.tx.AbstractCoinTransaction)7 LockNulsTransaction (io.nuls.ledger.entity.tx.LockNulsTransaction)7 TransferTransaction (io.nuls.ledger.entity.tx.TransferTransaction)7 ArrayList (java.util.ArrayList)6 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)4 NulsException (io.nuls.core.exception.NulsException)3 TransactionLocalPo (io.nuls.db.entity.TransactionLocalPo)3 Page (io.nuls.core.dto.Page)2 Searchable (io.nuls.db.dao.impl.mybatis.util.Searchable)2 DbSession (io.nuls.db.transactional.annotation.DbSession)2 IOException (java.io.IOException)2 Result (io.nuls.core.chain.entity.Result)1 ValidateResult (io.nuls.core.validate.ValidateResult)1 UtxoInputPo (io.nuls.db.entity.UtxoInputPo)1 FileOutputStream (java.io.FileOutputStream)1