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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations