use of io.nuls.db.model.Entry in project nuls by nuls-io.
the class UnconfiredmTransactionStorageImpl method loadAllUnconfirmedList.
@Override
public Result<List<Transaction>> loadAllUnconfirmedList() {
Result result;
List<UnconfirmedTxPo> tmpList = new ArrayList<>();
List<Entry<byte[], byte[]>> txs = dbService.entryList(AccountLedgerStorageConstant.DB_NAME_ACCOUNT_LEDGER_TX);
for (Entry<byte[], byte[]> txEntry : txs) {
try {
UnconfirmedTxPo tmpTx = new UnconfirmedTxPo(txEntry.getValue());
if (tmpTx != null) {
NulsByteBuffer buffer = new NulsByteBuffer(txEntry.getKey(), 0);
tmpTx.getTx().setHash(buffer.readHash());
tmpList.add(tmpTx);
}
} catch (Exception e) {
Log.warn("parse local tx error", e);
}
}
tmpList.sort(new Comparator<UnconfirmedTxPo>() {
@Override
public int compare(UnconfirmedTxPo o1, UnconfirmedTxPo o2) {
return (int) (o1.getSequence() - o2.getSequence());
}
});
List<Transaction> resultList = new ArrayList<>();
for (UnconfirmedTxPo po : tmpList) {
resultList.add(po.getTx());
}
return Result.getSuccess().setData(resultList);
}
use of io.nuls.db.model.Entry in project nuls by nuls-io.
the class AgentStorageServiceImpl method getList.
@Override
public List<AgentPo> getList() {
List<Entry<byte[], byte[]>> list = dbService.entryList(ConsensusStorageConstant.DB_NAME_CONSENSUS_AGENT);
List<AgentPo> resultList = new ArrayList<>();
if (list == null) {
return resultList;
}
for (Entry<byte[], byte[]> entry : list) {
AgentPo agentPo = new AgentPo();
try {
agentPo.parse(entry.getValue(), 0);
} catch (NulsException e) {
Log.error(e);
throw new NulsRuntimeException(e);
}
NulsDigestData hash = new NulsDigestData();
try {
hash.parse(entry.getKey(), 0);
} catch (NulsException e) {
Log.error(e);
}
agentPo.setHash(hash);
resultList.add(agentPo);
}
return resultList;
}
use of io.nuls.db.model.Entry in project nuls by nuls-io.
the class DepositStorageServiceImpl method getList.
@Override
public List<DepositPo> getList() {
List<Entry<byte[], byte[]>> list = dbService.entryList(ConsensusStorageConstant.DB_NAME_CONSENSUS_DEPOSIT);
List<DepositPo> resultList = new ArrayList<>();
if (list == null) {
return resultList;
}
for (Entry<byte[], byte[]> entry : list) {
DepositPo depositPo = new DepositPo();
try {
depositPo.parse(entry.getValue(), 0);
} catch (NulsException e) {
Log.error(e);
throw new NulsRuntimeException(e);
}
NulsDigestData hash = new NulsDigestData();
try {
hash.parse(entry.getKey(), 0);
} catch (NulsException e) {
Log.error(e);
}
depositPo.setTxHash(hash);
resultList.add(depositPo);
}
return resultList;
}
use of io.nuls.db.model.Entry in project nuls by nuls-io.
the class PunishLogStorageServiceImpl method getPunishList.
@Override
public List<PunishLogPo> getPunishList() {
List<Entry<byte[], byte[]>> list = dbService.entryList(ConsensusStorageConstant.DB_NAME_CONSENSUS_PUNISH_LOG);
List<PunishLogPo> polist = new ArrayList<>();
for (Entry<byte[], byte[]> entry : list) {
PunishLogPo po = new PunishLogPo();
try {
po.parse(entry.getValue(), 0);
} catch (NulsException e) {
throw new NulsRuntimeException(e);
}
polist.add(po);
}
return polist;
}
use of io.nuls.db.model.Entry in project nuls by nuls-io.
the class LocalUtxoServiceImpl method deleteUtxoOfTransaction.
@Override
public Result deleteUtxoOfTransaction(Transaction tx) {
if (tx == null) {
return Result.getFailed(KernelErrorCode.NULL_PARAMETER);
}
CoinData coinData = tx.getCoinData();
if (coinData != null) {
// delete utxo - to
List<Coin> tos = coinData.getTo();
List<byte[]> toList = new ArrayList<>();
byte[] outKey;
for (int i = 0, length = tos.size(); i < length; i++) {
try {
// if(!AccountLegerUtils.isLocalAccount(tos.get(i).getOwner()))
if (null == AccountLegerUtils.isLocalAccount(tos.get(i).getAddress())) {
continue;
}
outKey = ArraysTool.concatenate(tx.getHash().serialize(), new VarInt(i).encode());
toList.add(outKey);
} catch (IOException e) {
throw new NulsRuntimeException(e);
}
}
// save - from
List<Coin> froms = coinData.getFrom();
List<Entry<byte[], byte[]>> fromList = new ArrayList<>();
byte[] fromSource;
Coin fromOfFromCoin;
byte[] utxoFromSource;
byte[] fromIndex;
Transaction sourceTx;
byte[] address;
for (Coin from : froms) {
fromSource = from.getOwner();
fromOfFromCoin = from.getFrom();
if (fromOfFromCoin == null) {
utxoFromSource = new byte[tx.getHash().size()];
fromIndex = new byte[fromSource.length - utxoFromSource.length];
System.arraycopy(fromSource, 0, utxoFromSource, 0, tx.getHash().size());
System.arraycopy(fromSource, tx.getHash().size(), fromIndex, 0, fromIndex.length);
try {
sourceTx = ledgerService.getTx(NulsDigestData.fromDigestHex(Hex.encode(utxoFromSource)));
} catch (Exception e) {
continue;
}
if (sourceTx == null) {
return Result.getFailed(TransactionErrorCode.TX_NOT_EXIST);
}
fromOfFromCoin = sourceTx.getCoinData().getTo().get((int) new VarInt(fromIndex, 0).value);
from.setFrom(fromOfFromCoin);
}
if (fromOfFromCoin == null) {
Log.warn("from coin not found!");
continue;
}
address = fromOfFromCoin.getAddress();
if (null == AccountLegerUtils.isLocalAccount(address)) {
continue;
}
try {
fromList.add(new Entry<>(fromSource, fromOfFromCoin.serialize()));
} catch (IOException e) {
throw new NulsRuntimeException(e);
}
}
Result result = localUtxoStorageService.batchSaveAndDeleteUTXO(fromList, toList);
if (result.isFailed() || result.getData() == null || (int) result.getData() != fromList.size() + toList.size()) {
return Result.getFailed();
}
}
return Result.getSuccess();
}
Aggregations