Search in sources :

Example 1 with EventPublishingAccount

use of com.jd.blockchain.ledger.core.EventPublishingAccount 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 2 with EventPublishingAccount

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

Example 3 with EventPublishingAccount

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

the class LedgerQueryController method getLatestUserEvent.

@RequestMapping(method = RequestMethod.GET, path = GET_LATEST_EVENT)
@Override
public Event getLatestUserEvent(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address, @PathVariable(name = "eventName") String eventName) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    EventPublishingAccount account = ledger.getEventAccountSet(ledger.getLatestBlock()).getAccount(address);
    if (null == account) {
        return null;
    }
    return account.getLatest(eventName);
}
Also used : LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) EventPublishingAccount(com.jd.blockchain.ledger.core.EventPublishingAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with EventPublishingAccount

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

the class LedgerQueryController method getUserEventsTotalCount.

@RequestMapping(method = RequestMethod.GET, path = GET_EVENT_COUNT)
@Override
public long getUserEventsTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address, @PathVariable(name = "eventName") String eventName) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    EventPublishingAccount account = ledger.getEventAccountSet(ledger.getLatestBlock()).getAccount(address);
    if (null == account) {
        return 0;
    }
    return account.totalEvents(eventName);
}
Also used : LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) EventPublishingAccount(com.jd.blockchain.ledger.core.EventPublishingAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with EventPublishingAccount

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

the class LedgerQueryController method getUserEventNames.

@RequestMapping(method = RequestMethod.GET, path = GET_EVENT_SUBJECTS)
@Override
public String[] getUserEventNames(@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();
    EventPublishingAccount account = ledger.getEventAccountSet(block).getAccount(address);
    if (null == account) {
        return null;
    }
    QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, (int) account.totalEventNames());
    return account.getEventNames(queryArgs.getFrom(), queryArgs.getCount());
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) QueryArgs(utils.query.QueryArgs) EventPublishingAccount(com.jd.blockchain.ledger.core.EventPublishingAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EventPublishingAccount (com.jd.blockchain.ledger.core.EventPublishingAccount)5 LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)2 EventAccountSet (com.jd.blockchain.ledger.core.EventAccountSet)1 QueryArgs (utils.query.QueryArgs)1