Search in sources :

Example 21 with LedgerBlock

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

the class LedgerQueryController method getDataAccounts.

/**
 * get more dataAccounts by fromIndex and count;
 *
 * @param ledgerHash
 * @param fromIndex
 * @param count
 * @return
 */
@RequestMapping(method = RequestMethod.GET, path = GET_DATA_ACCOUNT_SEQUENCE)
@Override
public BlockchainIdentity[] getDataAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
    QueryArgs queryArgs = QueryUtils.calFromIndexAndCountDescend(fromIndex, count, (int) dataAccountSet.getTotal());
    SkippingIterator<BlockchainIdentity> it = dataAccountSet.identityIterator();
    it.skip(queryArgs.getFrom());
    return it.next(queryArgs.getCount(), BlockchainIdentity.class);
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) QueryArgs(utils.query.QueryArgs) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 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_HASH)
@Override
public long getContractCount(@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;
    }
    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 23 with LedgerBlock

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

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

the class LedgerQueryController method getUsers.

/**
 * get more users by fromIndex and count;
 *
 * @param ledgerHash
 * @param fromIndex
 * @param count
 * @return
 */
@RequestMapping(method = RequestMethod.GET, path = GET_USER_SEQUENCE)
@Override
public BlockchainIdentity[] getUsers(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    UserAccountSet userAccountSet = ledger.getUserAccountSet(block);
    QueryArgs queryArgs = QueryUtils.calFromIndexAndCountDescend(fromIndex, count, (int) userAccountSet.getTotal());
    SkippingIterator<BlockchainIdentity> it = userAccountSet.identityIterator();
    it.skip(queryArgs.getFrom());
    return it.next(queryArgs.getCount(), BlockchainIdentity.class);
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) QueryArgs(utils.query.QueryArgs) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) UserAccountSet(com.jd.blockchain.ledger.core.UserAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with LedgerBlock

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

the class LedgerQueryController method getDataAccountTotalCount.

@RequestMapping(method = RequestMethod.GET, path = GET_TOTAL_DATA_ACCOUNT_COUNT)
@Override
public long getDataAccountTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    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)

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