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;
}
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();
}
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;
}
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();
}
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;
}
Aggregations