Search in sources :

Example 11 with LedgerTransaction

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);
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) QueryArgs(utils.query.QueryArgs) TransactionSet(com.jd.blockchain.ledger.core.TransactionSet) LedgerTransaction(com.jd.blockchain.ledger.LedgerTransaction) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LedgerTransaction (com.jd.blockchain.ledger.LedgerTransaction)11 LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)8 HashDigest (com.jd.blockchain.crypto.HashDigest)5 LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 BlockchainKeypair (com.jd.blockchain.ledger.BlockchainKeypair)4 MemoryKVStorage (com.jd.blockchain.storage.service.utils.MemoryKVStorage)4 Test (org.junit.Test)4 QueryArgs (utils.query.QueryArgs)4 TransactionRequest (com.jd.blockchain.ledger.TransactionRequest)3 TransactionResult (com.jd.blockchain.ledger.TransactionResult)3 LedgerEditor (com.jd.blockchain.ledger.core.LedgerEditor)3 LedgerManager (com.jd.blockchain.ledger.core.LedgerManager)3 LedgerRepository (com.jd.blockchain.ledger.core.LedgerRepository)3 TransactionSet (com.jd.blockchain.ledger.core.TransactionSet)3 CryptoSetting (com.jd.blockchain.ledger.CryptoSetting)2 LedgerTransactionContext (com.jd.blockchain.ledger.core.LedgerTransactionContext)2 TransactionSetEditor (com.jd.blockchain.ledger.core.TransactionSetEditor)2 AsymmetricKeypair (com.jd.blockchain.crypto.AsymmetricKeypair)1 BytesValue (com.jd.blockchain.ledger.BytesValue)1