use of com.jd.blockchain.ledger.LedgerTransaction in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getAdditionalTransactions.
@RequestMapping(method = RequestMethod.GET, path = GET_TRANSACTIONS_IN_BLOCK_HASH)
@Override
public LedgerTransaction[] getAdditionalTransactions(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "blockHash") HashDigest blockHash, @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(blockHash);
if (null == ledgerBlock) {
return null;
}
long height = ledgerBlock.getHeight();
TransactionSet currTransactionSet = ledger.getTransactionSet(ledgerBlock);
TransactionSet lastTransactionSet = null;
int lastHeightTxTotalNums = 0;
if (height > 0) {
lastTransactionSet = ledger.getTransactionSet(ledger.getBlock(height - 1));
lastHeightTxTotalNums = (int) lastTransactionSet.getTotalCount();
}
int currentHeightTxTotalNums = (int) ledger.getTransactionSet(ledger.getBlock(height)).getTotalCount();
// 取当前块hash的增量交易数,在增量交易里进行查找
int currentHeightTxNums = currentHeightTxTotalNums - lastHeightTxTotalNums;
QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, currentHeightTxNums);
LedgerTransaction[] txs = currTransactionSet.getTransactions(lastHeightTxTotalNums + queryArgs.getFrom(), queryArgs.getCount());
return txsDecorator(txs);
}
Aggregations