Search in sources :

Example 6 with TypedKVData

use of com.jd.blockchain.ledger.TypedKVData in project jdchain-core by blockchain-jd-com.

the class UncommittedLedgerQueryService method getDataEntries.

@Override
public TypedKVEntry[] getDataEntries(String address, String... keys) {
    DataAccount account = transactionContext.getDataset().getDataAccountSet().getAccount(address);
    TypedKVEntry[] entries = new TypedKVEntry[keys.length];
    long ver;
    for (int i = 0; i < entries.length; i++) {
        final String currKey = keys[i];
        ver = account == null ? -1 : account.getDataset().getVersion(currKey);
        if (ver < 0) {
            entries[i] = new TypedKVData(currKey, -1, null);
        } else {
            BytesValue value = account.getDataset().getValue(currKey, ver);
            entries[i] = new TypedKVData(currKey, ver, value);
        }
    }
    return entries;
}
Also used : DataAccount(com.jd.blockchain.ledger.core.DataAccount) TypedKVEntry(com.jd.blockchain.ledger.TypedKVEntry) TypedKVData(com.jd.blockchain.ledger.TypedKVData) BytesValue(com.jd.blockchain.ledger.BytesValue)

Example 7 with TypedKVData

use of com.jd.blockchain.ledger.TypedKVData in project jdchain-core by blockchain-jd-com.

the class UncommittedLedgerQueryService method getDataEntry.

@Override
public TypedKVEntry getDataEntry(String address, String key, long version) {
    DataAccount account = transactionContext.getDataset().getDataAccountSet().getAccount(address);
    if (null == account) {
        return null;
    }
    BytesValue value = account.getDataset().getValue(key, version);
    if (null == value) {
        return null;
    }
    return new TypedKVData(key, version, value);
}
Also used : DataAccount(com.jd.blockchain.ledger.core.DataAccount) TypedKVData(com.jd.blockchain.ledger.TypedKVData) BytesValue(com.jd.blockchain.ledger.BytesValue)

Example 8 with TypedKVData

use of com.jd.blockchain.ledger.TypedKVData 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 TypedKVData

use of com.jd.blockchain.ledger.TypedKVData in project jdchain-core by blockchain-jd-com.

the class UncommittedLedgerQueryService method getDataEntries.

@Override
public TypedKVEntry[] getDataEntries(String address, KVInfoVO kvInfoVO) {
    List<String> keyList = new ArrayList<>();
    List<Long> versionList = new ArrayList<>();
    if (kvInfoVO != null) {
        for (KVDataVO kvDataVO : kvInfoVO.getData()) {
            for (Long version : kvDataVO.getVersion()) {
                keyList.add(kvDataVO.getKey());
                versionList.add(version);
            }
        }
    }
    String[] keys = keyList.toArray(new String[keyList.size()]);
    Long[] versions = versionList.toArray(new Long[versionList.size()]);
    if (keys.length == 0) {
        return null;
    }
    if (versions.length == 0) {
        return null;
    }
    if (keys.length != versions.length) {
        throw null;
    }
    DataAccount dataAccount = transactionContext.getDataset().getDataAccountSet().getAccount(address);
    TypedKVEntry[] entries = new TypedKVEntry[keys.length];
    long ver = -1L;
    for (int i = 0; i < entries.length; i++) {
        ver = versions[i];
        if (ver < 0) {
            entries[i] = new TypedKVData(keys[i], -1, null);
        } else {
            if (dataAccount.getDataset().getDataCount() == 0 || dataAccount.getDataset().getValue(keys[i], ver) == null) {
                // is the address is not exist; the result is null;
                entries[i] = new TypedKVData(keys[i], -1, null);
            } else {
                BytesValue value = dataAccount.getDataset().getValue(keys[i], ver);
                entries[i] = new TypedKVData(keys[i], ver, value);
            }
        }
    }
    return entries;
}
Also used : ArrayList(java.util.ArrayList) KVDataVO(com.jd.blockchain.ledger.KVDataVO) BytesValue(com.jd.blockchain.ledger.BytesValue) DataAccount(com.jd.blockchain.ledger.core.DataAccount) TypedKVEntry(com.jd.blockchain.ledger.TypedKVEntry) TypedKVData(com.jd.blockchain.ledger.TypedKVData)

Example 10 with TypedKVData

use of com.jd.blockchain.ledger.TypedKVData in project jdchain-core by blockchain-jd-com.

the class ContractLedgerQueryService method getDataEntries.

@Override
public TypedKVEntry[] getDataEntries(String address, KVInfoVO kvInfoVO) {
    List<String> keyList = new ArrayList<>();
    List<Long> versionList = new ArrayList<>();
    if (kvInfoVO != null) {
        for (KVDataVO kvDataVO : kvInfoVO.getData()) {
            for (Long version : kvDataVO.getVersion()) {
                keyList.add(kvDataVO.getKey());
                versionList.add(version);
            }
        }
    }
    String[] keys = keyList.toArray(new String[keyList.size()]);
    Long[] versions = versionList.toArray(new Long[versionList.size()]);
    if (keys.length == 0) {
        return null;
    }
    if (versions.length == 0) {
        return null;
    }
    if (keys.length != versions.length) {
        throw null;
    }
    DataAccount dataAccount = ledgerQuery.getDataAccountSet().getAccount(address);
    TypedKVEntry[] entries = new TypedKVEntry[keys.length];
    long ver = -1L;
    for (int i = 0; i < entries.length; i++) {
        ver = versions[i];
        if (ver < 0) {
            entries[i] = new TypedKVData(keys[i], -1, null);
        } else {
            if (dataAccount.getDataset().getDataCount() == 0 || dataAccount.getDataset().getValue(keys[i], ver) == null) {
                // is the address is not exist; the result is null;
                entries[i] = new TypedKVData(keys[i], -1, null);
            } else {
                BytesValue value = dataAccount.getDataset().getValue(keys[i], ver);
                entries[i] = new TypedKVData(keys[i], ver, value);
            }
        }
    }
    return entries;
}
Also used : ArrayList(java.util.ArrayList) KVDataVO(com.jd.blockchain.ledger.KVDataVO) BytesValue(com.jd.blockchain.ledger.BytesValue) DataAccount(com.jd.blockchain.ledger.core.DataAccount) TypedKVEntry(com.jd.blockchain.ledger.TypedKVEntry) TypedKVData(com.jd.blockchain.ledger.TypedKVData)

Aggregations

TypedKVData (com.jd.blockchain.ledger.TypedKVData)11 DataAccount (com.jd.blockchain.ledger.core.DataAccount)11 TypedKVEntry (com.jd.blockchain.ledger.TypedKVEntry)9 BytesValue (com.jd.blockchain.ledger.BytesValue)8 DataAccountSet (com.jd.blockchain.ledger.core.DataAccountSet)5 KVDataVO (com.jd.blockchain.ledger.KVDataVO)3 LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)3 IteratorDataset (com.jd.blockchain.ledger.core.IteratorDataset)3 LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)3 ArrayList (java.util.ArrayList)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 DataEntry (utils.DataEntry)3 QueryArgs (utils.query.QueryArgs)3 ContractException (com.jd.blockchain.contract.ContractException)1 TypedValue (com.jd.blockchain.ledger.TypedValue)1