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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations