Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not resolve methods executeTransactionAsync, deployAsync #214

Closed
4ntoine opened this issue Oct 31, 2017 · 1 comment
Closed

Can not resolve methods executeTransactionAsync, deployAsync #214

4ntoine opened this issue Oct 31, 2017 · 1 comment

Comments

@4ntoine
Copy link

4ntoine commented Oct 31, 2017

Here is the contract:

pragma solidity ^0.4.0;
contract EventsContract {
    address owner;
    uint256 counter_;
    uint256 fireOn_;
    
    event Fire(uint256 counter);
    
    function EventsContract(uint256 fireOn) public {
        owner = msg.sender;
        counter_ = 0;
        fireOn_ = fireOn;
    }
    
    function check() public {
        if (counter_++ == fireOn_) {
            Fire(counter_);
        }
    }
}

I've generate smart contract wrapper using plugin:

<plugin>
                <groupId>org.web3j</groupId>
                <artifactId>web3j-maven-plugin</artifactId>
                <version>0.1.2</version>
                <configuration>
                    <packageName>name.antonsmirnov.xyz</packageName>
                    <sourceDestination>target/generated-sources</sourceDestination>
                    <nativeJavaType>true</nativeJavaType>
                    <soliditySourceFiles>
                        <directory>src/test/resources</directory>
                        <includes>
                            <include>**/*.sol</include>
                        </includes>
                    </soliditySourceFiles>
                </configuration>
            </plugin>

Here is generated code (EventsContract.java):

package name.antonsmirnov.xyz;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Future;
import org.web3j.abi.EventEncoder;
import org.web3j.abi.EventValues;
import org.web3j.abi.FunctionEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Event;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.methods.request.EthFilter;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;
import rx.Observable;
import rx.functions.Func1;

/**
 * Auto generated code.<br>
 * <strong>Do not modify!</strong><br>
 * Please use {@link org.web3j.codegen.SolidityFunctionWrapperGenerator} to update.
 *
 * <p>Generated with web3j version 2.2.1.
 */
public final class EventsContract extends Contract {
    private static final String BINARY = "606060405234610000576040516020806100f483398101604052515b60008054600160a060020a03191633600160a060020a031617815560015560028190555b505b60a58061004f6000396000f300606060405263ffffffff60e060020a600035041663919840ad81146022575b6000565b34600057602c602e565b005b60025460018054808201909155141560765760015460408051918252517ffce85cb7510ed083bb6e03c70c64dbc141b5835a4bd560b4496e90e69bc4d6669181900360200190a15b5b5600a165627a7a72305820c5b33b955af86969b5ed5723d2b73f90c6b0906157ae4d30355a53880981cf850029";

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

    private EventsContract(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    public List<FireEventResponse> getFireEvents(TransactionReceipt transactionReceipt) {
        final Event event = new Event("Fire", 
                Arrays.<TypeReference<?>>asList(),
                Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
        List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
        ArrayList<FireEventResponse> responses = new ArrayList<FireEventResponse>(valueList.size());
        for (EventValues eventValues : valueList) {
            FireEventResponse typedResponse = new FireEventResponse();
            typedResponse.counter = (Uint256) eventValues.getNonIndexedValues().get(0);
            responses.add(typedResponse);
        }
        return responses;
    }

    public Observable<FireEventResponse> fireEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
        final Event event = new Event("Fire", 
                Arrays.<TypeReference<?>>asList(),
                Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(event));
        return web3j.ethLogObservable(filter).map(new Func1<Log, FireEventResponse>() {
            @Override
            public FireEventResponse call(Log log) {
                EventValues eventValues = extractEventParameters(event, log);
                FireEventResponse typedResponse = new FireEventResponse();
                typedResponse.counter = (Uint256) eventValues.getNonIndexedValues().get(0);
                return typedResponse;
            }
        });
    }

    public Future<TransactionReceipt> check() {
        Function function = new Function("check", Arrays.<Type>asList(), Collections.<TypeReference<?>>emptyList());
        return executeTransactionAsync(function);
    }

    public static Future<EventsContract> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialWeiValue, Uint256 fireOn) {
        String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(fireOn));
        return deployAsync(EventsContract.class, web3j, credentials, gasPrice, gasLimit, BINARY, encodedConstructor, initialWeiValue);
    }

    public static Future<EventsContract> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialWeiValue, Uint256 fireOn) {
        String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(fireOn));
        return deployAsync(EventsContract.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, encodedConstructor, initialWeiValue);
    }

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

    public static EventsContract load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return new EventsContract(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    public static class FireEventResponse {
        public Uint256 counter;
    }
}

First, it's strange that web3j 2.2.1 is used though i've added 3.0.1 as dependency to the module.
Second, methods executeTransactionAsync and deployAsync are not resolved. Most likely it's because of version 2.2.1 used (see above).

Is it correct and how can i fix it?

@4ntoine
Copy link
Author

4ntoine commented Oct 31, 2017

Regenerated with plugin 0.1.3 and it's totally fine now!

@4ntoine 4ntoine closed this as completed Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant