forked from hyperledger-web3j/web3j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Added MetaCoin smart contract wrapper to integration-tests module …
…and build script. 2. Documentation updates.
- Loading branch information
Showing
6 changed files
with
176 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
targets=" | ||
MetaCoin/MetaCoin | ||
" | ||
|
||
for target in ${targets}; do | ||
dirName=$(dirname $target) | ||
fileName=$(basename $target) | ||
|
||
cd $dirName | ||
echo "Generating web3j bindings" | ||
web3j truffle generate \ | ||
build/contracts/${fileName}.json \ | ||
-p org.web3j.generated \ | ||
-o ../../../../../../integration-tests/src/test/java/ > /dev/null | ||
echo "Complete" | ||
|
||
cd - | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
integration-tests/src/test/java/org/web3j/generated/MetaCoin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package org.web3j.generated; | ||
|
||
import java.math.BigInteger; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import org.web3j.abi.EventEncoder; | ||
import org.web3j.abi.EventValues; | ||
import org.web3j.abi.TypeReference; | ||
import org.web3j.abi.datatypes.Address; | ||
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.RemoteCall; | ||
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; | ||
|
||
/** | ||
* <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.1.0. | ||
*/ | ||
public final class MetaCoin extends Contract { | ||
private static final String BINARY = "0x6060604052341561000f57600080fd5b6127106000803273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506103c5806100636000396000f300606060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680637bd703e81461005c57806390b98a11146100a9578063f8b2cb4f14610103575b600080fd5b341561006757600080fd5b610093600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610150565b6040518082815260200191505060405180910390f35b34156100b457600080fd5b6100e9600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506101f8565b604051808215151515815260200191505060405180910390f35b341561010e57600080fd5b61013a600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610351565b6040518082815260200191505060405180910390f35b600073__ConvertLib____________________________6396e4ee3d61017584610351565b60026000604051602001526040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808381526020018281526020019250505060206040518083038186803b15156101d657600080fd5b6102c65a03f415156101e757600080fd5b505050604051805190509050919050565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610249576000905061034b565b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190505b92915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490509190505600a165627a7a72305820f791829bf0c920a6d43123cac9b9894757ddc838c17efbad6d56773d6e3dcf4c0029"; | ||
|
||
protected static final HashMap<String, String> _addresses; | ||
|
||
static { | ||
_addresses = new HashMap<>(); | ||
_addresses.put("4", "0xaea9d31a4aeda9e510f7d85559261c16ea0b6b8b"); | ||
_addresses.put("4447", "0x254dffcd3277c0b1660f6d42efbb754edababc2b"); | ||
} | ||
|
||
private MetaCoin(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { | ||
super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); | ||
} | ||
|
||
private MetaCoin(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { | ||
super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); | ||
} | ||
|
||
public List<TransferEventResponse> getTransferEvents(TransactionReceipt transactionReceipt) { | ||
final Event event = new Event("Transfer", | ||
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}), | ||
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); | ||
List<EventValues> valueList = extractEventParameters(event, transactionReceipt); | ||
ArrayList<TransferEventResponse> responses = new ArrayList<TransferEventResponse>(valueList.size()); | ||
for (EventValues eventValues : valueList) { | ||
TransferEventResponse typedResponse = new TransferEventResponse(); | ||
typedResponse._from = (String) eventValues.getIndexedValues().get(0).getValue(); | ||
typedResponse._to = (String) eventValues.getIndexedValues().get(1).getValue(); | ||
typedResponse._value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); | ||
responses.add(typedResponse); | ||
} | ||
return responses; | ||
} | ||
|
||
public Observable<TransferEventResponse> transferEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { | ||
final Event event = new Event("Transfer", | ||
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}), | ||
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, TransferEventResponse>() { | ||
@Override | ||
public TransferEventResponse call(Log log) { | ||
EventValues eventValues = extractEventParameters(event, log); | ||
TransferEventResponse typedResponse = new TransferEventResponse(); | ||
typedResponse._from = (String) eventValues.getIndexedValues().get(0).getValue(); | ||
typedResponse._to = (String) eventValues.getIndexedValues().get(1).getValue(); | ||
typedResponse._value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); | ||
return typedResponse; | ||
} | ||
}); | ||
} | ||
|
||
public RemoteCall<BigInteger> getBalanceInEth(String addr) { | ||
Function function = new Function("getBalanceInEth", | ||
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(addr)), | ||
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); | ||
return executeRemoteCallSingleValueReturn(function, BigInteger.class); | ||
} | ||
|
||
public RemoteCall<TransactionReceipt> sendCoin(String receiver, BigInteger amount) { | ||
Function function = new Function( | ||
"sendCoin", | ||
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(receiver), | ||
new org.web3j.abi.datatypes.generated.Uint256(amount)), | ||
Collections.<TypeReference<?>>emptyList()); | ||
return executeRemoteCallTransaction(function); | ||
} | ||
|
||
public RemoteCall<BigInteger> getBalance(String addr) { | ||
Function function = new Function("getBalance", | ||
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(addr)), | ||
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); | ||
return executeRemoteCallSingleValueReturn(function, BigInteger.class); | ||
} | ||
|
||
public static RemoteCall<MetaCoin> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { | ||
return deployRemoteCall(MetaCoin.class, web3j, credentials, gasPrice, gasLimit, BINARY, ""); | ||
} | ||
|
||
public static RemoteCall<MetaCoin> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { | ||
return deployRemoteCall(MetaCoin.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, ""); | ||
} | ||
|
||
public static MetaCoin load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { | ||
return new MetaCoin(contractAddress, web3j, credentials, gasPrice, gasLimit); | ||
} | ||
|
||
public static MetaCoin load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { | ||
return new MetaCoin(contractAddress, web3j, transactionManager, gasPrice, gasLimit); | ||
} | ||
|
||
protected String getStaticDeployedAddress(String networkId) { | ||
return _addresses.get(networkId); | ||
} | ||
|
||
public static class TransferEventResponse { | ||
public String _from; | ||
|
||
public String _to; | ||
|
||
public BigInteger _value; | ||
} | ||
} |