Search in sources :

Example 6 with LedgerQuery

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

the class LedgerQueryController method getUserEvents.

@RequestMapping(method = RequestMethod.GET, path = GET_EVENT_SEQUENCE)
@Override
public Event[] getUserEvents(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address, @PathVariable(name = "eventName") String eventName, @RequestParam(name = "fromSequence", required = false, defaultValue = "0") long fromSequence, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    EventPublishingAccount account = ledger.getEventAccountSet(block).getAccount(address);
    if (null == account) {
        return null;
    }
    return account.getEvents(eventName, fromSequence, count);
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) EventPublishingAccount(com.jd.blockchain.ledger.core.EventPublishingAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with LedgerQuery

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

the class LedgerQueryController method getContractAccounts.

@RequestMapping(method = RequestMethod.GET, path = GET_CONTRACT_ACCOUNT_SEQUENCE)
@Override
public BlockchainIdentity[] getContractAccounts(@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();
    ContractAccountSet contractAccountSet = ledger.getContractAccountSet(block);
    QueryArgs queryArgs = QueryUtils.calFromIndexAndCountDescend(fromIndex, count, (int) contractAccountSet.getTotal());
    SkippingIterator<BlockchainIdentity> it = contractAccountSet.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) ContractAccountSet(com.jd.blockchain.ledger.core.ContractAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 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_KV_VERSION_LIST)
@Override
public TypedKVEntry[] getDataEntries(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address, @RequestBody KVInfoVO kvInfoVO) {
    // parse 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 == null || keys.length == 0) {
        return null;
    }
    if (versions == null || versions.length == 0) {
        return null;
    }
    if (keys.length != versions.length) {
        throw new ContractException("keys.length!=versions.length!");
    }
    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;
    }
    TypedKVEntry[] entries = new TypedKVEntry[keys.length];
    long ver = -1;
    for (int i = 0; i < entries.length; i++) {
        // ver = dataAccount.getDataVersion(Bytes.fromString(keys[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 : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) ContractException(com.jd.blockchain.contract.ContractException) 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) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with LedgerQuery

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

the class LedgerQueryController method getTransactionByContentHash.

@RequestMapping(method = RequestMethod.GET, path = GET_TRANSACTION)
@Override
public LedgerTransaction getTransactionByContentHash(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "contentHash") HashDigest contentHash) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    TransactionSet txset = ledger.getTransactionSet(block);
    LedgerTransaction transaction = txset.getTransaction(contentHash);
    // TODO: 去掉包装类,通过修正针对代理对象的 JSON 序列化来解决; by huanghaiquan at 2020-09-21;
    return txDecorator(transaction);
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) TransactionSet(com.jd.blockchain.ledger.core.TransactionSet) LedgerTransaction(com.jd.blockchain.ledger.LedgerTransaction) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with LedgerQuery

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

the class LedgerQueryController method getUserEventNameTotalCount.

@RequestMapping(method = RequestMethod.GET, path = GET_EVENT_SUBJECT_COUNT)
@Override
public long getUserEventNameTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    EventAccountSet eventAccountSet = ledger.getEventAccountSet(ledger.getLatestBlock());
    EventPublishingAccount account = eventAccountSet.getAccount(address);
    if (null == account) {
        return 0;
    }
    return account.totalEventNames();
}
Also used : LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) EventPublishingAccount(com.jd.blockchain.ledger.core.EventPublishingAccount) EventAccountSet(com.jd.blockchain.ledger.core.EventAccountSet) 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