Search in sources :

Example 6 with DataEntry

use of utils.DataEntry in project jdchain-core by blockchain-jd-com.

the class MerkleHashDataset method getDataEntries.

@Override
public DataEntry<Bytes, byte[]>[] getDataEntries(long fromIndex, int count) {
    if (count > LedgerConsts.MAX_LIST_COUNT) {
        throw new IllegalArgumentException("Count exceed the upper limit[" + LedgerConsts.MAX_LIST_COUNT + "]!");
    }
    if (fromIndex < 0 || (fromIndex + count) > merkleTree.getTotalKeys()) {
        throw new IllegalArgumentException("Index out of bound!");
    }
    if (count == 0) {
        return EMPTY_ENTRIES;
    }
    @SuppressWarnings("unchecked") DataEntry<Bytes, byte[]>[] values = new DataEntry[count];
    byte[] bytesValue;
    SkippingIterator<KVEntry> iterator = merkleTree.iterator();
    iterator.skip(fromIndex);
    for (int i = 0; i < count && iterator.hasNext(); i++) {
        KVEntry dataNode = iterator.next();
        Bytes dataKey = encodeDataKey(dataNode.getKey());
        bytesValue = valueStorage.get(dataKey, dataNode.getVersion());
        values[i] = new VersioningKVData<Bytes, byte[]>(dataNode.getKey(), dataNode.getVersion(), bytesValue);
    }
    return values;
}
Also used : DataEntry(utils.DataEntry) Bytes(utils.Bytes) KVEntry(com.jd.blockchain.ledger.merkletree.KVEntry)

Example 7 with DataEntry

use of utils.DataEntry in project jdchain-core by blockchain-jd-com.

the class KvDataset method getDataEntries.

@Override
public DataEntry<Bytes, byte[]>[] getDataEntries(long fromIndex, int count) {
    if (count > LedgerConsts.MAX_LIST_COUNT) {
        throw new IllegalArgumentException("Count exceed the upper limit[" + LedgerConsts.MAX_LIST_COUNT + "]!");
    }
    if (fromIndex < 0 || (fromIndex + count) > getDataCount()) {
        throw new IllegalArgumentException("Index out of bound!");
    }
    if (count == 0) {
        return EMPTY_ENTRIES;
    }
    @SuppressWarnings("unchecked") DataEntry<Bytes, byte[]>[] values = new DataEntry[count];
    byte[] bytesValue;
    for (int i = 0; i < count; i++) {
        byte[] key = getValueAt(fromIndex + i);
        DataEntry<Bytes, byte[]> entry = getDataEntry(new Bytes(key));
        values[i] = entry;
    }
    return values;
}
Also used : DataEntry(utils.DataEntry) Bytes(utils.Bytes)

Example 8 with DataEntry

use of utils.DataEntry in project jdchain-core by blockchain-jd-com.

the class UncommittedLedgerQueryService method getDataEntries.

@Override
public TypedKVEntry[] getDataEntries(String address, int fromIndex, int count) {
    DataAccountSet dataAccountSet = transactionContext.getDataset().getDataAccountSet();
    DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));
    QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount());
    SkippingIterator<DataEntry<String, TypedValue>> iterator = ((IteratorDataset) dataAccount.getDataset()).kvIterator();
    iterator.skip(queryArgs.getFrom());
    TypedKVEntry[] typedKVEntries = iterator.next(queryArgs.getCount(), TypedKVEntry.class, entry -> new TypedKVData(entry.getKey(), entry.getVersion(), entry.getValue()));
    return typedKVEntries;
}
Also used : DataAccount(com.jd.blockchain.ledger.core.DataAccount) DataEntry(utils.DataEntry) TypedKVEntry(com.jd.blockchain.ledger.TypedKVEntry) TypedKVData(com.jd.blockchain.ledger.TypedKVData) QueryArgs(utils.query.QueryArgs) IteratorDataset(com.jd.blockchain.ledger.core.IteratorDataset) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet)

Example 9 with DataEntry

use of utils.DataEntry in project jdchain-core by blockchain-jd-com.

the class UserRoleDatasetEditor method getUserRoles.

@Override
public UserRoles[] getUserRoles() {
    DataEntry<Bytes, byte[]>[] kvEntries = dataset.getDataEntries(0, (int) dataset.getDataCount());
    UserRoles[] pns = new UserRoles[kvEntries.length];
    RoleSet roleset;
    for (int i = 0; i < pns.length; i++) {
        roleset = BinaryProtocol.decode(kvEntries[i].getValue());
        pns[i] = new UserRoles(kvEntries[i].getKey(), kvEntries[i].getVersion(), roleset);
    }
    return pns;
}
Also used : DataEntry(utils.DataEntry) RoleSet(com.jd.blockchain.ledger.RoleSet) UserRoles(com.jd.blockchain.ledger.UserRoles)

Example 10 with DataEntry

use of utils.DataEntry in project jdchain-core by blockchain-jd-com.

the class LedgerQueryController method getDataEntries.

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, path = GET_LATEST_KV_SEQUENCE)
@Override
public TypedKVEntry[] getDataEntries(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
    DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));
    if (dataAccount == null) {
        return null;
    }
    QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount());
    fromIndex = queryArgs.getFrom();
    count = queryArgs.getCount();
    SkippingIterator<DataEntry<String, TypedValue>> iterator = ((IteratorDataset) dataAccount.getDataset()).kvIterator();
    iterator.skip(fromIndex);
    TypedKVEntry[] typedKVEntries = iterator.next(count, TypedKVEntry.class, new Mapper<DataEntry<String, TypedValue>, TypedKVEntry>() {

        @Override
        public TypedKVEntry from(DataEntry<String, TypedValue> entry) {
            return entry == null ? null : new TypedKVData(entry.getKey(), entry.getVersion(), entry.getValue());
        }
    });
    return typedKVEntries;
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) DataAccount(com.jd.blockchain.ledger.core.DataAccount) DataEntry(utils.DataEntry) TypedKVEntry(com.jd.blockchain.ledger.TypedKVEntry) TypedKVData(com.jd.blockchain.ledger.TypedKVData) QueryArgs(utils.query.QueryArgs) IteratorDataset(com.jd.blockchain.ledger.core.IteratorDataset) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet) TypedValue(com.jd.blockchain.ledger.TypedValue) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataEntry (utils.DataEntry)10 QueryArgs (utils.query.QueryArgs)4 TypedKVData (com.jd.blockchain.ledger.TypedKVData)3 TypedKVEntry (com.jd.blockchain.ledger.TypedKVEntry)3 DataAccount (com.jd.blockchain.ledger.core.DataAccount)3 DataAccountSet (com.jd.blockchain.ledger.core.DataAccountSet)3 IteratorDataset (com.jd.blockchain.ledger.core.IteratorDataset)3 Bytes (utils.Bytes)3 HashDigest (com.jd.blockchain.crypto.HashDigest)2 MerkleProof (com.jd.blockchain.ledger.MerkleProof)2 MerkleHashDataset (com.jd.blockchain.ledger.core.MerkleHashDataset)2 MemoryKVStorage (com.jd.blockchain.storage.service.utils.MemoryKVStorage)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Random (java.util.Random)2 Test (org.junit.Test)2 Dataset (utils.Dataset)2 CryptoProvider (com.jd.blockchain.crypto.CryptoProvider)1 CryptoSetting (com.jd.blockchain.ledger.CryptoSetting)1