use of com.jd.blockchain.ledger.core.LedgerQuery 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);
}
use of com.jd.blockchain.ledger.core.LedgerQuery in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getUser.
@RequestMapping(method = RequestMethod.GET, path = GET_USER)
@Override
public UserInfo getUser(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
UserAccountSet userAccountSet = ledger.getUserAccountSet(block);
return userAccountSet.getAccount(address);
}
use of com.jd.blockchain.ledger.core.LedgerQuery in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getSystemEventNames.
@RequestMapping(method = RequestMethod.GET, path = GET_SYSTEM_EVENT_SUBJECTS)
@Override
public String[] getSystemEventNames(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "maxCount", required = false, defaultValue = "-1") int count) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
EventGroup systemEvents = ledger.getSystemEventGroup(block);
QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, (int) systemEvents.totalEventNames());
return systemEvents.getEventNames(queryArgs.getFrom(), queryArgs.getCount());
}
use of com.jd.blockchain.ledger.core.LedgerQuery in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getTransactions.
@RequestMapping(method = RequestMethod.GET, path = GET_TRANSACTIONS_ON_BLOCK_HEIGHT)
@Override
public LedgerTransaction[] getTransactions(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "blockHeight") long blockHeight, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock ledgerBlock = ledger.getBlock(blockHeight);
if (null == ledgerBlock) {
return null;
}
QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, (int) ledger.getTransactionSet(ledgerBlock).getTotalCount());
LedgerTransaction[] txs = ledger.getTransactionSet(ledgerBlock).getTransactions(queryArgs.getFrom(), queryArgs.getCount());
return txsDecorator(txs);
// LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
// LedgerBlock ledgerBlock = ledger.getBlock(blockHeight);
// TransactionQuery transactionSet = ledger.getTransactionSet(ledgerBlock);
// TransactionQuery origTransactionSet = null;
//
// int lastHeightTxTotalNums = 0;
//
// if (blockHeight > 0) {
// origTransactionSet = ledger.getTransactionSet(ledger.getBlock(blockHeight - 1));
// lastHeightTxTotalNums = (int) origTransactionSet.getTotalCount();
// }
//
// int currentHeightTxTotalNums = (int) ledger.getTransactionSet(ledger.getBlock(blockHeight)).getTotalCount();
// // 取当前高度的增量交易数,在增量交易里进行查找
// int currentHeightTxNums = currentHeightTxTotalNums - lastHeightTxTotalNums;
//
// QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, currentHeightTxNums);
// LedgerTransaction[] txs = transactionSet.getBlockTxs(queryArgs.getFrom(), queryArgs.getCount(), origTransactionSet);
// return txsDecorator(txs);
}
use of com.jd.blockchain.ledger.core.LedgerQuery in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getContractCount.
@RequestMapping(method = RequestMethod.GET, path = GET_CONTRACT_COUNT_ON_BLOCK_HEIGHT)
@Override
public long getContractCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "blockHeight") long height) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(height);
if (null == block) {
return 0;
}
ContractAccountSet contractAccountSet = ledger.getContractAccountSet(block);
return contractAccountSet.getTotal();
}
Aggregations