Search in sources :

Example 41 with LedgerBlock

use of com.jd.blockchain.ledger.LedgerBlock 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();
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) ContractAccountSet(com.jd.blockchain.ledger.core.ContractAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with LedgerBlock

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

Example 43 with LedgerBlock

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

the class LedgerQueryController method getTransactionCount.

@RequestMapping(method = RequestMethod.GET, path = GET_TRANSACTION_COUNT_ON_BLOCK_HASH)
@Override
public long getTransactionCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "blockHash") HashDigest blockHash) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getBlock(blockHash);
    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 44 with LedgerBlock

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

the class LedgerQueryController method getDataAccountCount.

@RequestMapping(method = RequestMethod.GET, path = GET_DATA_ACCOUNT_COUNT_ON_BLOCK_HEIGHT)
@Override
public long getDataAccountCount(@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;
    }
    DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
    return dataAccountSet.getTotal();
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with LedgerBlock

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

the class LedgerQueryController method getContractTotalCount.

@RequestMapping(method = RequestMethod.GET, path = GET_TOTAL_CONTRACT_COUNT)
@Override
public long getContractTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    ContractAccountSet contractAccountSet = ledger.getContractAccountSet(block);
    return contractAccountSet.getTotal();
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) ContractAccountSet(com.jd.blockchain.ledger.core.ContractAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)53 LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)36 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)36 QueryArgs (utils.query.QueryArgs)10 LedgerTransaction (com.jd.blockchain.ledger.LedgerTransaction)9 DataAccountSet (com.jd.blockchain.ledger.core.DataAccountSet)9 LedgerEditor (com.jd.blockchain.ledger.core.LedgerEditor)9 Test (org.junit.Test)9 BlockchainKeypair (com.jd.blockchain.ledger.BlockchainKeypair)8 TransactionRequest (com.jd.blockchain.ledger.TransactionRequest)8 LedgerRepository (com.jd.blockchain.ledger.core.LedgerRepository)8 HashDigest (com.jd.blockchain.crypto.HashDigest)7 LedgerManager (com.jd.blockchain.ledger.core.LedgerManager)7 TransactionSet (com.jd.blockchain.ledger.core.TransactionSet)7 MemoryKVStorage (com.jd.blockchain.storage.service.utils.MemoryKVStorage)7 ContractAccountSet (com.jd.blockchain.ledger.core.ContractAccountSet)6 DataAccount (com.jd.blockchain.ledger.core.DataAccount)6 UserAccount (com.jd.blockchain.ledger.core.UserAccount)6 TransactionResponse (com.jd.blockchain.ledger.TransactionResponse)5 DefaultOperationHandleRegisteration (com.jd.blockchain.ledger.core.DefaultOperationHandleRegisteration)5