use of io.nuls.kernel.utils.NulsByteBuffer 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.kernel.utils.NulsByteBuffer in project nuls by nuls-io.
the class TransactionCacheStorageServiceImpl method getTx.
@Override
public Transaction getTx(NulsDigestData hash) {
if (hash == null) {
return null;
}
byte[] hashBytes = null;
try {
hashBytes = hash.serialize();
} catch (IOException e) {
Log.error(e);
throw new NulsRuntimeException(e);
}
byte[] txBytes = dbService.get(TRANSACTION_CACHE_KEY_NAME, hashBytes);
Transaction tx = null;
if (null != txBytes) {
try {
tx = TransactionManager.getInstance(new NulsByteBuffer(txBytes, 0));
} catch (Exception e) {
Log.error(e);
return null;
}
}
return tx;
}
use of io.nuls.kernel.utils.NulsByteBuffer in project nuls by nuls-io.
the class RandomSeedsStorageServiceImpl method getSeed.
@Override
public RandomSeedPo getSeed(long height) {
byte[] bytes = dbService.get(ConsensusStorageConstant.DB_NAME_RANDOM_SEEDS, SerializeUtils.uint64ToByteArray(height));
if (null == bytes) {
return null;
}
RandomSeedPo po = new RandomSeedPo();
try {
po.parse(new NulsByteBuffer(bytes, 0));
po.setHeight(height);
} catch (NulsException e) {
Log.error(e);
}
return po;
}
use of io.nuls.kernel.utils.NulsByteBuffer in project nuls by nuls-io.
the class RandomSeedsStorageServiceImpl method getAddressStatus.
@Override
public RandomSeedStatusPo getAddressStatus(byte[] address) {
byte[] bytes = dbService.get(ConsensusStorageConstant.DB_NAME_RANDOM_SEEDS, address);
if (null == bytes) {
return null;
}
RandomSeedStatusPo po = new RandomSeedStatusPo();
try {
po.parse(new NulsByteBuffer(bytes, 0));
po.setAddress(address);
} catch (NulsException e) {
Log.error(e);
}
return po;
}
use of io.nuls.kernel.utils.NulsByteBuffer in project nuls by nuls-io.
the class TransactionCacheStorageServiceImpl method pollTx.
@Override
public Transaction pollTx() {
byte[] startIndexBytes = Util.intToBytes(startIndex.get());
byte[] hashBytes = dbService.get(TRANSACTION_CACHE_KEY_NAME, startIndexBytes);
if (hashBytes == null) {
return null;
}
byte[] txBytes = dbService.get(TRANSACTION_CACHE_KEY_NAME, hashBytes);
Transaction tx = null;
if (null != txBytes) {
try {
tx = TransactionManager.getInstance(new NulsByteBuffer(txBytes, 0));
} catch (Exception e) {
Log.error(e);
return null;
}
}
startIndex.incrementAndGet();
return tx;
}
Aggregations