Search in sources :

Example 11 with BlockchainIdentity

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

the class KvAccountSetEditor method createAccount.

private InnerSimpleAccount createAccount(Bytes address, HashDigest headerRoot, HashDigest dataRoot, long version, boolean readonly) {
    Bytes accountIndexPrefix = Bytes.fromString("I/").concat(address);
    long accountIndex = BytesUtils.toLong(kvDataset.getValue(accountIndexPrefix));
    Bytes accountIndexBytes = Bytes.fromString(String.valueOf(accountIndex));
    // 根据账户的顺序号查找其身份信息(ID), 前缀为:L:/DS/SQ/accountindex
    Bytes idkeyPrefix = Bytes.fromString("SQ/").concat(accountIndexBytes);
    BlockchainIdentity id = loadId(idkeyPrefix);
    // 数据账户集下具体账户的完整前缀:L:/DS/accountindex
    Bytes accountPrefix = keyPrefix.concat(accountIndexBytes);
    return new InnerSimpleAccount(id, version, headerRoot, dataRoot, cryptoSetting, accountPrefix, baseExStorage, baseVerStorage, readonly);
}
Also used : Bytes(utils.Bytes) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity)

Example 12 with BlockchainIdentity

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

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

Example 14 with BlockchainIdentity

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

the class ContractLedgerQueryService method getUsers.

@Override
public BlockchainIdentity[] getUsers(int fromIndex, int count) {
    UserAccountSet userAccountSet = ledgerQuery.getUserAccountSet();
    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 : QueryArgs(utils.query.QueryArgs) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) UserAccountSet(com.jd.blockchain.ledger.core.UserAccountSet)

Example 15 with BlockchainIdentity

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

the class ContractLedgerQueryService method getDataAccounts.

@Override
public BlockchainIdentity[] getDataAccounts(int fromIndex, int count) {
    DataAccountSet dataAccountSet = ledgerQuery.getDataAccountSet();
    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 : QueryArgs(utils.query.QueryArgs) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet)

Aggregations

BlockchainIdentity (com.jd.blockchain.ledger.BlockchainIdentity)17 QueryArgs (utils.query.QueryArgs)12 LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)4 LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ContractAccountSet (com.jd.blockchain.ledger.core.ContractAccountSet)3 DataAccountSet (com.jd.blockchain.ledger.core.DataAccountSet)3 EventAccountSet (com.jd.blockchain.ledger.core.EventAccountSet)3 UserAccountSet (com.jd.blockchain.ledger.core.UserAccountSet)3 ContractInfo (com.jd.blockchain.ledger.ContractInfo)2 DataAccountInfo (com.jd.blockchain.ledger.DataAccountInfo)2 SecurityPolicy (com.jd.blockchain.ledger.SecurityPolicy)2 UserInfo (com.jd.blockchain.ledger.UserInfo)2 Bytes (utils.Bytes)2 Transaction (com.jd.blockchain.gateway.service.search.Transaction)1 AccountDataPermission (com.jd.blockchain.ledger.AccountDataPermission)1 IllegalTransactionException (com.jd.blockchain.ledger.IllegalTransactionException)1 LedgerTransaction (com.jd.blockchain.ledger.LedgerTransaction)1 DataAccount (com.jd.blockchain.ledger.core.DataAccount)1 DataAccountSetEditor (com.jd.blockchain.ledger.core.DataAccountSetEditor)1