Search in sources :

Example 1 with TransactionSet

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

the class LedgerQueryController method getTransactionCount.

@RequestMapping(method = RequestMethod.GET, path = GET_TRANSACTION_COUNT_ON_BLOCK_HEIGHT)
@Override
public long getTransactionCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "blockHeight") long blockHeight) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getBlock(blockHeight);
    if (null == block) {
        return 0;
    }
    TransactionSet txSet = ledger.getTransactionSet(block);
    return txSet.getTotalCount();
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) TransactionSet(com.jd.blockchain.ledger.core.TransactionSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with TransactionSet

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

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

the class LedgerQueryController method getTransactionTotalCount.

@RequestMapping(method = RequestMethod.GET, path = GET_TOTAL_TRANSACTION_COUNT)
@Override
public long getTransactionTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    TransactionSet txSet = ledger.getTransactionSet(block);
    return txSet.getTotalCount();
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) TransactionSet(com.jd.blockchain.ledger.core.TransactionSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with TransactionSet

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

the class LedgerQueryController method getAdditionalTransactions.

@RequestMapping(method = RequestMethod.GET, path = GET_TRANSACTIONS_IN_BLOCK_HEIGHT)
@Override
public LedgerTransaction[] getAdditionalTransactions(@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;
    }
    TransactionSet currTransactionSet = ledger.getTransactionSet(ledgerBlock);
    TransactionSet lastTransactionSet = null;
    int lastHeightTxTotalNums = 0;
    if (blockHeight > 0) {
        lastTransactionSet = ledger.getTransactionSet(ledger.getBlock(blockHeight - 1));
        lastHeightTxTotalNums = (int) lastTransactionSet.getTotalCount();
    }
    int currentHeightTxTotalNums = (int) ledger.getTransactionSet(ledger.getBlock(blockHeight)).getTotalCount();
    // 取当前高度的增量交易数,在增量交易里进行查找
    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)

Example 5 with TransactionSet

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

LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)7 LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)7 TransactionSet (com.jd.blockchain.ledger.core.TransactionSet)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 LedgerTransaction (com.jd.blockchain.ledger.LedgerTransaction)3 QueryArgs (utils.query.QueryArgs)2