Search in sources :

Example 6 with DataAccountSet

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

the class LedgerQueryController method getDataAccountCount.

@RequestMapping(method = RequestMethod.GET, path = GET_DATA_ACCOUNT_COUNT_ON_BLOCK_HASH)
@Override
public long getDataAccountCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "blockHash") HashDigest blockHash) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getBlock(blockHash);
    if (null == block) {
        return 0;
    }
    DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
    return dataAccountSet.getTotal();
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with DataAccountSet

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

the class LedgerQueryController method getDataAccounts.

/**
 * get more dataAccounts by fromIndex and count;
 *
 * @param ledgerHash
 * @param fromIndex
 * @param count
 * @return
 */
@RequestMapping(method = RequestMethod.GET, path = GET_DATA_ACCOUNT_SEQUENCE)
@Override
public BlockchainIdentity[] getDataAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @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);
    QueryArgs queryArgs = QueryUtils.calFromIndexAndCountDescend(fromIndex, count, (int) dataAccountSet.getTotal());
    SkippingIterator<BlockchainIdentity> it = dataAccountSet.identityIterator();
    it.skip(queryArgs.getFrom());
    return it.next(queryArgs.getCount(), BlockchainIdentity.class);
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) QueryArgs(utils.query.QueryArgs) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with DataAccountSet

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

the class LedgerQueryController method getDataAccountTotalCount.

@RequestMapping(method = RequestMethod.GET, path = GET_TOTAL_DATA_ACCOUNT_COUNT)
@Override
public long getDataAccountTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
    return dataAccountSet.getTotal();
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with DataAccountSet

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

the class ContractLedgerQueryService method getDataAccounts.

@Override
public BlockchainIdentity[] getDataAccounts(int fromIndex, int count) {
    DataAccountSet dataAccountSet = ledgerQuery.getDataAccountSet();
    QueryArgs queryArgs = QueryUtils.calFromIndexAndCountDescend(fromIndex, count, (int) dataAccountSet.getTotal());
    SkippingIterator<BlockchainIdentity> it = dataAccountSet.identityIterator();
    it.skip(queryArgs.getFrom());
    return it.next(queryArgs.getCount(), BlockchainIdentity.class);
}
Also used : QueryArgs(utils.query.QueryArgs) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet)

Example 10 with DataAccountSet

use of com.jd.blockchain.ledger.core.DataAccountSet 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)

Aggregations

DataAccountSet (com.jd.blockchain.ledger.core.DataAccountSet)14 LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)9 LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 DataAccount (com.jd.blockchain.ledger.core.DataAccount)6 QueryArgs (utils.query.QueryArgs)6 TypedKVData (com.jd.blockchain.ledger.TypedKVData)5 TypedKVEntry (com.jd.blockchain.ledger.TypedKVEntry)5 BlockchainIdentity (com.jd.blockchain.ledger.BlockchainIdentity)3 IteratorDataset (com.jd.blockchain.ledger.core.IteratorDataset)3 DataEntry (utils.DataEntry)3 BytesValue (com.jd.blockchain.ledger.BytesValue)2 ContractException (com.jd.blockchain.contract.ContractException)1 HashDigest (com.jd.blockchain.crypto.HashDigest)1 KVDataVO (com.jd.blockchain.ledger.KVDataVO)1 TypedValue (com.jd.blockchain.ledger.TypedValue)1 ContractAccountSet (com.jd.blockchain.ledger.core.ContractAccountSet)1 DataAccountSetEditor (com.jd.blockchain.ledger.core.DataAccountSetEditor)1 LedgerDataSetEditor (com.jd.blockchain.ledger.core.LedgerDataSetEditor)1 LedgerEditor (com.jd.blockchain.ledger.core.LedgerEditor)1