org.web3j.protocol.core.methods.response.AbiDefinition Java Examples

The following examples show how to use org.web3j.protocol.core.methods.response.AbiDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TruffleJsonFunctionWrapperGenerator.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
public Contract(String contractName, List<AbiDefinition> abi, String bytecode,
        String deployedBytecode,
        String sourceMap, String deployedSourceMap, String source, String sourcePath,
        JsonNode ast,
        Compiler compiler, Map<String, NetworkInfo> networks, String schemaVersion,
        Date updatedAt) {
    super();
    this.contractName = contractName;
    this.abi = abi;
    this.bytecode = bytecode;
    this.deployedBytecode = deployedBytecode;
    this.sourceMap = sourceMap;
    this.deployedSourceMap = deployedSourceMap;
    this.source = source;
    this.sourcePath = sourcePath;
    this.ast = ast;
    this.compiler = compiler;
    this.networks = networks;
    this.schemaVersion = schemaVersion;
    this.updatedAt = updatedAt;
}
 
Example #2
Source File: SolidityFunctionWrapper.java    From web3j with Apache License 2.0 6 votes vote down vote up
private List<ParameterSpec> buildParameterTypes(
        List<AbiDefinition.NamedType> namedTypes, boolean primitives)
        throws ClassNotFoundException {

    List<ParameterSpec> result = new ArrayList<>(namedTypes.size());
    for (int i = 0; i < namedTypes.size(); i++) {
        AbiDefinition.NamedType namedType = namedTypes.get(i);

        String name = createValidParamName(namedType.getName(), i);
        String type = namedTypes.get(i).getType();

        if (type.startsWith("tuple")) {
            result.add(
                    ParameterSpec.builder(
                                    structClassNameMap.get(namedType.structIdentifier()), name)
                            .build());
        } else {
            result.add(ParameterSpec.builder(buildTypeName(type, primitives), name).build());
        }
    }
    return result;
}
 
Example #3
Source File: SolidityFunctionWrapper.java    From web3j with Apache License 2.0 6 votes vote down vote up
private MethodSpec buildDeploy(
        String className,
        AbiDefinition functionDefinition,
        Class authType,
        String authName,
        boolean withGasProvider)
        throws ClassNotFoundException {

    boolean isPayable = functionDefinition.isPayable();

    MethodSpec.Builder methodBuilder =
            getDeployMethodSpec(className, authType, authName, isPayable, withGasProvider);
    String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());

    if (!inputParams.isEmpty()) {
        return buildDeployWithParams(
                methodBuilder, className, inputParams, authName, isPayable, withGasProvider);
    } else {
        return buildDeployNoParams(
                methodBuilder, className, authName, isPayable, withGasProvider);
    }
}
 
Example #4
Source File: TruffleJsonFunctionWrapperGenerator.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
public Contract(String contractName, List<AbiDefinition> abi, String bytecode,
        String deployedBytecode,
        String sourceMap, String deployedSourceMap, String source, String sourcePath,
        JsonNode ast,
        Compiler compiler, Map<String, NetworkInfo> networks, String schemaVersion,
        Date updatedAt) {
    super();
    this.contractName = contractName;
    this.abi = abi;
    this.bytecode = bytecode;
    this.deployedBytecode = deployedBytecode;
    this.sourceMap = sourceMap;
    this.deployedSourceMap = deployedSourceMap;
    this.source = source;
    this.sourcePath = sourcePath;
    this.ast = ast;
    this.compiler = compiler;
    this.networks = networks;
    this.schemaVersion = schemaVersion;
    this.updatedAt = updatedAt;
}
 
Example #5
Source File: SolidityFunctionWrapper.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
MethodSpec buildFunction(
        AbiDefinition functionDefinition) throws ClassNotFoundException {
    String functionName = functionDefinition.getName();

    MethodSpec.Builder methodBuilder =
            MethodSpec.methodBuilder(functionName)
                    .addModifiers(Modifier.PUBLIC);

    String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());

    List<TypeName> outputParameterTypes = buildTypeNames(functionDefinition.getOutputs());
    if (functionDefinition.isConstant()) {
        buildConstantFunction(
                functionDefinition, methodBuilder, outputParameterTypes, inputParams);
    } else {
        buildTransactionFunction(
                functionDefinition, methodBuilder, inputParams);
    }

    return methodBuilder.build();
}
 
