use of com.bsnbase.sdk.entity.base.BaseReqModel in project PCNGateway-Java-SDK by BSNDA.
the class NodeService method getBlockHeight.
/**
* Get the block height
* Get the block height based on this interface.
*/
public static ResGetBlockHeight getBlockHeight() {
String api = Config.config.getApi() + PathUtil.FISCOBCOS_NODE_GET_BLOCK_HEIGHT;
BaseReqModel req = new BaseReqModel<>();
req.setReqHeader(Config.config.getUserCode(), Config.config.getAppCode());
HttpService httpService = new HttpService<>();
BaseResModel<ResGetBlockHeight> res = httpService.post(req, api, ResGetBlockHeight.class);
return res.getBody();
}
use of com.bsnbase.sdk.entity.base.BaseReqModel in project PCNGateway-Java-SDK by BSNDA.
the class TransactionService method trans.
/**
* Invoke the smart contract in Public Key Upload Mode
* When the off-chain business system connects to the BSN gateway, it needs to add the corresponding parameters in the request message according to the interface description. After invoking the gateway, the gateway will return the execution result of the smart contract.
* In the transaction of public key upload mode, the private key of the on-chain transaction is generated and saved by the user, and then the client will assemble and sign the on-chain data locally, and upload the signed data to the node gateway.
* The gateway forwards the data to the corresponding blockchain node to initiate the transaction request. In this mode, the ABI of the contract and the contract address are required to assemble the data.
* The ABI of the contract is obtained by compiling the contract when developing the contract, and the contract address can be obtained from the details page of the participated service.
* The method to assemble the on-chain data has been implemented in the SDK of the gateway, and it can be called directly.
*/
public static ResTrans trans(ReqTransData reqTransData) throws Exception {
ReqTrans reqTrans = FiscoTransUtil.buildTrans(reqTransData);
String api = Config.config.getApi() + PathUtil.FISCOBCOS_NODE_TRANS;
BaseReqModel<ReqTrans> req = new BaseReqModel<>(reqTrans);
req.setReqHeader(Config.config.getUserCode(), Config.config.getAppCode());
HttpService<ReqTrans, ResTrans> httpService = new HttpService();
BaseResModel<ResTrans> res = httpService.post(req, api, ResTrans.class);
return res.getBody();
}
use of com.bsnbase.sdk.entity.base.BaseReqModel 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 participated in the FISCO BCOS application 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 sub-user in this city node, and the sub-user's username is name@appCode in the call parameter.
*/
public static ResUserRegister userRegister(ReqUserRegister register) throws IOException {
String api = Config.config.getApi() + PathUtil.FISCOBCOS_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.entity.base.BaseReqModel in project PCNGateway-Java-SDK by BSNDA.
the class NodeService method getBlockHeight.
/**
* Get the block height
* Get the block height based on this interface.
*/
public static ResGetBlockHeight getBlockHeight() {
String api = Config.config.getApi() + PathUtil.CITA_NODE_GET_BLOCK_HEIGHT;
BaseReqModel req = new BaseReqModel<>();
req.setReqHeader(Config.config.getUserCode(), Config.config.getAppCode());
HttpService httpService = new HttpService<>();
BaseResModel<ResGetBlockHeight> res = httpService.post(req, api, ResGetBlockHeight.class);
return res.getBody();
}
use of com.bsnbase.sdk.entity.base.BaseReqModel in project PCNGateway-Java-SDK by BSNDA.
the class TransactionService method nodeTrans.
/**
* Invoke the smart contract in Public Key Upload Mode
* When the off-chain business system connects to the BSN gateway, it needs to add the corresponding parameters in the request message according to the interface description. After invoking the gateway, the gateway will return the execution result of the smart contract.
* In the transaction of public key upload mode, the private key of the on-chain transaction is generated and saved by the user, and then the client will assemble and sign the on-chain data locally, and upload the signed data to the node gateway.
* The gateway forwards the data to the corresponding blockchain node to initiate the transaction request. In this mode, the ABI of the contract and the contract address are required to assemble the data.
* The ABI of the contract is obtained by compiling the contract when developing the contract, and the contract address can be obtained from the details page of the participated service.
* The method to assemble the on-chain data has been implemented in the SDK of the gateway, and it can be called directly.
* -----------------------------------------------------------------------------------------------------------------
* Example of default contract method parameters
* FuncParam: the parameter type of the preset chaincode package is already handled in Service, just pass String.
* <p>
* Save data
* FuncName:insert
* FuncParam:{"insert1219", "123456"}
* <p>
* Remove data
* FuncName:remove
* FuncParam:{"insert1219"}
* <p>
* Update data
* FuncName:update
* FuncParam:{"insert1219", "1234567"}
* Retrieve data
* FuncName:retrieve
* FuncParam:{"insert1219"}
* <p>
* Get key by index
* FuncName:keyAtIndex
* FuncParam:{"1"}
* -----------------------------------------------------------------------------------------------------------------
*/
public static ResKeyEscrow nodeTrans(@NotNull ReqKeyUpload req) throws Exception {
// 1 The user in Key Trust Mode
if (Config.config.getAppInfo().getCaType() == 1) {
throw new GlobalException(ResultInfoEnum.FUNCTION_CALL_ERROR);
}
String api = Config.config.getApi() + PathUtil.CITA_NODE_TRANS;
nonce = new Random(System.currentTimeMillis());
// Get current block height
ResGetBlockHeight resGetBlockHeight = NodeService.getBlockHeight();
long blockIndex = 0;
if (resGetBlockHeight != null && !resGetBlockHeight.getData().isEmpty()) {
blockIndex = Long.parseLong(resGetBlockHeight.getData()) + valid_until_block;
} else {
throw new GlobalException(ResultInfoEnum.BLOCK_HEIGHT_ERROR);
}
// Get FuncData
String addFuncData = getAddFuncData(req);
// Get the signed transaction
String rawTx = getRawTx(req, blockIndex, addFuncData);
// Send transaction
ReqKeyUploadBody transBody = new ReqKeyUploadBody();
transBody.setContractName(req.getContractName());
transBody.setTransData(rawTx);
BaseReqModel<ReqKeyUploadBody> baseReqModel = new BaseReqModel<>();
baseReqModel.setReqHeader(Config.config.getUserCode(), Config.config.getAppCode());
baseReqModel.setBody(transBody);
HttpService<ReqKeyUploadBody, ResKeyEscrow> httpService = new HttpService<>();
BaseResModel<ResKeyEscrow> baseRes = httpService.post(baseReqModel, api, ResKeyEscrow.class);
return baseRes.getBody();
}
Aggregations