Search in sources :

Example 1 with HttpService

use of com.bsnbase.sdk.util.common.HttpService in project PCNGateway-Java-SDK by BSNDA.

the class UserService method userEnroll.

/**
 * User certificate registration in Public Key Upload Mode
 * When a user participated in the application in the public key upload mode needs to register a sub-user, after completing the user registration interface, he/she can call this interface to upload a public key certificate application file and obtain a sub-user certificate issued by the city node.
 * An exception will be returned when this interface is called in key trust mode.
 */
public static ResKeyEscrowEnroll userEnroll(@NotNull ReqKeyEscrowEnroll kes) throws IOException {
    String api = Config.config.getApi() + PathUtil.FABRIC_USER_ENROLL;
    UserCertInfo certInfo = StoreUtils.generateCSR(kes.getName(), Config.config.getAppCode());
    kes.setCsrPem(certInfo.getCSRPem());
    BaseReqModel<ReqKeyEscrowEnroll> req = new BaseReqModel<ReqKeyEscrowEnroll>();
    req.setReqHeader(Config.config.getUserCode(), Config.config.getAppCode());
    req.setBody(kes);
    HttpService<ReqKeyEscrowEnroll, ResKeyEscrowEnroll> httpService = new HttpService<ReqKeyEscrowEnroll, ResKeyEscrowEnroll>();
    BaseResModel<ResKeyEscrowEnroll> res = httpService.post(req, api, ResKeyEscrowEnroll.class);
    ResKeyEscrowEnroll body = res.getBody();
    // Save the private key
    Config.config.getKeyStore().storeUserPrivateKey(kes.getName(), Config.config.getAppCode(), certInfo.getKey());
    // Save the registered certificate
    Config.config.getKeyStore().storeUserCert(kes.getName(), Config.config.getAppCode(), body.getCert());
    return body;
}
Also used : UserCertInfo(com.bsnbase.sdk.util.common.UserCertInfo) BaseReqModel(com.bsnbase.sdk.entity.base.BaseReqModel) HttpService(com.bsnbase.sdk.util.common.HttpService) ReqKeyEscrowEnroll(com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowEnroll) ResKeyEscrowEnroll(com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowEnroll)

Example 2 with HttpService

use of com.bsnbase.sdk.util.common.HttpService in project PCNGateway-Java-SDK by BSNDA.

the class NodeService method getTxCount.

/**
 * Get the total number of transactions
 * The total number of transactions can be Getd by calling this interface
 */
public static ResGetTxCount getTxCount() throws IOException {
    String api = Config.config.getApi() + PathUtil.FISCOBCOS_NODE_GET_TXCOUNT;
    BaseReqModel<ReqKeyEscrow> req = new BaseReqModel<>();
    req.setReqHeader(Config.config.getUserCode(), Config.config.getAppCode());
    HttpService httpService = new HttpService();
    BaseResModel<ResGetTxCount> res = httpService.post(req, api, ResGetTxCount.class);
    return res.getBody();
}
Also used : BaseReqModel(com.bsnbase.sdk.entity.base.BaseReqModel) HttpService(com.bsnbase.sdk.util.common.HttpService)

Example 3 with HttpService

use of com.bsnbase.sdk.util.common.HttpService in project PCNGateway-Java-SDK by BSNDA.

the class UserService method userRegister.

/**
 * User registration
 * After a user participates in a XuperChain-based application, he/she needs to call this interface through the off-chain business system to generate the user account and account address for on-chain transaction processing.
 */
public static ResUserRegister userRegister(ReqUserRegister register) {
    String api = Config.config.getApi() + PathUtil.XUPERCHAIN_USER_REGISTER;
    BaseReqModel<ReqUserRegister> req = new BaseReqModel<>(register);
    req.setReqHeader(Config.config.getUserCode(), Config.config.getAppCode());
    HttpService<ReqUserRegister, ResUserRegister> httpService = new HttpService<ReqUserRegister, ResUserRegister>();
    BaseResModel<ResUserRegister> res = httpService.post(req, api, ResUserRegister.class);
    ResUserRegister body = res.getBody();
    return body;
}
Also used : BaseReqModel(com.bsnbase.sdk.entity.base.BaseReqModel) HttpService(com.bsnbase.sdk.util.common.HttpService) ResUserRegister(com.bsnbase.sdk.entity.resp.xuperChain.ResUserRegister) ReqUserRegister(com.bsnbase.sdk.entity.req.xuperChain.ReqUserRegister)

Example 4 with HttpService

use of com.bsnbase.sdk.util.common.HttpService in project PCNGateway-Java-SDK by BSNDA.

the class TransactionService method nodeTrans.

/**
 * Invoke chaincode in Public Key Upload Mode
 * <p>
 * When the user of the public key upload mode application needs to initiate a transaction from the off-chain system to the chaincode on the chain, he/she needs to assemble the transaction message locally and call this interface to initiate the transaction.
 */
public static ResKeyEscrowNo nodeTrans(@NotNull ReqKeyEscrow reqkey) throws NoSuchAlgorithmException {
    String api = Config.config.getApi() + PathUtil.FABRIC_NODE_TRANS;
    TransactionUser user = null;
    try {
        user = Config.config.getKeyStore().loadUser(reqkey.getUserName(), Config.config.getAppCode());
        user.setMspId(Config.config.getAppInfo().getMspId());
        AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(Config.config.getAppInfo().getAlgorithmType());
        if (algorithmTypeEnum == AlgorithmTypeEnum.AppAlgorithmType_SM2 && Config.config.getAppInfo().getFabricVersion().equals("2.2.1")) {
            user.setSM3(true);
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new GlobalException(ResultInfoEnum.USER_CERTIFICATE_ERROR.getMsg());
    }
    // Assemble the transaction information
    TransactionRequest request = new TransactionRequest();
    request.setChannelId(Config.config.getAppInfo().getChannelId());
    request.setArgs(Common.StringBytesConvert(reqkey.getArgs()));
    request.setTransientMap(reqkey.getTransientData());
    request.setChaincodeId(reqkey.getChainCode());
    request.setFcn(reqkey.getFuncName());
    String transData = null;
    try {
        transData = getTransdata(request, user);
    } catch (Exception e) {
        e.printStackTrace();
        throw new GlobalException(ResultInfoEnum.TRANSACTION_CONVERSION_ERROR.getMsg());
    }
    ReqKeyEscrowNo keyNo = new ReqKeyEscrowNo();
    keyNo.setTransData(transData);
    BaseReqModel<ReqKeyEscrowNo> req = new BaseReqModel<ReqKeyEscrowNo>();
    req.setReqHeader(Config.config.getUserCode(), Config.config.getAppCode());
    req.setBody(keyNo);
    HttpService<ReqKeyEscrowNo, ResKeyEscrowNo> httpService = new HttpService<ReqKeyEscrowNo, ResKeyEscrowNo>();
    BaseResModel<ResKeyEscrowNo> res = httpService.post(req, api, ResKeyEscrowNo.class);
    return res.getBody();
}
Also used : ResKeyEscrowNo(com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowNo) ReqKeyEscrowNo(com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowNo) IOException(java.io.IOException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) TransactionRequest(com.bsnbase.sdk.entity.transactionHeader.TransactionRequest) IOException(java.io.IOException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BaseReqModel(com.bsnbase.sdk.entity.base.BaseReqModel) TransactionUser(com.bsnbase.sdk.entity.transactionHeader.TransactionUser) HttpService(com.bsnbase.sdk.util.common.HttpService) AlgorithmTypeEnum(com.bsnbase.sdk.util.enums.AlgorithmTypeEnum)

Example 5 with HttpService

use of com.bsnbase.sdk.util.common.HttpService in project PCNGateway-Java-SDK by BSNDA.

the class UserService method userRegister.

/**
 * User registration
 * <p>
 * In both key trust mode and public key upload mode, when the user is participating in the Fabric application and needs to create a separate user transaction certificate for the sub-user of the off-chain system, it is necessary to call this interface first to register the user in this city node, and the user's username is name@appCode in the call parameter.
 */
public static ResUserRegister userRegister(ReqUserRegister register) throws IOException {
    String api = Config.config.getApi() + PathUtil.FABRIC_USER_REGISTER;
    BaseReqModel<ReqUserRegister> req = new BaseReqModel<ReqUserRegister>();
    req.setReqHeader(Config.config.getUserCode(), Config.config.getAppCode());
    req.setBody(register);
    HttpService<ReqUserRegister, ResUserRegister> httpService = new HttpService<ReqUserRegister, ResUserRegister>();
    BaseResModel<ResUserRegister> res = httpService.post(req, api, ResUserRegister.class);
    ResUserRegister body = res.getBody();
    return body;
}
Also used : BaseReqModel(com.bsnbase.sdk.entity.base.BaseReqModel) HttpService(com.bsnbase.sdk.util.common.HttpService) ResUserRegister(com.bsnbase.sdk.entity.resp.fabric.ResUserRegister) ReqUserRegister(com.bsnbase.sdk.entity.req.fabric.ReqUserRegister)

Aggregations

BaseReqModel (com.bsnbase.sdk.entity.base.BaseReqModel)11 HttpService (com.bsnbase.sdk.util.common.HttpService)11 ResGetBlockHeight (com.bsnbase.sdk.entity.resp.cita.ResGetBlockHeight)2 GlobalException (com.bsnbase.sdk.util.exception.GlobalException)2 ReqKeyUploadBody (com.bsnbase.sdk.entity.req.cita.ReqKeyUploadBody)1 ReqUserRegister (com.bsnbase.sdk.entity.req.cita.ReqUserRegister)1 ReqKeyEscrowEnroll (com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowEnroll)1 ReqKeyEscrowNo (com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowNo)1 ReqUserRegister (com.bsnbase.sdk.entity.req.fabric.ReqUserRegister)1 ReqTrans (com.bsnbase.sdk.entity.req.fiscobcos.ReqTrans)1 ReqUserRegister (com.bsnbase.sdk.entity.req.fiscobcos.ReqUserRegister)1 ReqUserRegister (com.bsnbase.sdk.entity.req.xuperChain.ReqUserRegister)1 ResKeyEscrow (com.bsnbase.sdk.entity.resp.cita.ResKeyEscrow)1 ResUserRegister (com.bsnbase.sdk.entity.resp.cita.ResUserRegister)1 ResKeyEscrowEnroll (com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowEnroll)1 ResKeyEscrowNo (com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowNo)1 ResUserRegister (com.bsnbase.sdk.entity.resp.fabric.ResUserRegister)1 ResTrans (com.bsnbase.sdk.entity.resp.fiscobcos.ResTrans)1 ResUserRegister (com.bsnbase.sdk.entity.resp.fiscobcos.ResUserRegister)1 ResUserRegister (com.bsnbase.sdk.entity.resp.xuperChain.ResUserRegister)1