Search in sources :

Example 1 with GlobalException

use of com.bsnbase.sdk.util.exception.GlobalException in project PCNGateway-Java-SDK by BSNDA.

the class AbiUtil method transactionAssembleForMethodInvoke.

public static String transactionAssembleForMethodInvoke(String contractAbi, int groupId, BigInteger blockNumber, String contractAddress, String funcName, List<Object> funcParam) throws IOException, BaseException {
    AbiDefinition abiDefinition = getFunctionAbiDefinition(funcName, contractAbi);
    if (Objects.isNull(abiDefinition)) {
        throw new GlobalException("contract funcName is error");
    } else {
        List<String> funcInputTypes = ContractAbiUtil.getFuncInputType(abiDefinition);
        if (funcParam == null) {
            funcParam = new ArrayList();
        }
        if (funcInputTypes.size() != ((List) funcParam).size()) {
            throw new GlobalException("contract funcParam size is error");
        } else {
            List<Type> finalInputs = AbiUtil.inputFormat(funcInputTypes, (List) funcParam);
            List<String> funOutputTypes = getFuncOutputType(abiDefinition);
            List<TypeReference<?>> finalOutputs = outputFormat(funOutputTypes);
            boolean isConstant = abiDefinition.isConstant();
            Function function = new Function(funcName, finalInputs, finalOutputs);
            String encodedFunction = FunctionEncoder.encode(function);
            if (isConstant) {
                return encodedFunction;
            } else {
                Random r = new Random();
                BigInteger randomid = new BigInteger(250, r);
                BigInteger blockNumberLimit = blockNumber.add(new BigInteger(String.valueOf(600L)));
                ExtendedRawTransaction extendedRawTransaction = ExtendedRawTransaction.createTransaction(randomid, DefaultGasProvider.GAS_PRICE, DefaultGasProvider.GAS_LIMIT, blockNumberLimit, contractAddress, BigInteger.ZERO, encodedFunction, new BigInteger("1"), BigInteger.valueOf((long) groupId), "");
                byte[] encodedTransaction = ExtendedTransactionEncoder.encode(extendedRawTransaction);
                String encodedDataStr = Numeric.toHexString(encodedTransaction);
                return encodedDataStr;
            }
        }
    }
}
Also used : RlpString(org.fisco.bcos.web3j.rlp.RlpString) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) BigInteger(java.math.BigInteger) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Example 2 with GlobalException

use of com.bsnbase.sdk.util.exception.GlobalException in project PCNGateway-Java-SDK by BSNDA.

the class HttpService method noSignPost.

public BaseResModel<K> noSignPost(BaseReqModel<T> req, String url, Class<K> clazz) {
    String res;
    BaseResModel<K> resModel = new BaseResModel<K>();
    try {
        res = doPost(req, url);
    } catch (GlobalException e) {
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
        throw new GlobalException(ResultInfoEnum.SYSTEM_ERROR);
    }
    if (res != null && res.length() > 0) {
        try {
            resModel = JSON.parseObject(res, resModel.getClass());
            String bodystr = JSON.toJSONString(resModel.getBody());
            resModel.setBody(JSON.parseObject(bodystr, clazz));
        } catch (JsonException e) {
            throw new GlobalException(ResultInfoEnum.DATA_CONVERSION_ERROR);
        }
        // Signature verfication, data transfer
        if (resModel == null) {
            throw new GlobalException(ResultInfoEnum.INVALID_RESPONSE_ERROR);
        }
        if (resModel.getHeader().getCode() != 0) {
            throw new GlobalException(resModel.getHeader().getMsg());
        } else {
        }
        return resModel;
    } else {
        throw new GlobalException(ResultInfoEnum.SYSTEM_ERROR);
    }
}
Also used : JsonException(javax.json.JsonException) BaseResModel(com.bsnbase.sdk.entity.base.BaseResModel) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) JsonException(javax.json.JsonException)

Example 3 with GlobalException

use of com.bsnbase.sdk.util.exception.GlobalException in project PCNGateway-Java-SDK by BSNDA.

