Search in sources :

Example 6 with BlockchainIdentity

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());
}
Also used : Bytes(utils.Bytes) IllegalTransactionException(com.jd.blockchain.ledger.IllegalTransactionException) UserAccountSetEditor(com.jd.blockchain.ledger.core.UserAccountSetEditor) SecurityPolicy(com.jd.blockchain.ledger.SecurityPolicy) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) X509Certificate(java.security.cert.X509Certificate)

Example 7 with BlockchainIdentity

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);
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) QueryArgs(utils.query.QueryArgs) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) ContractAccountSet(com.jd.blockchain.ledger.core.ContractAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with BlockchainIdentity

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);
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) QueryArgs(utils.query.QueryArgs) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with BlockchainIdentity

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);
}
Also used : LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) QueryArgs(utils.query.QueryArgs) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) EventAccountSet(com.jd.blockchain.ledger.core.EventAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with BlockchainIdentity

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);
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) QueryArgs(utils.query.QueryArgs) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) UserAccountSet(com.jd.blockchain.ledger.core.UserAccountSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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