use of com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowNo 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();
}
Aggregations