use of com.bsnbase.sdk.entity.req.cita.ReqKeyUploadBody 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