Search in sources :

Example 1 with ResGetBlockHeight

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;
}
Also used : BigInteger(java.math.BigInteger) ReqTrans(com.bsnbase.sdk.entity.req.fiscobcos.ReqTrans) AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) ECKeyPair(org.fisco.bcos.web3j.crypto.ECKeyPair) BigInteger(java.math.BigInteger) ResGetBlockHeight(com.bsnbase.sdk.entity.resp.fiscobcos.ResGetBlockHeight) GlobalException(com.bsnbase.sdk.util.exception.GlobalException)

Aggregations

ReqTrans (com.bsnbase.sdk.entity.req.fiscobcos.ReqTrans)1 ResGetBlockHeight (com.bsnbase.sdk.entity.resp.fiscobcos.ResGetBlockHeight)1 GlobalException (com.bsnbase.sdk.util.exception.GlobalException)1 BigInteger (java.math.BigInteger)1 ECKeyPair (org.fisco.bcos.web3j.crypto.ECKeyPair)1 AbiDefinition (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition)1