Example #6
Source File: SolidityFunctionWrapper.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
private MethodSpec buildDeploy(
        String className, AbiDefinition functionDefinition,
        Class authType, String authName, boolean withGasProvider) {

    boolean isPayable = functionDefinition.isPayable();

    MethodSpec.Builder methodBuilder = getDeployMethodSpec(
            className, authType, authName, isPayable, withGasProvider);
    String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());

    if (!inputParams.isEmpty()) {
        return buildDeployWithParams(
                methodBuilder, className, inputParams, authName,
                isPayable, withGasProvider);
    } else {
        return buildDeployNoParams(methodBuilder, className, authName,
                isPayable, withGasProvider);
    }
}
 
Example #7
Source File: SolidityFunctionWrapperTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildFunctionConstantSingleValueReturn() throws Exception {
    AbiDefinition functionDefinition =
            new AbiDefinition(
                    true,
                    Arrays.asList(new AbiDefinition.NamedType("param", "uint8")),
                    "functionName",
                    Arrays.asList(new AbiDefinition.NamedType("result", "int8")),
                    "type",
                    false);

    MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);

    String expected =
            "public org.web3j.protocol.core.RemoteFunctionCall<java.math.BigInteger> functionName(java.math.BigInteger param) {\n"
                    + "  final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_FUNCTIONNAME, \n"
                    + "      java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
                    + "      java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Int8>() {}));\n"
                    + "  return executeRemoteCallSingleValueReturn(function, java.math.BigInteger.class);\n"
                    + "}\n";

    assertEquals(methodSpec.toString(), (expected));
}
 
Example #8
Source File: SolidityFunctionWrapper.java    From web3j with Apache License 2.0 6 votes vote down vote up
private java.util.Collection<? extends AbiDefinition.NamedType> extractNested(
        final AbiDefinition.NamedType namedType) {
    if (namedType.getComponents().size() == 0) {
        return new ArrayList<>();
    } else {
        List<AbiDefinition.NamedType> nestedStructs = new ArrayList<>();
        namedType
                .getComponents()
                .forEach(
                        nestedNamedStruct -> {
                            nestedStructs.add(nestedNamedStruct);
                            nestedStructs.addAll(extractNested(nestedNamedStruct));
                        });
        return nestedStructs;
    }
}
 
Example #9
Source File: SolidityFunctionWrapperTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildingFunctionTransactionThatReturnsValueReportsWarning() throws Exception {
    AbiDefinition functionDefinition =
            new AbiDefinition(
                    false,
                    Arrays.asList(new AbiDefinition.NamedType("param", "uint8")),
                    "functionName",
                    Arrays.asList(new AbiDefinition.NamedType("result", "uint8")),
                    "type",
                    false);

    solidityFunctionWrapper.buildFunction(functionDefinition);

    verify(generationReporter)
            .report(
                    "Definition of the function functionName returns a value but is not defined as a view function. "
                            + "Please ensure it contains the view modifier if you want to read the return value");
}
 
Example #10
Source File: SolidityFunctionWrapperTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildFunctionTransaction() throws Exception {
    AbiDefinition functionDefinition =
            new AbiDefinition(
                    false,
                    Arrays.asList(new AbiDefinition.NamedType("param", "uint8")),
                    "functionName",
                    Collections.emptyList(),
                    "type",
                    false);

    MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);

    String expected =
            "public org.web3j.protocol.core.RemoteFunctionCall<org.web3j.protocol.core.methods.response.TransactionReceipt> functionName(java.math.BigInteger param) {\n"
                    + "  final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\n"
                    + "      FUNC_FUNCTIONNAME, \n"
                    + "      java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
                    + "      java.util.Collections.<org.web3j.abi.TypeReference<?>>emptyList());\n"
                    + "  return executeRemoteCallTransaction(function);\n"
                    + "}\n";

    assertEquals(methodSpec.toString(), (expected));
}
 
