Search in sources :

Example 36 with LedgerQuery

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

the class LedgerQueryController method getTransactionStateByContentHash.

@RequestMapping(method = RequestMethod.GET, path = GET_TRANSACTION_STATE)
@Override
public TransactionState getTransactionStateByContentHash(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "contentHash") HashDigest contentHash) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    TransactionSet txset = ledger.getTransactionSet(block);
    return txset.getState(contentHash);
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) TransactionSet(com.jd.blockchain.ledger.core.TransactionSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with LedgerQuery

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

Example 38 with LedgerQuery

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

the class LedgerQueryController method getDataEntriesTotalCount.

@RequestMapping(method = RequestMethod.GET, path = GET_KV_COUNT)
@Override
public long getDataEntriesTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address) {
    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 0;
    }
    return dataAccount.getDataset().getDataCount();
}
Also used : DataAccount(com.jd.blockchain.ledger.core.DataAccount) 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 39 with LedgerQuery

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

the class LedgerQueryController method getUserEventAccount.

@RequestMapping(method = RequestMethod.GET, path = GET_EVENT_ACCOUNT)
@Override
public EventPublishingAccount getUserEventAccount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    EventAccountSet eventAccountSet = ledger.getEventAccountSet(ledger.getLatestBlock());
    return eventAccountSet.getAccount(address);
}
Also used : LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) EventAccountSet(com.jd.blockchain.ledger.core.EventAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 40 with LedgerQuery

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

the class LedgerQueryController method getLatestSystemEvent.

@RequestMapping(method = RequestMethod.GET, path = GET_LATEST_SYSTEM_EVENT)
@Override
public Event getLatestSystemEvent(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "eventName") String eventName) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    EventGroup systemEvents = ledger.getSystemEventGroup(block);
    return systemEvents.getLatest(eventName);
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) EventGroup(com.jd.blockchain.ledger.core.EventGroup) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)45 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)45 LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)36 QueryArgs (utils.query.QueryArgs)11 DataAccountSet (com.jd.blockchain.ledger.core.DataAccountSet)9 TransactionSet (com.jd.blockchain.ledger.core.TransactionSet)7 ContractAccountSet (com.jd.blockchain.ledger.core.ContractAccountSet)6 LedgerTransaction (com.jd.blockchain.ledger.LedgerTransaction)5 EventGroup (com.jd.blockchain.ledger.core.EventGroup)5 EventPublishingAccount (com.jd.blockchain.ledger.core.EventPublishingAccount)5 UserAccountSet (com.jd.blockchain.ledger.core.UserAccountSet)5 BlockchainIdentity (com.jd.blockchain.ledger.BlockchainIdentity)4 DataAccount (com.jd.blockchain.ledger.core.DataAccount)4 EventAccountSet (com.jd.blockchain.ledger.core.EventAccountSet)4 TypedKVData (com.jd.blockchain.ledger.TypedKVData)3 TypedKVEntry (com.jd.blockchain.ledger.TypedKVEntry)3 BytesValue (com.jd.blockchain.ledger.BytesValue)2 LedgerAdminInfo (com.jd.blockchain.ledger.LedgerAdminInfo)2 ContractException (com.jd.blockchain.contract.ContractException)1 KVDataVO (com.jd.blockchain.ledger.KVDataVO)1