Search in sources :

Example 6 with HttpService

use of com.bsnbase.sdk.util.common.HttpService 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();
}
Also used : BaseReqModel(com.bsnbase.sdk.entity.base.BaseReqModel) HttpService(com.bsnbase.sdk.util.common.HttpService)

Example 7 with HttpService

use of com.bsnbase.sdk.util.common.HttpService 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();
}
Also used : BaseReqModel(com.bsnbase.sdk.entity.base.BaseReqModel) ResTrans(com.bsnbase.sdk.entity.resp.fiscobcos.ResTrans) ReqTrans(com.bsnbase.sdk.entity.req.fiscobcos.ReqTrans) HttpService(com.bsnbase.sdk.util.common.HttpService)

Example 8 with HttpService

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 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;
}
Also used : BaseReqModel(com.bsnbase.sdk.entity.base.BaseReqModel) HttpService(com.bsnbase.sdk.util.common.HttpService) ResUserRegister(com.bsnbase.sdk.entity.resp.fiscobcos.ResUserRegister) ReqUserRegister(com.bsnbase.sdk.entity.req.fiscobcos.ReqUserRegister)

Example 9 with HttpService

use of com.bsnbase.sdk.util.common.HttpService 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();
}
Also used : BaseReqModel(com.bsnbase.sdk.entity.base.BaseReqModel) HttpService(com.bsnbase.sdk.util.common.HttpService) ResGetBlockHeight(com.bsnbase.sdk.entity.resp.cita.ResGetBlockHeight)

Example 10 with HttpService

use of com.bsnbase.sdk.util.common.HttpService 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();
}
Also used : BaseReqModel(com.bsnbase.sdk.entity.base.BaseReqModel) ResKeyEscrow(com.bsnbase.sdk.entity.resp.cita.ResKeyEscrow) Random(java.util.Random) HttpService(com.bsnbase.sdk.util.common.HttpService) ResGetBlockHeight(com.bsnbase.sdk.entity.resp.cita.ResGetBlockHeight) ReqKeyUploadBody(com.bsnbase.sdk.entity.req.cita.ReqKeyUploadBody) GlobalException(com.bsnbase.sdk.util.exception.GlobalException)

Aggregations

BaseReqModel (com.bsnbase.sdk.entity.base.BaseReqModel)11 HttpService (com.bsnbase.sdk.util.common.HttpService)11 ResGetBlockHeight (com.bsnbase.sdk.entity.resp.cita.ResGetBlockHeight)2 GlobalException (com.bsnbase.sdk.util.exception.GlobalException)2 ReqKeyUploadBody (com.bsnbase.sdk.entity.req.cita.ReqKeyUploadBody)1 ReqUserRegister (com.bsnbase.sdk.entity.req.cita.ReqUserRegister)1 ReqKeyEscrowEnroll (com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowEnroll)1 ReqKeyEscrowNo (com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowNo)1 ReqUserRegister (com.bsnbase.sdk.entity.req.fabric.ReqUserRegister)1 ReqTrans (com.bsnbase.sdk.entity.req.fiscobcos.ReqTrans)1 ReqUserRegister (com.bsnbase.sdk.entity.req.fiscobcos.ReqUserRegister)1 ReqUserRegister (com.bsnbase.sdk.entity.req.xuperChain.ReqUserRegister)1 ResKeyEscrow (com.bsnbase.sdk.entity.resp.cita.ResKeyEscrow)1 ResUserRegister (com.bsnbase.sdk.entity.resp.cita.ResUserRegister)1 ResKeyEscrowEnroll (com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowEnroll)1 ResKeyEscrowNo (com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowNo)1 ResUserRegister (com.bsnbase.sdk.entity.resp.fabric.ResUserRegister)1 ResTrans (com.bsnbase.sdk.entity.resp.fiscobcos.ResTrans)1 ResUserRegister (com.bsnbase.sdk.entity.resp.fiscobcos.ResUserRegister)1 ResUserRegister (com.bsnbase.sdk.entity.resp.xuperChain.ResUserRegister)1