Skip to content

Commit 31b30ad

Browse files
committed
1. Added MetaCoin smart contract wrapper to integration-tests module and build script.
2. Documentation updates.
1 parent 1884378 commit 31b30ad

File tree

6 files changed

+176
-5
lines changed

6 files changed

+176
-5
lines changed

README.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ Features
4343
client API over HTTP and IPC
4444
- Ethereum wallet support
4545
- Auto-generation of Java smart contract wrappers to create, deploy, transact with and call smart
46-
contracts from native Java code (Solidity and Truffle definition formats supported)
46+
contracts from native Java code
47+
(`Solidity <http://solidity.readthedocs.io/en/latest/using-the-compiler.html#using-the-commandline-compiler>`_
48+
and
49+
`Truffle <https://github.com/trufflesuite/truffle-contract-schema>`_ definition formats supported)
4750
- Reactive-functional API for working with filters
4851
- `Ethereum Name Service (ENS) <https://ens.domains/>`_ support
4952
- Support for Parity's
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
targets="
4+
MetaCoin/MetaCoin
5+
"
6+
7+
for target in ${targets}; do
8+
dirName=$(dirname $target)
9+
fileName=$(basename $target)
10+
11+
cd $dirName
12+
echo "Generating web3j bindings"
13+
web3j truffle generate \
14+
build/contracts/${fileName}.json \
15+
-p org.web3j.generated \
16+
-o ../../../../../../integration-tests/src/test/java/ > /dev/null
17+
echo "Complete"
18+
19+
cd -
20+
done

docs/source/command_line.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ To send Ether to another address:
6464
6565
.. code-block:: bash
6666
67-
$ web3j wallet send <walletfile> <destination-address>
67+
$ web3j wallet send <walletfile> 0x<address>|<ensName>
6868
6969
When sending Ether to another address you will be asked a series of questions before the
7070
transaction takes place. See the below for a full example
@@ -73,7 +73,7 @@ The following example demonstrates using web3j to send Ether to another wallet.
7373
7474
.. code-block:: bash
7575
76-
$ ./web3j-<version>/bin/web3j wallet send <walletfile> <destination-address>
76+
$ ./web3j-<version>/bin/web3j wallet send <walletfile> 0x<address>|<ensName>
7777
7878
_ _____ _ _
7979
| | |____ (_) (_)

docs/source/index.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ Features
2222
client API over HTTP and IPC
2323
- Ethereum wallet support
2424
- Auto-generation of Java smart contract wrappers to create, deploy, transact with and call smart
25-
contracts from native Java code (Solidity and Truffle definition formats supported)
25+
contracts from native Java code
26+
(`Solidity <http://solidity.readthedocs.io/en/latest/using-the-compiler.html#using-the-commandline-compiler>`_
27+
and
28+
`Truffle <https://github.com/trufflesuite/truffle-contract-schema>`_ definition formats supported)
2629
- Reactive-functional API for working with filters
2730
- `Ethereum Name Service (ENS) <https://ens.domains/>`_ support
2831
- Support for Parity's

docs/source/smart_contracts.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ The smart contract wrappers support all common operations for working with smart
180180
Any method calls that requires an underlying JSON-RPC call to take place will return a Future to
181181
avoid blocking.
182182

183-
web3j also supports the generation of Java smart contract function wrappers directly from `Truffle <http://truffleframework.com/>`_ via the :doc:`command_line` utility.
183+
web3j also supports the generation of Java smart contract function wrappers directly from
184+
`Truffle's <http://truffleframework.com/>`_
185+
`Contract Schema <https://github.com/trufflesuite/truffle-contract-schema>`_
186+
via the :doc:`command_line` utility.
184187

