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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations