Search in sources :

Example 1 with TransactionRequest

use of com.bsnbase.sdk.entity.transactionHeader.TransactionRequest 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)

Aggregations

BaseReqModel (com.bsnbase.sdk.entity.base.BaseReqModel)1 ReqKeyEscrowNo (com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowNo)1 ResKeyEscrowNo (com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowNo)1 TransactionRequest (com.bsnbase.sdk.entity.transactionHeader.TransactionRequest)1 TransactionUser (com.bsnbase.sdk.entity.transactionHeader.TransactionUser)1 HttpService (com.bsnbase.sdk.util.common.HttpService)1 AlgorithmTypeEnum (com.bsnbase.sdk.util.enums.AlgorithmTypeEnum)1 GlobalException (com.bsnbase.sdk.util.exception.GlobalException)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1