Example #11
Source File: SolidityFunctionWrapper.java    From web3j with Apache License 2.0 6 votes vote down vote up
private List<MethodSpec> buildFunctionDefinitions(
        String className,
        TypeSpec.Builder classBuilder,
        List<AbiDefinition> functionDefinitions)
        throws ClassNotFoundException {

    Set<String> duplicateFunctionNames = getDuplicateFunctionNames(functionDefinitions);
    List<MethodSpec> methodSpecs = new ArrayList<>();
    for (AbiDefinition functionDefinition : functionDefinitions) {
        if (functionDefinition.getType().equals(TYPE_FUNCTION)) {
            String functionName = funcNameToConst(functionDefinition.getName(), true);
            boolean useUpperCase = !duplicateFunctionNames.contains(functionName);
            methodSpecs.addAll(buildFunctions(functionDefinition, useUpperCase));
        } else if (functionDefinition.getType().equals(TYPE_EVENT)) {
            methodSpecs.addAll(buildEventFunctions(functionDefinition, classBuilder));
        }
    }
    return methodSpecs;
}
 
Example #12
Source File: SolidityFunctionWrapperTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildFunctionTransaction() throws Exception {
    AbiDefinition functionDefinition = new AbiDefinition(
            false,
            Arrays.asList(
                    new AbiDefinition.NamedType("param", "uint8")),
            "functionName",
            Collections.emptyList(),
            "type",
            false);

    MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);

    //CHECKSTYLE:OFF
    String expected =
            "public org.web3j.protocol.core.RemoteCall<org.web3j.protocol.core.methods.response.TransactionReceipt> functionName(java.math.BigInteger param) {\n"
                    + "  final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\n"
                    + "      FUNC_FUNCTIONNAME, \n"
                    + "      java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
                    + "      java.util.Collections.<org.web3j.abi.TypeReference<?>>emptyList());\n"
                    + "  return executeRemoteCallTransaction(function);\n"
                    + "}\n";
    //CHECKSTYLE:ON

    assertThat(methodSpec.toString(), is(expected));
}
 
Example #13
Source File: SolidityFunctionWrapperTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildFunctionConstantInvalid() throws Exception {
    AbiDefinition functionDefinition = new AbiDefinition(
            true,
            Arrays.asList(
                    new AbiDefinition.NamedType("param", "uint8")),
            "functionName",
            Collections.emptyList(),
            "type",
            false);

    MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);

    //CHECKSTYLE:OFF
    String expected =
            "public void functionName(java.math.BigInteger param) {\n"
            + "  throw new RuntimeException(\"cannot call constant function with void return type\");\n"
            + "}\n";
    //CHECKSTYLE:ON

    assertThat(methodSpec.toString(), is(expected));
}
 
Example #14
Source File: SolidityFunctionWrapperTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildPayableFunctionTransaction() throws Exception {
    AbiDefinition functionDefinition = new AbiDefinition(
            false,
            Arrays.asList(
                    new AbiDefinition.NamedType("param", "uint8")),
            "functionName",
            Collections.emptyList(),
            "type",
            true);

    MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);

    //CHECKSTYLE:OFF
    String expected =
            "public org.web3j.protocol.core.RemoteCall<org.web3j.protocol.core.methods.response.TransactionReceipt> functionName(java.math.BigInteger param, java.math.BigInteger vonValue) {\n"
                    + "  final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\n"
                    + "      FUNC_FUNCTIONNAME, \n"
                    + "      java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
                    + "      java.util.Collections.<org.web3j.abi.TypeReference<?>>emptyList());\n"
                    + "  return executeRemoteCallTransaction(function, vonValue);\n"
                    + "}\n";
    //CHECKSTYLE:ON

    assertThat(methodSpec.toString(), is(expected));
}
 
