use of io.nuls.db.model.Entry in project nuls by nuls-io.
the class BalanceManager method getCoinListByAddress.
public List<Coin> getCoinListByAddress(byte[] address) {
List<Coin> coinList = new ArrayList<>();
Collection<Entry<byte[], byte[]>> rawList = localUtxoStorageService.loadAllCoinList();
for (Entry<byte[], byte[]> coinEntry : rawList) {
Coin coin = new Coin();
try {
coin.parse(coinEntry.getValue(), 0);
} catch (NulsException e) {
Log.info("parse coin form db error");
continue;
}
if (Arrays.equals(coin.getAddress(), address)) {
coin.setTempOwner(coin.getOwner());
coin.setOwner(coinEntry.getKey());
coinList.add(coin);
}
}
return coinList;
}
use of io.nuls.db.model.Entry in project nuls by nuls-io.
the class ContractAddressStorageServiceImpl method getAllContractInfoList.
@Override
public Result<List<ContractAddressInfoPo>> getAllContractInfoList() {
List<Entry<byte[], ContractAddressInfoPo>> list = dbService.entryList(ContractStorageConstant.DB_NAME_CONTRACT_ADDRESS, ContractAddressInfoPo.class);
if (list == null || list.size() == 0) {
return Result.getFailed(KernelErrorCode.DATA_NOT_FOUND);
}
List<ContractAddressInfoPo> resultList = new ArrayList<>();
ContractAddressInfoPo po;
for (Entry<byte[], ContractAddressInfoPo> entry : list) {
po = entry.getValue();
po.setContractAddress(entry.getKey());
resultList.add(po);
}
Result<List<ContractAddressInfoPo>> result = Result.getSuccess();
result.setData(resultList);
return result;
}
use of io.nuls.db.model.Entry in project nuls by nuls-io.
the class ContractUtxoStorageServiceImpl method batchSaveAndDeleteUTXO.
@Override
public Result<List<Entry<byte[], byte[]>>> batchSaveAndDeleteUTXO(List<Entry<byte[], byte[]>> utxosToSave, List<byte[]> utxosToDelete) {
BatchOperation batch = dbService.createWriteBatch(ContractStorageConstant.DB_NAME_CONTRACT_LEDGER_UTXO);
List<Entry<byte[], byte[]>> deleteUtxoEntryList = new ArrayList<>();
byte[] deleteUtxo;
if (utxosToDelete != null) {
for (byte[] key : utxosToDelete) {
batch.delete(key);
}
}
if (utxosToSave != null) {
for (Entry<byte[], byte[]> entry : utxosToSave) {
batch.put(entry.getKey(), entry.getValue());
}
}
Result batchResult = batch.executeBatch();
if (batchResult.isFailed()) {
return batchResult;
}
return Result.getSuccess().setData(deleteUtxoEntryList);
}
use of io.nuls.db.model.Entry in project nuls by nuls-io.
the class ContractBalanceManager method getCoinListByAddress.
public List<Coin> getCoinListByAddress(byte[] address) {
List<Coin> coinList = new ArrayList<>();
List<Entry<byte[], byte[]>> rawList = contractUtxoStorageService.loadAllCoinList();
for (Entry<byte[], byte[]> coinEntry : rawList) {
Coin coin = new Coin();
try {
coin.parse(coinEntry.getValue(), 0);
} catch (NulsException e) {
Log.info("parse coin form db error");
continue;
}
if (Arrays.equals(coin.getAddress(), address)) {
coin.setOwner(coinEntry.getKey());
coin.setKey(asString(coinEntry.getKey()));
coinList.add(coin);
}
}
return coinList;
}
use of io.nuls.db.model.Entry in project nuls by nuls-io.
the class LevelDBManager method entrySet.
public static Set<Entry<byte[], byte[]>> entrySet(String area) {
if (!baseCheckArea(area)) {
return null;
}
DBIterator iterator = null;
Set<Entry<byte[], byte[]>> entrySet;
try {
DB db = AREAS.get(area);
entrySet = new HashSet<>();
iterator = db.iterator();
byte[] key, bytes;
Map.Entry<byte[], byte[]> entry;
for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
entry = iterator.peekNext();
key = entry.getKey();
bytes = entry.getValue();
entrySet.add(new Entry<byte[], byte[]>(key, bytes));
}
} catch (Exception e) {
Log.error(e);
return null;
} finally {
// Make sure you close the iterator to avoid resource leaks.
if (iterator != null) {
try {
iterator.close();
} catch (Exception e) {
// skip it
}
}
}
return entrySet;
}
Aggregations