185188
.. code-block:: bash
186189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package org.web3j.generated;
2+
3+
import java.math.BigInteger;
4+
import java.util.ArrayList;
5+
import java.util.Arrays;
6+
import java.util.Collections;
7+
import java.util.HashMap;
8+
import java.util.List;
9+
import org.web3j.abi.EventEncoder;
10+
import org.web3j.abi.EventValues;
11+
import org.web3j.abi.TypeReference;
12+
import org.web3j.abi.datatypes.Address;
13+
import org.web3j.abi.datatypes.Event;
14+
import org.web3j.abi.datatypes.Function;
15+
import org.web3j.abi.datatypes.Type;
16+
import org.web3j.abi.datatypes.generated.Uint256;
17+
import org.web3j.crypto.Credentials;
18+
import org.web3j.protocol.Web3j;
19+
import org.web3j.protocol.core.DefaultBlockParameter;
20+
import org.web3j.protocol.core.RemoteCall;
21+
import org.web3j.protocol.core.methods.request.EthFilter;
22+
import org.web3j.protocol.core.methods.response.Log;
23+
import org.web3j.protocol.core.methods.response.TransactionReceipt;
24+
import org.web3j.tx.Contract;
25+
import org.web3j.tx.TransactionManager;
26+
import rx.Observable;
27+
import rx.functions.Func1;
28+
29+
/**
30+
* <p>Auto generated code.
31+
* <p><strong>Do not modify!</strong>
32+
* <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
33+
* or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the
34+
* <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
35+
*
36+
* <p>Generated with web3j version 3.1.0.
37+
*/
38+
public final class MetaCoin extends Contract {
39+
private static final String BINARY = "0x6060604052341561000f57600080fd5b6127106000803273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506103c5806100636000396000f300606060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680637bd703e81461005c57806390b98a11146100a9578063f8b2cb4f14610103575b600080fd5b341561006757600080fd5b610093600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610150565b6040518082815260200191505060405180910390f35b34156100b457600080fd5b6100e9600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506101f8565b604051808215151515815260200191505060405180910390f35b341561010e57600080fd5b61013a600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610351565b6040518082815260200191505060405180910390f35b600073__ConvertLib____________________________6396e4ee3d61017584610351565b60026000604051602001526040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808381526020018281526020019250505060206040518083038186803b15156101d657600080fd5b6102c65a03f415156101e757600080fd5b505050604051805190509050919050565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610249576000905061034b565b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190505b92915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490509190505600a165627a7a72305820f791829bf0c920a6d43123cac9b9894757ddc838c17efbad6d56773d6e3dcf4c0029";
40+
41+
protected static final HashMap<String, String> _addresses;
42+
43+
static {
44+
_addresses = new HashMap<>();
45+
_addresses.put("4", "0xaea9d31a4aeda9e510f7d85559261c16ea0b6b8b");
46+
_addresses.put("4447", "0x254dffcd3277c0b1660f6d42efbb754edababc2b");
47+
}
48+
49+
private MetaCoin(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
50+
super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
51+
}
52+
53+
private MetaCoin(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
54+
super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
55+
}
56+
57+
public List<TransferEventResponse> getTransferEvents(TransactionReceipt transactionReceipt) {
58+
final Event event = new Event("Transfer",
59+
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}),
60+
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
61+
List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
62+
ArrayList<TransferEventResponse> responses = new ArrayList<TransferEventResponse>(valueList.size());
63+
for (EventValues eventValues : valueList) {
64+
TransferEventResponse typedResponse = new TransferEventResponse();
65+
typedResponse._from = (String) eventValues.getIndexedValues().get(0).getValue();
66+
typedResponse._to = (String) eventValues.getIndexedValues().get(1).getValue();
67+
typedResponse._value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
68+
responses.add(typedResponse);
69+
}
70+
return responses;
71+
}
72+
73+
public Observable<TransferEventResponse> transferEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
74+
final Event event = new Event("Transfer",
75+
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}),
76+
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
77+
EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
78+
filter.addSingleTopic(EventEncoder.encode(event));
79+
return web3j.ethLogObservable(filter).map(new Func1<Log, TransferEventResponse>() {
80+
@Override
81+
public TransferEventResponse call(Log log) {
82+
EventValues eventValues = extractEventParameters(event, log);
83+
TransferEventResponse typedResponse = new TransferEventResponse();
84+
typedResponse._from = (String) eventValues.getIndexedValues().get(0).getValue();
85+
typedResponse._to = (String) eventValues.getIndexedValues().get(1).getValue();
86+
typedResponse._value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
87+
return typedResponse;
88+
}
89+
});
90+
}
91+
92+
public RemoteCall<BigInteger> getBalanceInEth(String addr) {
93+
Function function = new Function("getBalanceInEth",
94+
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(addr)),
95+
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
96+
return executeRemoteCallSingleValueReturn(function, BigInteger.class);
97+
}
98+
99+
public RemoteCall<TransactionReceipt> sendCoin(String receiver, BigInteger amount) {
100+
Function function = new Function(
101+
"sendCoin",
102+
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(receiver),
103+
new org.web3j.abi.datatypes.generated.Uint256(amount)),
104+
Collections.<TypeReference<?>>emptyList());
105+
return executeRemoteCallTransaction(function);
106+
}
107+
108+
public RemoteCall<BigInteger> getBalance(String addr) {
109+
Function function = new Function("getBalance",
110+
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(addr)),
111+
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
112+
return executeRemoteCallSingleValueReturn(function, BigInteger.class);
113+
}
114+
115+
public static RemoteCall<MetaCoin> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
116+
return deployRemoteCall(MetaCoin.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
117+
}
118+
119+
public static RemoteCall<MetaCoin> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
120+
return deployRemoteCall(MetaCoin.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
121+
}
122+
123+
public static MetaCoin load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
124+
return new MetaCoin(contractAddress, web3j, credentials, gasPrice, gasLimit);
125+
}
126+
127+
public static MetaCoin load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
128+
return new MetaCoin(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
129+
}
130+
131+
protected String getStaticDeployedAddress(String networkId) {
132+
return _addresses.get(networkId);
133+
}
134+
135+
public static class TransferEventResponse {
136+
public String _from;
137+
138+
public String _to;
139+
140+
public BigInteger _value;
141+
}
142+
}

0 commit comments

Comments
 (0)