Example #15
Source File: SolidityFunctionWrapperTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildFuncNameConstants() throws Exception {
    AbiDefinition functionDefinition = new AbiDefinition(
            false,
            Arrays.asList(
                    new AbiDefinition.NamedType("param", "uint8")),
            "functionName",
            Collections.emptyList(),
            "function",
            true);
    TypeSpec.Builder builder = TypeSpec.classBuilder("testClass");

    builder.addFields(solidityFunctionWrapper
            .buildFuncNameConstants(Collections.singletonList(functionDefinition)));


    //CHECKSTYLE:OFF
    String expected =
            "class testClass {\n" +
                    "  public static final java.lang.String FUNC_FUNCTIONNAME = \"functionName\";\n" +
                    "}\n";
    //CHECKSTYLE:ON


    assertThat(builder.build().toString(), is(expected));
}
 
Example #16
Source File: SolidityFunctionWrapperTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildPayableFunctionTransaction() throws Exception {
    AbiDefinition functionDefinition =
            new AbiDefinition(
                    false,
                    Arrays.asList(new AbiDefinition.NamedType("param", "uint8")),
                    "functionName",
                    Collections.emptyList(),
                    "type",
                    true);

    MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);

    String expected =
            "public org.web3j.protocol.core.RemoteFunctionCall<org.web3j.protocol.core.methods.response.TransactionReceipt> functionName(java.math.BigInteger param, java.math.BigInteger weiValue) {\n"
                    + "  final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\n"
                    + "      FUNC_FUNCTIONNAME, \n"
                    + "      java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
                    + "      java.util.Collections.<org.web3j.abi.TypeReference<?>>emptyList());\n"
                    + "  return executeRemoteCallTransaction(function, weiValue);\n"
                    + "}\n";

    assertEquals(methodSpec.toString(), (expected));
}
 
Example #17
Source File: SolidityFunctionWrapperTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildFunctionConstantSingleValueReturn() throws Exception {
    AbiDefinition functionDefinition = new AbiDefinition(
            true,
            Arrays.asList(
                    new AbiDefinition.NamedType("param", "uint8")),
            "functionName",
            Arrays.asList(
                    new AbiDefinition.NamedType("result", "int8")),
            "type",
            false);

    MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);

    //CHECKSTYLE:OFF
    String expected =
            "public org.web3j.protocol.core.RemoteCall<java.math.BigInteger> functionName(java.math.BigInteger param) {\n"
                    + "  final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_FUNCTIONNAME, \n"
                    + "      java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
                    + "      java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Int8>() {}));\n"
                    + "  return executeRemoteCallSingleValueReturn(function, java.math.BigInteger.class);\n"
                    + "}\n";
    //CHECKSTYLE:ON

    assertThat(methodSpec.toString(), is(expected));
}
 
Example #18
Source File: SolidityFunctionWrapper.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
private MethodSpec buildDeploy(
        String className, AbiDefinition functionDefinition,
        Class authType, String authName) {

    boolean isPayable = functionDefinition.isPayable();

    MethodSpec.Builder methodBuilder = getDeployMethodSpec(
            className, authType, authName, isPayable);
    String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());

    if (!inputParams.isEmpty()) {
        return buildDeployWithParams(
                methodBuilder, className, inputParams, authName, isPayable);
    } else {
        return buildDeployNoParams(methodBuilder, className, authName, isPayable);
    }
}
 
Example #19
Source File: SolidityFunctionWrapperTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildFuncNameConstants() throws Exception {
    AbiDefinition functionDefinition =
            new AbiDefinition(
                    false,
                    Arrays.asList(new AbiDefinition.NamedType("param", "uint8")),
                    "functionName",
                    Collections.emptyList(),
                    "function",
                    true);
    TypeSpec.Builder builder = TypeSpec.classBuilder("testClass");

    builder.addFields(
            solidityFunctionWrapper.buildFuncNameConstants(
                    Collections.singletonList(functionDefinition)));

    String expected =
            "class testClass {\n"
                    + "  public static final java.lang.String FUNC_FUNCTIONNAME = \"functionName\";\n"
                    + "}\n";

    assertEquals(builder.build().toString(), (expected));
}
 
