Search in sources :

Example 21 with LedgerQuery

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

the class LedgerQueryController method getLedger.

@RequestMapping(method = RequestMethod.GET, path = GET_LEDGER)
@Override
public LedgerInfo getLedger(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    // TODO: 需要配置返回值的 spring MsgQueueMessageDispatcher
    // ,对返回对象仅仅序列化声明的返回值类型的属性,而不是整个对象本身;
    LedgerInfo ledgerInfo = new LedgerInfo();
    ledgerInfo.setHash(ledgerHash);
    ledgerInfo.setLatestBlockHash(ledger.getLatestBlockHash());
    ledgerInfo.setLatestBlockHeight(ledger.getLatestBlockHeight());
    return ledgerInfo;
}
Also used : LedgerInfo(com.jd.blockchain.ledger.LedgerInfo) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with LedgerQuery

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

the class LedgerQueryController method getLatestUserEvent.

@RequestMapping(method = RequestMethod.GET, path = GET_LATEST_EVENT)
@Override
public Event getLatestUserEvent(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address, @PathVariable(name = "eventName") String eventName) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    EventPublishingAccount account = ledger.getEventAccountSet(ledger.getLatestBlock()).getAccount(address);
    if (null == account) {
        return null;
    }
    return account.getLatest(eventName);
}
Also used : LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) EventPublishingAccount(com.jd.blockchain.ledger.core.EventPublishingAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with LedgerQuery

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

the class LedgerQueryController method getUserTotalCount.

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

Example 24 with LedgerQuery

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

the class LedgerQueryController method getContract.

@RequestMapping(method = RequestMethod.GET, path = GET_COMPILED_CONTRACT)
@Override
public ContractInfo getContract(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address, @PathVariable(name = "version") long version) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    ContractAccountSet contractAccountSet = ledger.getContractAccountSet(block);
    return contractAccountSet.getAccount(Bytes.fromBase58(address), version);
}
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 25 with LedgerQuery

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

Aggregations

LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)45 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)45 LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)36 QueryArgs (utils.query.QueryArgs)11 DataAccountSet (com.jd.blockchain.ledger.core.DataAccountSet)9 TransactionSet (com.jd.blockchain.ledger.core.TransactionSet)7 ContractAccountSet (com.jd.blockchain.ledger.core.ContractAccountSet)6 LedgerTransaction (com.jd.blockchain.ledger.LedgerTransaction)5 EventGroup (com.jd.blockchain.ledger.core.EventGroup)5 EventPublishingAccount (com.jd.blockchain.ledger.core.EventPublishingAccount)5 UserAccountSet (com.jd.blockchain.ledger.core.UserAccountSet)5 BlockchainIdentity (com.jd.blockchain.ledger.BlockchainIdentity)4 DataAccount (com.jd.blockchain.ledger.core.DataAccount)4 EventAccountSet (com.jd.blockchain.ledger.core.EventAccountSet)4 TypedKVData (com.jd.blockchain.ledger.TypedKVData)3 TypedKVEntry (com.jd.blockchain.ledger.TypedKVEntry)3 BytesValue (com.jd.blockchain.ledger.BytesValue)2 LedgerAdminInfo (com.jd.blockchain.ledger.LedgerAdminInfo)2 ContractException (com.jd.blockchain.contract.ContractException)1 KVDataVO (com.jd.blockchain.ledger.KVDataVO)1