use of com.jd.blockchain.ledger.BlockchainIdentity in project jdchain-core by blockchain-jd-com.
the class UserRegisterOperationHandle method doProcess.
@Override
protected void doProcess(UserRegisterOperation op, LedgerTransactionContext transactionContext, TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext, EventManager manager) {
// 权限校验;
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy();
securityPolicy.checkEndpointPermission(LedgerPermission.REGISTER_USER, MultiIDsPolicy.AT_LEAST_ONE);
// 证书模式下必须传递证书
if (transactionContext.getDataset().getAdminDataset().getAdminSettings().getMetadata().getIdentityMode() == IdentityMode.CA) {
if (StringUtils.isEmpty(op.getCertificate())) {
throw new IllegalTransactionException("User certificate is empty!");
}
X509Certificate cert = CertificateUtils.parseCertificate(op.getCertificate());
CertificateUtils.checkCertificateRolesAny(cert, CertificateRole.PEER, CertificateRole.GW, CertificateRole.USER);
CertificateUtils.checkValidity(cert);
X509Certificate[] ledgerCAs = CertificateUtils.parseCertificates(transactionContext.getDataset().getAdminDataset().getAdminSettings().getMetadata().getLedgerCertificates());
X509Certificate[] issuers = CertificateUtils.findIssuers(cert, ledgerCAs);
Arrays.stream(issuers).forEach(issuer -> CertificateUtils.checkCACertificate(issuer));
CertificateUtils.checkValidityAny(issuers);
}
// 操作账本;
BlockchainIdentity bid = op.getUserID();
Bytes userAddress = bid.getAddress();
((UserAccountSetEditor) (transactionContext.getDataset().getUserAccountSet())).register(userAddress, bid.getPubKey(), op.getCertificate());
}
use of com.jd.blockchain.ledger.BlockchainIdentity in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getContractAccounts.
@RequestMapping(method = RequestMethod.GET, path = GET_CONTRACT_ACCOUNT_SEQUENCE)
@Override
public BlockchainIdentity[] getContractAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
ContractAccountSet contractAccountSet = ledger.getContractAccountSet(block);
QueryArgs queryArgs = QueryUtils.calFromIndexAndCountDescend(fromIndex, count, (int) contractAccountSet.getTotal());
SkippingIterator<BlockchainIdentity> it = contractAccountSet.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 LedgerQueryController method getDataAccounts.
/**
* get more dataAccounts by fromIndex and count;
*
* @param ledgerHash
* @param fromIndex
* @param count
* @return
*/
@RequestMapping(method = RequestMethod.GET, path = GET_DATA_ACCOUNT_SEQUENCE)
@Override
public BlockchainIdentity[] getDataAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
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);
}
use of com.jd.blockchain.ledger.BlockchainIdentity in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getUserEventAccounts.
@RequestMapping(method = RequestMethod.GET, path = GET_EVENT_ACCOUNT_SEQUENCE)
@Override
public BlockchainIdentity[] getUserEventAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
EventAccountSet eventAccountSet = ledger.getEventAccountSet(ledger.getLatestBlock());
QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, (int) eventAccountSet.getTotal());
SkippingIterator<BlockchainIdentity> it = eventAccountSet.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 LedgerQueryController method getUsers.
/**
* get more users by fromIndex and count;
*
* @param ledgerHash
* @param fromIndex
* @param count
* @return
*/
@RequestMapping(method = RequestMethod.GET, path = GET_USER_SEQUENCE)
@Override
public BlockchainIdentity[] getUsers(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
UserAccountSet userAccountSet = ledger.getUserAccountSet(block);
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);
}
Aggregations