Search in sources :

Example 1 with LedgerQuery

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

the class LedgerQueryController method getTransactions.

@RequestMapping(method = RequestMethod.GET, path = GET_TRANSACTIONS_ON_BLOCK_HASH)
@Override
public LedgerTransaction[] getTransactions(@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;
    }
    QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, (int) ledger.getTransactionSet(ledgerBlock).getTotalCount());
    LedgerTransaction[] txs = ledger.getTransactionSet(ledgerBlock).getTransactions(queryArgs.getFrom(), queryArgs.getCount());
    return txsDecorator(txs);
// LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
// LedgerBlock ledgerBlock = ledger.getBlock(blockHash);
// long height = ledgerBlock.getHeight();
// TransactionQuery transactionSet = ledger.getTransactionSet(ledgerBlock);
// TransactionQuery origTransactionSet = null;
// int lastHeightTxTotalNums = 0;
// 
// if (height > 0) {
// origTransactionSet = ledger.getTransactionSet(ledger.getBlock(height - 1));
// lastHeightTxTotalNums = (int) origTransactionSet.getTotalCount();
// }
// 
// int currentHeightTxTotalNums = (int) ledger.getTransactionSet(ledger.getBlock(height)).getTotalCount();
// // 取当前块hash的增量交易数,在增量交易里进行查找
// int currentHeightTxNums = currentHeightTxTotalNums - lastHeightTxTotalNums;
// 
// QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, currentHeightTxNums);
// LedgerTransaction[] txs = transactionSet.getBlockTxs(queryArgs.getFrom(), queryArgs.getCount(), origTransactionSet);
// return txsDecorator(txs);
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) QueryArgs(utils.query.QueryArgs) LedgerTransaction(com.jd.blockchain.ledger.LedgerTransaction) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with LedgerQuery

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

the class LedgerQueryController method getConsensusParticipants.

@RequestMapping(method = RequestMethod.GET, path = GET_CONSENSUS_PARTICIPANTS)
@Override
public ParticipantNode[] getConsensusParticipants(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerAdminInfo ledgerAdministration = ledger.getAdminInfo();
    long participantCount = ledgerAdministration.getParticipantCount();
    if (participantCount <= 0) {
        return null;
    }
    ParticipantNode[] participantNodes = ledgerAdministration.getParticipants();
    // 重新封装,处理Proxy的问题
    if (participantNodes != null && participantNodes.length > 0) {
        ParticipantNode[] convertNodes = new ParticipantNode[participantNodes.length];
        for (int i = 0, length = participantNodes.length; i < length; i++) {
            convertNodes[i] = new ParticipantCertData(participantNodes[i]);
        }
        return convertNodes;
    }
    return null;
}
Also used : LedgerAdminInfo(com.jd.blockchain.ledger.LedgerAdminInfo) ParticipantNode(com.jd.blockchain.ledger.ParticipantNode) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) ParticipantCertData(com.jd.blockchain.ledger.core.ParticipantCertData) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with LedgerQuery

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

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

the class LedgerQueryController method getDataEntries.

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, path = GET_LATEST_KV_LIST)
@Override
public TypedKVEntry[] getDataEntries(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address, @RequestParam("keys") String... keys) {
    if (keys == null || keys.length == 0) {
        return null;
    }
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
    DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));
    if (dataAccount == null) {
        return null;
    }
    TypedKVEntry[] entries = new TypedKVEntry[keys.length];
    long ver;
    for (int i = 0; i < entries.length; i++) {
        ver = dataAccount.getDataset().getVersion(keys[i]);
        if (ver < 0) {
            entries[i] = new TypedKVData(keys[i], -1, null);
        } else {
            BytesValue value = dataAccount.getDataset().getValue(keys[i], ver);
            entries[i] = new TypedKVData(keys[i], ver, value);
        }
    }
    return entries;
}
Also used : DataAccount(com.jd.blockchain.ledger.core.DataAccount) TypedKVEntry(com.jd.blockchain.ledger.TypedKVEntry) TypedKVData(com.jd.blockchain.ledger.TypedKVData) LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet) BytesValue(com.jd.blockchain.ledger.BytesValue) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 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_LATEST_COMPILED_CONTRACT)
@Override
public ContractInfo getContract(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    ContractAccountSet contractAccountSet = ledger.getContractAccountSet(block);
    return contractAccountSet.getAccount(Bytes.fromBase58(address));
}
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

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