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

Additional method added to generated class #657

Closed
wants to merge 6 commits into from

Conversation

MykolaMarkov
Copy link

It will be useful in case if you need only transaction hash of submitted transaction.

@codecov
Copy link

codecov bot commented Aug 3, 2018

Codecov Report

Merging #657 into master will decrease coverage by 0.04%.
The diff coverage is 93.33%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #657      +/-   ##
============================================
- Coverage     77.13%   77.08%   -0.05%     
- Complexity     1793     1798       +5     
============================================
  Files           239      239              
  Lines          6664     6690      +26     
  Branches        996      999       +3     
============================================
+ Hits           5140     5157      +17     
- Misses         1272     1282      +10     
+ Partials        252      251       -1
Impacted Files Coverage Δ Complexity Δ
...ava/org/web3j/codegen/SolidityFunctionWrapper.java 95.78% <93.33%> (-0.16%) 119 <3> (+5)
...n/java/org/web3j/protocol/core/filters/Filter.java 53.12% <0%> (-14.07%) 8% <0%> (-2%)
...ore/src/main/java/org/web3j/utils/Observables.java 88% <0%> (+8%) 11% <0%> (+2%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8349907...38cbc65. Read the comment docs.

@yuriymyronovych
Copy link
Contributor

yuriymyronovych commented Aug 3, 2018

@MykolaMarkov can you please show what would be the result? You can generate java wrapper for one of the example contracts in gen folder, would be easier for us to see.

@MykolaMarkov
Copy link
Author

Greeter code:

/**
 * <p>Auto generated code.
 * <p><strong>Do not modify!</strong>
 * <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
 * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the 
 * <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
 *
 * <p>Generated with web3j version 3.5.0.
 */
public class Greeter extends Contract {
    private static final String BINARY = "608060405234801561001057600080fd5b506040516102ec3803806102ec83398101604052805160008054600160a060020a0319163317905501805161004c906001906020840190610053565b50506100ee565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061009457805160ff19168380011785556100c1565b828001600101855582156100c1579182015b828111156100c15782518255916020019190600101906100a6565b506100cd9291506100d1565b5090565b6100eb91905b808211156100cd57600081556001016100d7565b90565b6101ef806100fd6000396000f30060806040526004361061004b5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166341c0e1b58114610050578063cfae321714610067575b600080fd5b34801561005c57600080fd5b506100656100f1565b005b34801561007357600080fd5b5061007c61012e565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100b657818101518382015260200161009e565b50505050905090810190601f1680156100e35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60005473ffffffffffffffffffffffffffffffffffffffff1633141561012c5760005473ffffffffffffffffffffffffffffffffffffffff16ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156101b95780601f1061018e576101008083540402835291602001916101b9565b820191906000526020600020905b81548152906001019060200180831161019c57829003601f168201915b50505050509050905600a165627a7a723058206ab1077e4c14d943950b92e2aab11d7a9d778da5230b64065465be83db7a9cd00029";

    public static final String FUNC_KILL = "kill";

    public static final String FUNC_GREET = "greet";

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

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

    public RemoteCall<TransactionReceipt> kill() {
        final Function function = new Function(
                FUNC_KILL, 
                Arrays.<Type>asList(), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public EthSendTransaction killTxId() throws IOException {
        final Function function = new Function(
                FUNC_KILL, 
                Arrays.<Type>asList(), 
                Collections.<TypeReference<?>>emptyList());
        return transactionManager.sendTransaction(
                gasProvider.getGasPrice(function.getName()),
                gasProvider.getGasLimit(function.getName()), contractAddress,
                org.web3j.abi.FunctionEncoder.encode(function), BigInteger.ZERO);
    }

    public RemoteCall<String> greet() {
        final Function function = new Function(FUNC_GREET, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
        return executeRemoteCallSingleValueReturn(function, String.class);
    }

    public static RemoteCall<Greeter> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, String _greeting) {
        String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(_greeting)));
        return deployRemoteCall(Greeter.class, web3j, credentials, gasPrice, gasLimit, BINARY, encodedConstructor);
    }

    public static RemoteCall<Greeter> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, String _greeting) {
        String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(_greeting)));
        return deployRemoteCall(Greeter.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, encodedConstructor);
    }

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

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

@yuriymyronovych
Copy link
Contributor

yuriymyronovych commented Aug 3, 2018

I am not 100% convinced we need those extra methods, you can get txHash from RemoteCall< TransactionReceipt> as well, you have to overwrite transactionManager though to make it return txHash strait away and not poll for tx being mined... @conor10 I will let you decide here.

In case we are keeping this change - something we definitely need to address is to make new method return RemoteCall<...>. There is a good reason why it was done that way in all other places.

@MykolaMarkov
Copy link
Author

I'm not sure that it is possible to receive transactionHash from RemoteCall<...> until block be mined.

@conor10
Copy link
Contributor

conor10 commented Oct 19, 2018

I don't think it's appropriate to add an additional method to every single transaction method. You can obtain the transaction hash using different transaction receipt processors - see the following docs.

Closing for this reason. Please reopen if you have further comments.

@conor10 conor10 closed this Oct 19, 2018
@MykolaMarkov
Copy link
Author

You can obtain the transaction hash using different transaction receipt processors - see the following docs.

I don't want to wait until block will be mined in this case I need only EthSendTransaction.getTransactionHash(). And I can receive whole transactionReceipt after it will be mined. In my application I want to send multiply transactions to block and I need to be sure that all transactions processed successfully. Transaction receipt processor can help you only in case if you are using only one JavaApp node to communicate with ETH network. In case if you send transaction from one node and want process response on any node, it doesn't help. This is my case.

Anyway thanks @conor10, @yuriymyronovych for doing great job!

@iikirilov
Copy link
Contributor

@MykolaMarkov can you draw a diagram - I do not understand your use-case.

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

Successfully merging this pull request may close these issues.

None yet

5 participants