Search in sources :

Example 1 with TransactionLocalPo

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

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

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

the class AccountServiceImpl method importSave.

private void importSave(List<Account> accounts) throws Exception {
    List<AccountPo> accountPoList = new ArrayList<>();
    for (Account account : accounts) {
        AccountPo accountPo = new AccountPo();
        AccountTool.toPojo(account, accountPo);
        List<TransactionLocalPo> transactionPos = new ArrayList<>();
        for (Transaction tx : account.getMyTxs()) {
            TransactionLocalPo po = UtxoTransferTool.toLocalTransactionPojo(tx);
            transactionPos.add(po);
        }
        accountPo.setMyTxs(transactionPos);
        accountPoList.add(accountPo);
    }
    accountAliasDBService.importAccount(accountPoList);
}
Also used : Account(io.nuls.account.entity.Account) Transaction(io.nuls.core.chain.entity.Transaction) AliasTransaction(io.nuls.account.entity.tx.AliasTransaction) AccountPo(io.nuls.db.entity.AccountPo) TransactionLocalPo(io.nuls.db.entity.TransactionLocalPo)

Example 4 with TransactionLocalPo

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

the class UtxoTransferTool method toLocalTransactionPojo.

public static TransactionLocalPo toLocalTransactionPojo(Transaction tx) throws IOException {
    TransactionLocalPo po = new TransactionLocalPo();
    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.setTransferType(tx.getTransferType());
    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 : TransactionLocalPo(io.nuls.db.entity.TransactionLocalPo)

Example 5 with TransactionLocalPo

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

the class UtxoLedgerServiceImpl method getLocalTx.

@Override
public Transaction getLocalTx(NulsDigestData hash) {
    Transaction tx = getTxFromCache(hash);
    if (tx != null) {
        return tx;
    }
    TransactionLocalPo po = txDao.getLocaltx(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) TransactionLocalPo(io.nuls.db.entity.TransactionLocalPo) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

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