use of com.bsnbase.sdk.entity.resp.fiscobcos.ResGetBlockHeight in project PCNGateway-Java-SDK by BSNDA.
the class FiscoTransUtil method buildTrans.
/**
* 构建交易信息
*/
public static ReqTrans buildTrans(ReqTransData reqTransData) throws Exception {
// 0:k1 1:sign
getEncryptTypeByAlgorithmType(Config.config.getAppInfo().getAlgorithmType());
String abi = reqTransData.getContractAbi();
String funcName = reqTransData.getFuncName();
int groupId = Integer.parseInt(Config.config.getAppInfo().getChannelId());
String contractAddress = reqTransData.getContractAddress();
List<Object> funcParam = reqTransData.getFuncParam();
ResGetBlockHeight resGetBlockHeight = NodeService.getBlockHeight();
if (Objects.isNull(resGetBlockHeight)) {
throw new GlobalException(ResultInfoEnum.BLOCK_HEIGHT_ERROR);
}
Integer blockHeight = Integer.valueOf(resGetBlockHeight.getData());
BigInteger blockLimit = BigInteger.valueOf(blockHeight + 100);
String signedStr;
String encodeTransaction = AbiUtil.transactionAssembleForMethodInvoke(abi, groupId, blockLimit, contractAddress, funcName, funcParam);
AbiDefinition abiDefinition = AbiUtil.getFunctionAbiDefinition(funcName, abi);
if (abiDefinition.isConstant()) {
signedStr = encodeTransaction;
} else {
ECKeyPair ecKeyPair = loadKeyPair(reqTransData.getUserName(), Config.config.getAppCode(), Config.config.getMspDir());
signedStr = AbiUtil.signMessageByEncryptType(encodeTransaction, ecKeyPair, EncryptType.getEncryptType());
}
ReqTrans reqTrans = new ReqTrans();
reqTrans.setTransData(signedStr);
reqTrans.setContractName(reqTransData.getContractName());
return reqTrans;
}
Aggregations