Search in sources :

Example 1 with Entry

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;
}
Also used : Coin(io.nuls.kernel.model.Coin) Entry(io.nuls.db.model.Entry) NulsException(io.nuls.kernel.exception.NulsException)

Example 2 with Entry

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;
}
Also used : ContractAddressInfoPo(io.nuls.contract.storage.po.ContractAddressInfoPo) Entry(io.nuls.db.model.Entry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 3 with Entry

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);
}
Also used : Entry(io.nuls.db.model.Entry) ArrayList(java.util.ArrayList) BatchOperation(io.nuls.db.service.BatchOperation) Result(io.nuls.kernel.model.Result)

Example 4 with Entry

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;
}
Also used : Coin(io.nuls.kernel.model.Coin) Entry(io.nuls.db.model.Entry) NulsException(io.nuls.kernel.exception.NulsException)

Example 5 with Entry

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;
}
Also used : DBIterator(org.iq80.leveldb.DBIterator) Entry(io.nuls.db.model.Entry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DB(org.iq80.leveldb.DB) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Entry (io.nuls.db.model.Entry)24 ArrayList (java.util.ArrayList)12 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)9 NulsException (io.nuls.kernel.exception.NulsException)8 IOException (java.io.IOException)8 Coin (io.nuls.kernel.model.Coin)6 VarInt (io.nuls.kernel.utils.VarInt)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 List (java.util.List)4 Result (io.nuls.kernel.model.Result)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 DB (org.iq80.leveldb.DB)3 DBIterator (org.iq80.leveldb.DBIterator)3 ContractAddressInfoPo (io.nuls.contract.storage.po.ContractAddressInfoPo)2 BatchOperation (io.nuls.db.service.BatchOperation)2 NulsDigestData (io.nuls.kernel.model.NulsDigestData)2 LedgerUtil.asString (io.nuls.ledger.util.LedgerUtil.asString)2 LinkedList (java.util.LinkedList)2 UnconfirmedTxPo (io.nuls.account.ledger.storage.po.UnconfirmedTxPo)1 AgentPo (io.nuls.consensus.poc.storage.po.AgentPo)1