Example #20
Source File: SolidityFunctionWrapperTest.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBuildingFunctionTransactionThatReturnsValueReportsWarning() throws Exception {
    AbiDefinition functionDefinition = new AbiDefinition(
            false,
            Arrays.asList(
                    new AbiDefinition.NamedType("param", "uint8")),
            "functionName",
            Arrays.asList(
                    new AbiDefinition.NamedType("result", "uint8")),
            "type",
            false);

    solidityFunctionWrapper.buildFunction(functionDefinition);

    //CHECKSTYLE:OFF
    verify(generationReporter).report(
            "Definition of the function functionName returns a value but is not defined as a view function. " +
                    "Please ensure it contains the view modifier if you want to read the return value");
    //CHECKSTYLE:ON
}
 
Example #21
Source File: SolidityFunctionWrapperTest.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBuildPayableFunctionTransaction() throws Exception {
    AbiDefinition functionDefinition = new AbiDefinition(
            false,
            Arrays.asList(
                    new AbiDefinition.NamedType("param", "uint8")),
            "functionName",
            Collections.emptyList(),
            "type",
            true);

    MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);

    //CHECKSTYLE:OFF
    String expected =
            "public org.web3j.protocol.core.RemoteCall<org.web3j.protocol.core.methods.response.TransactionReceipt> functionName(java.math.BigInteger param, java.math.BigInteger weiValue) {\n"
                    + "  final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\n"
                    + "      \"functionName\", \n"
                    + "      java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
                    + "      java.util.Collections.<org.web3j.abi.TypeReference<?>>emptyList());\n"
                    + "  return executeRemoteCallTransaction(function, weiValue);\n"
                    + "}\n";
    //CHECKSTYLE:ON

    assertThat(methodSpec.toString(), is(expected));
}
 
Example #22
Source File: SolidityFunctionWrapper.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
MethodSpec buildFunction(
        AbiDefinition functionDefinition) throws ClassNotFoundException {
    String functionName = functionDefinition.getName();

    MethodSpec.Builder methodBuilder =
            MethodSpec.methodBuilder(functionName)
                    .addModifiers(Modifier.PUBLIC);

    String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());

    List<TypeName> outputParameterTypes = buildTypeNames(functionDefinition.getOutputs());
    if (functionDefinition.isConstant()) {
        buildConstantFunction(
                functionDefinition, methodBuilder, outputParameterTypes, inputParams);
    } else {
        buildTransactionFunction(
                functionDefinition, methodBuilder, inputParams);
    }

    return methodBuilder.build();
}
 
Example #23
Source File: SolidityFunctionWrapperTest.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBuildFunctionConstantSingleValueReturn() throws Exception {
    AbiDefinition functionDefinition = new AbiDefinition(
            true,
            Arrays.asList(
                    new AbiDefinition.NamedType("param", "uint8")),
            "functionName",
            Arrays.asList(
                    new AbiDefinition.NamedType("result", "int8")),
            "type",
            false);

    MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);

    //CHECKSTYLE:OFF
    String expected =
            "public org.web3j.protocol.core.RemoteCall<java.math.BigInteger> functionName(java.math.BigInteger param) {\n"
                    + "  final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\"functionName\", \n"
                    + "      java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
                    + "      java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Int8>() {}));\n"
                    + "  return executeRemoteCallSingleValueReturn(function, java.math.BigInteger.class);\n"
                    + "}\n";
    //CHECKSTYLE:ON

    assertThat(methodSpec.toString(), is(expected));
}
 
Example #24
Source File: SolidityFunctionWrapper.java    From web3j with Apache License 2.0 5 votes vote down vote up
public void generateJavaFiles(
        String contractName,
        String bin,
        List<AbiDefinition> abi,
        String destinationDir,
        String basePackageName,
        Map<String, String> addresses)
        throws IOException, ClassNotFoundException {

    generateJavaFiles(
            Contract.class, contractName, bin, abi, destinationDir, basePackageName, addresses);
}
 
Example #25
Source File: SolidityFunctionWrapperTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testBuildFunctionConstantInvalid() throws Exception {
    AbiDefinition functionDefinition = new AbiDefinition(
            true,
            Arrays.asList(
                    new AbiDefinition.NamedType("param", "uint8")),
            "functionName",
            Collections.emptyList(),
            "type",
            false);

    solidityFunctionWrapper.buildFunction(functionDefinition);
}
 
