web3j icon indicating copy to clipboard operation
web3j copied to clipboard

Class Generator error with public mapping

Open fraspadafora opened this issue 10 years ago • 1 comments

Hi, I'm using web3j v.1.0.6

I created this test Smart Contract:

pragma solidity ^0.4.2;
contract Test{
    
    enum Status{
        SHIPMENT_CREATED
    }
    
    struct Shipment{
        address sender;
        address receiver;
        uint creationDate;
        uint departureDate;
        Status status;
        uint packageWeight;
        string depot;
        bytes32 receiverHash;
    }
    
    mapping(address => Shipment) public shipments;
}

The ABI of this Smart Contract is:

[
  {
    "constant": true,
    "inputs": [
      {
        "name": "",
        "type": "address"
      }
    ],
    "name": "shipments",
    "outputs": [
      {
        "name": "sender",
        "type": "address"
      },
      {
        "name": "receiver",
        "type": "address"
      },
      {
        "name": "creationDate",
        "type": "uint256"
      },
      {
        "name": "departureDate",
        "type": "uint256"
      },
      {
        "name": "status",
        "type": "uint8"
      },
      {
        "name": "packageWeight",
        "type": "uint256"
      },
      {
        "name": "depot",
        "type": "string"
      },
      {
        "name": "receiverHash",
        "type": "bytes32"
      }
    ],
    "payable": false,
    "type": "function"
  }
]

And the compiled code is:

606060405261015c806100126000396000f3606060405260e060020a6000350463d51cd4ac811461001e575b610002565b3461000257600060208190526004803582526040909120805460018201546002830154600384015494840154600585015460078601546100869773ffffffffffffffffffffffffffffffffffffffff96871697969095169593949360ff909316926006019088565b6040805173ffffffffffffffffffffffffffffffffffffffff808b16825289166020820152908101879052606081018690526080810185905260a0810184905260e0810182905261010060c082018181528454600260018216158402600019019091160491830182905290610120830190859080156101465780601f1061011b57610100808354040283529160200191610146565b820191906000526020600020905b81548152906001019060200180831161012957829003601f168201915b5050995050505050505050505060405180910390f3

The problem is that the class generated is not correct, here is the class:

import java.lang.String;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Future;
import org.web3j.abi.Contract;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.Utf8String;
import org.web3j.abi.datatypes.generated.Bytes32;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.abi.datatypes.generated.Uint8;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;

/**
 * <p>Auto generated code.<br>
 * <strong>Do not modifiy!</strong><br>
 * Please use {@link org.web3j.codegen.SolidityFunctionWrapperGenerator} to update.</p>
 */
public final class Test extends Contract {
    private static final String BINARY = "606060405261015c806100126000396000f3606060405260e060020a6000350463d51cd4ac811461001e575b610002565b3461000257600060208190526004803582526040909120805460018201546002830154600384015494840154600585015460078601546100869773ffffffffffffffffffffffffffffffffffffffff96871697969095169593949360ff909316926006019088565b6040805173ffffffffffffffffffffffffffffffffffffffff808b16825289166020820152908101879052606081018690526080810185905260a0810184905260e0810182905261010060c082018181528454600260018216158402600019019091160491830182905290610120830190859080156101465780601f1061011b57610100808354040283529160200191610146565b820191906000526020600020905b81548152906001019060200180831161012957829003601f168201915b5050995050505050505050505060405180910390f3";

    private Test(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        super(contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    public <T extends Type> Future<List<T>> shipments(Address param0) {
        Function function = new Function<Bytes32>("shipments", 
                Arrays<Type>.asList(param0), 
                Arrays<TypeReference<?>>.asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}, new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}, new TypeReference<Uint8>() {}, new TypeReference<Uint256>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Bytes32>() {}));
        return executeCallMultipleValueReturnAsync(function);
    }

    public static Future<Test> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialValue) {
        return deployAsync(Test.class, web3j, credentials, gasPrice, gasLimit, BINARY, "", initialValue);
    }

    public static Test load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return new Test(contractAddress, web3j, credentials, gasPrice, gasLimit);
    }
}

The List of TypeReference is giving error. This is the part of code that is giving error: Arrays<Type>.asList(param0), Arrays<TypeReference<?>>.asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}, new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}, new TypeReference<Uint8>() {}, new TypeReference<Uint256>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Bytes32>() {}));

fraspadafora avatar Nov 19 '16 11:11 fraspadafora

This issue has been fixed with release 1.0.7.

conor10 avatar Nov 22 '16 04:11 conor10