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