Example #26
Source File: SolidityFunctionWrapperTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBuildFunctionConstantSingleValueRawListReturn() throws Exception {
    AbiDefinition functionDefinition = new AbiDefinition(
            true,
            Arrays.asList(
                new AbiDefinition.NamedType("param", "uint8")),
            "functionName",
            Arrays.asList(
                    new AbiDefinition.NamedType("result", "address[]")),
            "type",
            false);

    MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);

    //CHECKSTYLE:OFF
    String expected =
            "public org.web3j.protocol.core.RemoteCall<java.util.List> functionName(java.math.BigInteger param) {\n"
            + "  final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\"functionName\", \n"
            + "      java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
            + "      java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.DynamicArray<org.web3j.abi.datatypes.Address>>() {}));\n"
            + "  return new org.web3j.protocol.core.RemoteCall<java.util.List>(\n"
            + "      new java.util.concurrent.Callable<java.util.List>() {\n"
            + "        @java.lang.Override\n"
            + "        @java.lang.SuppressWarnings(\"unchecked\")\n"
            + "        public java.util.List call() throws java.lang.Exception {\n"
            + "          java.util.List<org.web3j.abi.datatypes.Type> result = (java.util.List<org.web3j.abi.datatypes.Type>) executeCallSingleValueReturn(function, java.util.List.class);\n"
            + "          return convertToNative(result);\n"
            + "        }\n"
            + "      });\n"
            + "}\n";
    //CHECKSTYLE:ON

    assertThat(methodSpec.toString(), is(expected));
}
 
Example #27
Source File: SolidityFunctionWrapper.java    From web3j with Apache License 2.0 5 votes vote down vote up
private List<TypeName> buildTypeNames(
        List<AbiDefinition.NamedType> namedTypes, boolean primitives)
        throws ClassNotFoundException {

    List<TypeName> result = new ArrayList<>(namedTypes.size());
    for (AbiDefinition.NamedType namedType : namedTypes) {
        if (namedType.getType().equals("tuple")) {
            result.add(structClassNameMap.get(namedType.structIdentifier()));
        } else {
            result.add(buildTypeName(namedType.getType(), primitives));
        }
    }
    return result;
}
 
Example #28
Source File: TruffleJsonFunctionWrapperGenerator.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Contract(
        String contractName,
        List<AbiDefinition> abi,
        String bytecode,
        String deployedBytecode,
        String sourceMap,
        String deployedSourceMap,
        String source,
        String sourcePath,
        JsonNode ast,
        Compiler compiler,
        Map<String, NetworkInfo> networks,
        String schemaVersion,
        Date updatedAt) {
    super();
    this.contractName = contractName;
    this.abi = abi;
    this.bytecode = bytecode;
    this.deployedBytecode = deployedBytecode;
    this.sourceMap = sourceMap;
    this.deployedSourceMap = deployedSourceMap;
    this.source = source;
    this.sourcePath = sourcePath;
    this.ast = ast;
    this.compiler = compiler;
    this.networks = networks;
    this.schemaVersion = schemaVersion;
    this.updatedAt = updatedAt;
}
 
Example #29
Source File: EqualsVerifierResponseTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAbiDefinitionNamedType() {
    EqualsVerifier.forClass(AbiDefinition.NamedType.class)
            .withPrefabValues(
                    AbiDefinition.NamedType.class,
                    new AbiDefinition.NamedType(),
                    new AbiDefinition.NamedType("name", "uint256"))
            .suppress(Warning.NONFINAL_FIELDS)
            .suppress(Warning.STRICT_INHERITANCE)
            .verify();
}
 
Example #30
Source File: EqualsVerifierResponseTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAbiDefinition() {
    EqualsVerifier.forClass(AbiDefinition.class)
            .suppress(Warning.NONFINAL_FIELDS)
            .suppress(Warning.STRICT_INHERITANCE)
            .verify();
}