the class Config method buildLocalConfigByJson.

/**
 * Read the local configuration file
 *
 * @param filePath
 * @return
 */
public static Config buildLocalConfigByJson(String filePath) {
    String result = "";
    try {
        result = Common.readLocalFile(filePath);
    } catch (Exception e) {
        e.printStackTrace();
        throw new GlobalException(ResultInfoEnum.CONFIG_NOT_EXISTS);
    }
    Config config = buildConfgiByJsonStr(result);
    return config;
}
Also used : IOException(java.io.IOException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException)

Example 4 with GlobalException

use of com.bsnbase.sdk.util.exception.GlobalException in project PCNGateway-Java-SDK by BSNDA.

the class Config method initConfig.

public void initConfig(Config cg) {
    if (config == null) {
        valid(cg);
        config = cg;
        keyStore = new KeyStore(config.getMspDir());
        ResUserInfo res = null;
        try {
            res = AppService.getAppInfo();
        } catch (IOException e) {
            e.printStackTrace();
            throw new GlobalException(ResultInfoEnum.GET_APP_INFO_ERROR);
        }
        if (CaTypeEnum.NON_HOSTED.nCode == res.getCaType() && AppTypeEnum.FABIRC.getValue().equals(res.getAppType().toLowerCase())) {
            validMspDir(config);
        }
        appInfo = res;
    }
}
Also used : ResUserInfo(com.bsnbase.sdk.entity.resp.fabric.ResUserInfo) IOException(java.io.IOException) KeyStore(com.bsnbase.sdk.util.keystore.KeyStore) IKeyStore(com.bsnbase.sdk.util.keystore.IKeyStore) GlobalException(com.bsnbase.sdk.util.exception.GlobalException)

Example 5 with GlobalException

use of com.bsnbase.sdk.util.exception.GlobalException in project PCNGateway-Java-SDK by BSNDA.

the class Config method buildByConfigJson.

/**
 * Read the project configuration in the file under the directory of resource
 *
 * @param filePath
 * @return
 */
public static Config buildByConfigJson(String filePath) {
    String result = "";
    try {
        result = Common.readFile(filePath);
    } catch (IOException e) {
        e.printStackTrace();
        throw new GlobalException(ResultInfoEnum.CONFIG_NOT_EXISTS);
    }
    Config config = buildConfgiByJsonStr(result);
    return config;
}
Also used : IOException(java.io.IOException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException)

Aggregations

GlobalException (com.bsnbase.sdk.util.exception.GlobalException)15 AlgorithmTypeEnum (com.bsnbase.sdk.util.enums.AlgorithmTypeEnum)5 IOException (java.io.IOException)5 JsonException (javax.json.JsonException)3 BaseReqModel (com.bsnbase.sdk.entity.base.BaseReqModel)2 BaseResModel (com.bsnbase.sdk.entity.base.BaseResModel)2 AlgorithmTypeContext (com.bsnbase.sdk.util.algorithm.AlgorithmTypeContext)2 HttpService (com.bsnbase.sdk.util.common.HttpService)2 BigInteger (java.math.BigInteger)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 AbiDefinition (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition)2 BaseResArrayModel (com.bsnbase.sdk.entity.base.BaseResArrayModel)1 ReqKeyUploadBody (com.bsnbase.sdk.entity.req.cita.ReqKeyUploadBody)1 ReqKeyEscrowNo (com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowNo)1 ReqTrans (com.bsnbase.sdk.entity.req.fiscobcos.ReqTrans)1 ResGetBlockHeight (com.bsnbase.sdk.entity.resp.cita.ResGetBlockHeight)1 ResKeyEscrow (com.bsnbase.sdk.entity.resp.cita.ResKeyEscrow)1 ResKeyEscrowNo (com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowNo)1 ResUserInfo (com.bsnbase.sdk.entity.resp.fabric.ResUserInfo)1 ResGetBlockHeight (com.bsnbase.sdk.entity.resp.fiscobcos.ResGetBlockHeight)1