【 bug反馈】java sdk中的多处bug

使用maven导入依赖

 <dependency>
            <groupId>com.alaya.client</groupId>
            <artifactId>alaya-core</artifactId>
            <version>0.15.0.0-SNAPSHOT</version>
 </dependency>

DelegateContract中调用无gas设置的委托,方法如下:

  public RemoteCall<TransactionResponse> delegate(String nodeId, StakingAmountType stakingAmountType, BigInteger amount) {
        Function function = createDelegateFunction(nodeId, stakingAmountType, amount);
        return executeRemoteCallTransaction(function);
    }
    protected RemoteCall<TransactionResponse> executeRemoteCallTransaction(Function function) {
    	return new RemoteCall<>(() -> executeTransaction(function, BigInteger.ZERO, getDefaultGasProvider(function)));
	}

此处的getDefaultGasProvider(function)一定会产生NoSupportFunctionType异常
原因getDefaultGasProvider(function)只会调用getDefaultGasProviderRemote(function),而在getDefaultGasProviderRemote(function)中调用的 EstimateGasUtil.getGasLimit(function)由于不支持委托类型的function,会抛出NoSupportFunctionType异常。

  public static BigInteger getGasLimit(Function function) throws NoSupportFunctionType {
        if(isSupportLocal(function.getType())){
            return  BASE_DEFAULT_GAS_LIMIT
                    .add(getContractGasLimit(function.getType()))
                    .add(getFunctionGasLimit(function.getType()))
                    .add(getInterfaceDynamicGasLimit(function.getType(),function.getInputParameters()))
                    .add(getDataGasLimit(EncoderUtils.functionEncoder(function)));
        } else {
            throw new NoSupportFunctionType(function.getType());
        }
    }

因此只要是在

public static boolean isSupportLocal(int type) {
        switch (type) {
            case FunctionType.STAKING_FUNC_TYPE:
            case FunctionType.UPDATE_STAKING_INFO_FUNC_TYPE:
            case FunctionType.ADD_STAKING_FUNC_TYPE:
            case FunctionType.WITHDREW_STAKING_FUNC_TYPE:
            case FunctionType.SUBMIT_TEXT_FUNC_TYPE:
            case FunctionType.SUBMIT_VERSION_FUNC_TYPE:
            case FunctionType.SUBMIR_PARAM_FUNCTION_TYPE:
            case FunctionType.SUBMIT_CANCEL_FUNC_TYPE:
            case FunctionType.VOTE_FUNC_TYPE:
            case FunctionType.DECLARE_VERSION_FUNC_TYPE:
            case FunctionType.REPORT_DOUBLESIGN_FUNC_TYPE:
            case FunctionType.CREATE_RESTRICTINGPLAN_FUNC_TYPE:
                return true;
            default:
                return false;
        }
    }

中未出现的function类型,调用了无gas参数设置的方法,一定会抛出NoSupportFunctionType异常。
已知存在的问题存在于DelegateContractRewardContract

2 Likes

多谢发现问题。请使用最新的SDK。参考:

https://github.com/PlatONnetwork/client-sdk-java/blob/develop-0.15.1/README.md
<dependency>
    <groupId>com.platon.sdk</groupId>
    <artifactId>core</artifactId>
    <version>0.15.1.8</version>
</dependency>