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