Search in sources :

Example 1 with TransactionPo

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

the class UtxoLedgerServiceImpl method saveTxList.

@Override
@DbSession
public boolean saveTxList(List<Transaction> txList) throws IOException {
    lock.lock();
    try {
        List<TransactionPo> poList = new ArrayList<>();
        List<TransactionLocalPo> localPoList = new ArrayList<>();
        for (int i = 0; i < txList.size(); i++) {
            Transaction tx = txList.get(i);
            boolean isMine = false;
            try {
                isMine = this.checkTxIsMine(tx);
            } catch (NulsException e) {
                throw new NulsRuntimeException(e);
            }
            TransactionPo po = UtxoTransferTool.toTransactionPojo(tx);
            poList.add(po);
            if (isMine) {
                TransactionLocalPo localPo = UtxoTransferTool.toLocalTransactionPojo(tx);
                localPoList.add(localPo);
            }
        }
        txDao.saveTxList(poList);
        if (localPoList.size() > 0) {
            txDao.saveLocalList(localPoList);
        }
    } finally {
        lock.unlock();
    }
    return false;
}
Also used : TransferTransaction(io.nuls.ledger.entity.tx.TransferTransaction) AbstractCoinTransaction(io.nuls.ledger.entity.tx.AbstractCoinTransaction) LockNulsTransaction(io.nuls.ledger.entity.tx.LockNulsTransaction) NulsException(io.nuls.core.exception.NulsException) TransactionLocalPo(io.nuls.db.entity.TransactionLocalPo) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) TransactionPo(io.nuls.db.entity.TransactionPo) DbSession(io.nuls.db.transactional.annotation.DbSession)

Example 2 with TransactionPo

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

the class UtxoLedgerServiceImpl method saveTxInLocal.

@Override
@DbSession
public void saveTxInLocal(String address) {
    List<TransactionPo> poList = txDao.getTxs(null, address, 0, 0, 0);
    if (poList.isEmpty()) {
        return;
    }
    List<TransactionLocalPo> localPoList = new ArrayList<>();
    for (TransactionPo po : poList) {
        TransactionLocalPo localPo = txDao.getLocaltx(po.getHash());
        if (localPo != null) {
            continue;
        }
        localPo = new TransactionLocalPo(po);
        for (UtxoInputPo inputPo : po.getInputs()) {
            if (inputPo.getFromOutPut().getAddress().equals(address)) {
                localPo.setTransferType(Transaction.TRANSFER_SEND);
                break;
            }
        }
        localPoList.add(localPo);
    }
    txDao.saveLocalList(localPoList);
}
Also used : TransactionLocalPo(io.nuls.db.entity.TransactionLocalPo) ArrayList(java.util.ArrayList) UtxoInputPo(io.nuls.db.entity.UtxoInputPo) TransactionPo(io.nuls.db.entity.TransactionPo) DbSession(io.nuls.db.transactional.annotation.DbSession)

Example 3 with TransactionPo

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

the class TransactionDaoImpl method getTxs.

@Override
public List<TransactionPo> 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<TransactionPo> localPoList = getMapper().selectByAddress(searchable);
    return localPoList;
}
Also used : TransactionPo(io.nuls.db.entity.TransactionPo) Searchable(io.nuls.db.dao.impl.mybatis.util.Searchable)

Example 4 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 height) throws Exception {
    List<Transaction> txList = new ArrayList<>();
    List<TransactionPo> poList = txDao.getTxs(height);
    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 5 with TransactionPo

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

the class AccountServiceImpl method exportAccounts.

private Result exportAccounts(List<Account> accounts, File backupFile) {
    FileOutputStream fos = null;
    List<TransactionPo> txList;
    TransactionPo tx;
    try {
        fos = new FileOutputStream(backupFile);
        // account length
        fos.write(new VarInt(accounts.size()).encode());
    } catch (Exception e) {
        Log.error(e);
        return new Result(false, "export failed");
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
            }
        }
    }
    return new Result(true, "OK");
}
Also used : FileOutputStream(java.io.FileOutputStream) TransactionPo(io.nuls.db.entity.TransactionPo) IOException(java.io.IOException) 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)

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