Search in sources :

Example 1 with DataAccountInfo

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

the class DataSearchController method dataQuery.

private WebResponse dataQuery(String uri, HashDigest ledgerHash, String keyword) {
    if (StringUtils.isEmpty(keyword)) {
        return WebResponse.createFailureResult(new WebResponse.ErrorMessage(-1, "empty keywords"));
    }
    String ledger = ledgerHash.toString();
    String type = uri.substring(uri.indexOf(ledger) + ledger.length(), uri.lastIndexOf("search"));
    Object data = null;
    switch(type) {
        case // 综合查询
        "/all/":
            data = dataSearchService.searchAll(ledgerHash, keyword);
            break;
        case // 数据账户数
        "/accounts/count/":
            data = dataSearchService.searchDataAccountCount(ledgerHash, keyword);
            break;
        case // 数据账户
        "/accounts/":
            DataAccountInfo dataAccount = dataSearchService.searchDataAccount(ledgerHash, keyword);
            data = null != dataAccount ? new DataAccountInfo[] { dataAccount } : new DataAccountInfo[] {};
            break;
        case // 事件账户账户数
        "/events/accounts/count/":
            data = dataSearchService.searchEventAccountCount(ledgerHash, keyword);
            break;
        case // 事件账户
        "/events/accounts/":
            BlockchainIdentity eventAccount = dataSearchService.searchEventAccount(ledgerHash, keyword);
            data = null != eventAccount ? new BlockchainIdentity[] { eventAccount } : new BlockchainIdentity[] {};
            break;
        case // 合约账户数
        "/contracts/count/":
            data = dataSearchService.searchContractAccountCount(ledgerHash, keyword);
            break;
        case // 合约
        "/contracts/":
            ContractInfo contract = dataSearchService.searchContractAccount(ledgerHash, keyword);
            data = null != contract ? new ContractInfo[] { contract } : new ContractInfo[] {};
            break;
        case // 用户账户数
        "/users/count/":
            data = dataSearchService.searchUserCount(ledgerHash, keyword);
            break;
        case // 用户
        "/users/":
            UserInfo user = dataSearchService.searchUser(ledgerHash, keyword);
            data = null != user ? new UserInfo[] { user } : new UserInfo[] {};
            break;
        default:
            return WebResponse.createFailureResult(new WebResponse.ErrorMessage(-1, "404"));
    }
    return WebResponse.createSuccessResult(data);
}
Also used : ContractInfo(com.jd.blockchain.ledger.ContractInfo) WebResponse(com.jd.httpservice.utils.web.WebResponse) DataAccountInfo(com.jd.blockchain.ledger.DataAccountInfo) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) UserInfo(com.jd.blockchain.ledger.UserInfo)

Example 2 with DataAccountInfo

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

the class DataSearchServiceHandler method searchAll.

@Override
public Map<String, Object> searchAll(HashDigest ledgerHash, String keyword) {
    Map<String, Object> data = new HashMap<>();
    data.put("combine", true);
    // 区块
    LedgerBlock block = searchBlock(ledgerHash, keyword);
    if (null != block) {
        data.put("blocks", new LedgerBlock[] { block });
    }
    // 交易
    Transaction tx = searchTransaction(ledgerHash, keyword);
    if (null != tx) {
        data.put("txs", new Transaction[] { tx });
    }
    // 数据账户
    DataAccountInfo dataAccount = searchDataAccount(ledgerHash, keyword);
    if (null != dataAccount) {
        data.put("accounts", new DataAccountInfo[] { dataAccount });
    }
    // 事件账户
    BlockchainIdentity eventAccount = searchEventAccount(ledgerHash, keyword);
    if (null != eventAccount) {
        data.put("event_accounts", new BlockchainIdentity[] { eventAccount });
    }
    // 合约
    ContractInfo contract = searchContractAccount(ledgerHash, keyword);
    if (null != contract) {
        data.put("contracts", new ContractInfo[] { contract });
    }
    // 用户
    UserInfo user = searchUser(ledgerHash, keyword);
    if (null != user) {
        data.put("users", new UserInfo[] { user });
    }
    return data;
}
Also used : ContractInfo(com.jd.blockchain.ledger.ContractInfo) LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) Transaction(com.jd.blockchain.gateway.service.search.Transaction) LedgerTransaction(com.jd.blockchain.ledger.LedgerTransaction) DataAccountInfo(com.jd.blockchain.ledger.DataAccountInfo) HashMap(java.util.HashMap) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) UserInfo(com.jd.blockchain.ledger.UserInfo)

Aggregations

BlockchainIdentity (com.jd.blockchain.ledger.BlockchainIdentity)2 ContractInfo (com.jd.blockchain.ledger.ContractInfo)2 DataAccountInfo (com.jd.blockchain.ledger.DataAccountInfo)2 UserInfo (com.jd.blockchain.ledger.UserInfo)2 Transaction (com.jd.blockchain.gateway.service.search.Transaction)1 LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)1 LedgerTransaction (com.jd.blockchain.ledger.LedgerTransaction)1 WebResponse (com.jd.httpservice.utils.web.WebResponse)1 HashMap (java.util.HashMap)1