Permalink
Browse files

1. Bumped version to 3.1.1.

2. Added shutdown hooks to Executor service factory methods.
3. Fixed regression with generated Events in smart contract wrappers #242.
4. Added new new company to web3j users.
5. Removed ens reference from settings.gradle.
  • Loading branch information...
conor10 committed Nov 15, 2017
1 parent 05e8d34 commit fc5c992f4ff750916ba597086c01bb24f4c679bd
@@ -527,6 +527,7 @@ Please submit a pull request if you wish to include your company on the list:
- `Amberdata <https://www.amberdata.io/>`_
- `blk.io <https://blk.io>`_
- `comitFS <http://www.comitfs.com/>`_
- `ConsenSys <https://consensys.net/>`_
- `Othera <https://www.othera.io/>`_
@@ -44,7 +44,7 @@ allprojects {
targetCompatibility = 1.8
group 'org.web3j'
version '3.1.0'
version '3.1.1'
apply plugin: 'java'
apply plugin: 'jacoco'
@@ -378,7 +378,7 @@ private TypeName getWrapperType(TypeName typeName) {
}
}
private TypeName getEventWrapperType(TypeName typeName) {
private TypeName getIndexedEventWrapperType(TypeName typeName) {
if (useNativeJavaTypes) {
return getEventNativeType(typeName);
} else {
@@ -587,12 +587,12 @@ TypeSpec buildEventResponseObject(String className,
.addModifiers(Modifier.PUBLIC, Modifier.STATIC);
for (NamedTypeName namedType : indexedParameters) {
TypeName typeName = getEventWrapperType(namedType.typeName);
TypeName typeName = getIndexedEventWrapperType(namedType.typeName);
builder.addField(typeName, namedType.getName(), Modifier.PUBLIC);
}
for (NamedTypeName namedType : nonIndexedParameters) {
TypeName typeName = getEventWrapperType(namedType.typeName);
TypeName typeName = getWrapperType(namedType.typeName);
builder.addField(typeName, namedType.getName(), Modifier.PUBLIC);
}
@@ -732,7 +732,7 @@ CodeBlock buildTypedResponse(String objectName,
"$L.$L = ($T) eventValues.getIndexedValues().get($L)" + nativeConversion,
objectName,
indexedParameters.get(i).getName(),
getEventWrapperType(indexedParameters.get(i).getTypeName()),
getIndexedEventWrapperType(indexedParameters.get(i).getTypeName()),
i);
}
@@ -741,7 +741,7 @@ CodeBlock buildTypedResponse(String objectName,
"$L.$L = ($T) eventValues.getNonIndexedValues().get($L)" + nativeConversion,
objectName,
nonIndexedParameters.get(i).getName(),
getEventWrapperType(nonIndexedParameters.get(i).getTypeName()),
getWrapperType(nonIndexedParameters.get(i).getTypeName()),
i);
}
return builder.build();
@@ -260,15 +260,17 @@ public void testBuildFunctionConstantMultipleValueReturn() throws Exception {
@Test
public void testBuildEventConstantMultipleValueReturn() throws Exception {
AbiDefinition.NamedType id = new AbiDefinition.NamedType("id", "string", true);
AbiDefinition.NamedType fromAddress = new AbiDefinition.NamedType("from", "address");
AbiDefinition.NamedType toAddress = new AbiDefinition.NamedType("to", "address");
AbiDefinition.NamedType value = new AbiDefinition.NamedType("value", "uint256");
AbiDefinition.NamedType message = new AbiDefinition.NamedType("message", "string");
fromAddress.setIndexed(true);
toAddress.setIndexed(true);
AbiDefinition functionDefinition = new AbiDefinition(
false,
Arrays.asList(fromAddress, toAddress, value),
Arrays.asList(id, fromAddress, toAddress, value, message),
"Transfer",
new ArrayList<>(),
"event",
@@ -282,45 +284,53 @@ public void testBuildEventConstantMultipleValueReturn() throws Exception {
"class testClass {\n"
+ " public java.util.List<TransferEventResponse> getTransferEvents(org.web3j.protocol.core.methods.response.TransactionReceipt transactionReceipt) {\n"
+ " final org.web3j.abi.datatypes.Event event = new org.web3j.abi.datatypes.Event(\"Transfer\", \n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Address>() {}, new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Address>() {}),\n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Uint256>() {}));\n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Utf8String>() {}, new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Address>() {}, new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Address>() {}),\n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Uint256>() {}, new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Utf8String>() {}));\n"
+ " java.util.List<org.web3j.abi.EventValues> valueList = extractEventParameters(event, transactionReceipt);\n"
+ " java.util.ArrayList<TransferEventResponse> responses = new java.util.ArrayList<TransferEventResponse>(valueList.size());\n"
+ " for (org.web3j.abi.EventValues eventValues : valueList) {\n"
+ " TransferEventResponse typedResponse = new TransferEventResponse();\n"
+ " typedResponse.from = (java.lang.String) eventValues.getIndexedValues().get(0).getValue();\n"
+ " typedResponse.to = (java.lang.String) eventValues.getIndexedValues().get(1).getValue();\n"
+ " typedResponse.id = (byte[]) eventValues.getIndexedValues().get(0).getValue();\n"
+ " typedResponse.from = (java.lang.String) eventValues.getIndexedValues().get(1).getValue();\n"
+ " typedResponse.to = (java.lang.String) eventValues.getIndexedValues().get(2).getValue();\n"
+ " typedResponse.value = (java.math.BigInteger) eventValues.getNonIndexedValues().get(0).getValue();\n"
+ " typedResponse.message = (java.lang.String) eventValues.getNonIndexedValues().get(1).getValue();\n"
+ " responses.add(typedResponse);\n"
+ " }\n"
+ " return responses;\n"
+ " }\n"
+ "\n"
+ " public rx.Observable<TransferEventResponse> transferEventObservable(org.web3j.protocol.core.DefaultBlockParameter startBlock, org.web3j.protocol.core.DefaultBlockParameter endBlock) {\n"
+ " final org.web3j.abi.datatypes.Event event = new org.web3j.abi.datatypes.Event(\"Transfer\", \n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Address>() {}, new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Address>() {}),\n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Uint256>() {}));\n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Utf8String>() {}, new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Address>() {}, new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Address>() {}),\n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Uint256>() {}, new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Utf8String>() {}));\n"
+ " org.web3j.protocol.core.methods.request.EthFilter filter = new org.web3j.protocol.core.methods.request.EthFilter(startBlock, endBlock, getContractAddress());\n"
+ " filter.addSingleTopic(org.web3j.abi.EventEncoder.encode(event));\n"
+ " return web3j.ethLogObservable(filter).map(new rx.functions.Func1<org.web3j.protocol.core.methods.response.Log, TransferEventResponse>() {\n"
+ " @java.lang.Override\n"
+ " public TransferEventResponse call(org.web3j.protocol.core.methods.response.Log log) {\n"
+ " org.web3j.abi.EventValues eventValues = extractEventParameters(event, log);\n"
+ " TransferEventResponse typedResponse = new TransferEventResponse();\n"
+ " typedResponse.from = (java.lang.String) eventValues.getIndexedValues().get(0).getValue();\n"
+ " typedResponse.to = (java.lang.String) eventValues.getIndexedValues().get(1).getValue();\n"
+ " typedResponse.id = (byte[]) eventValues.getIndexedValues().get(0).getValue();\n"
+ " typedResponse.from = (java.lang.String) eventValues.getIndexedValues().get(1).getValue();\n"
+ " typedResponse.to = (java.lang.String) eventValues.getIndexedValues().get(2).getValue();\n"
+ " typedResponse.value = (java.math.BigInteger) eventValues.getNonIndexedValues().get(0).getValue();\n"
+ " typedResponse.message = (java.lang.String) eventValues.getNonIndexedValues().get(1).getValue();\n"
+ " return typedResponse;\n"
+ " }\n"
+ " });\n"
+ " }\n"
+ "\n"
+ " public static class TransferEventResponse {\n"
+ " public byte[] id;\n"
+ "\n"
+ " public java.lang.String from;\n"
+ "\n"
+ " public java.lang.String to;\n"
+ "\n"
+ " public java.math.BigInteger value;\n"
+ "\n"
+ " public java.lang.String message;\n"
+ " }\n"
+ "}\n";
//CHECKSTYLE:ON
@@ -10,10 +10,27 @@
* JSON-RPC Request object building factory.
*/
public interface Web3j extends Ethereum, Web3jRx {
/**
* Construct a new Web3j instance.
*
* @param web3jService web3j service instance - i.e. HTTP or IPC
* @return new Web3j instance
*/
static Web3j build(Web3jService web3jService) {
return new JsonRpc2_0Web3j(web3jService);
}
/**
* Construct a new Web3j instance.
*
* @param web3jService web3j service instance - i.e. HTTP or IPC
* @param pollingInterval polling interval for responses from network nodes
* @param scheduledExecutorService executor service to use for scheduled tasks.
* <strong>You are responsible for terminating this thread
* pool</strong>
* @return new Web3j instance
*/
static Web3j build(
Web3jService web3jService, long pollingInterval,
ScheduledExecutorService scheduledExecutorService) {
@@ -173,6 +173,12 @@ public NamedType(String name, String type) {
this.type = type;
}
public NamedType(String name, String type, boolean indexed) {
this.name = name;
this.type = type;
this.indexed = indexed;
}
public String getName() {
return name;
}
@@ -2,16 +2,21 @@
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* Async task facilitation.
*/
public class Async {
private static final Executor executor = Executors.newCachedThreadPool();
private static final ExecutorService executor = Executors.newCachedThreadPool();
static {
Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown(executor)));
}
public static <T> CompletableFuture<T> run(Callable<T> callable) {
CompletableFuture<T> result = new CompletableFuture<>();
@@ -31,7 +36,39 @@ private static int getCpuCount() {
return Runtime.getRuntime().availableProcessors();
}
/**
* Provide a new ScheduledExecutorService instance.
*
* <p>A shutdown hook is created to terminate the thread pool on application termination.
*
* @return new ScheduledExecutorService
*/
public static ScheduledExecutorService defaultExecutorService() {
return Executors.newScheduledThreadPool(getCpuCount());
ScheduledExecutorService scheduledExecutorService =
Executors.newScheduledThreadPool(getCpuCount());
Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown(scheduledExecutorService)));
return scheduledExecutorService;
}
/**
* Shutdown as per {@link ExecutorService} Javadoc recommendation.
*
* @param executorService executor service we wish to shut down.
*/
private static void shutdown(ExecutorService executorService) {
executorService.shutdown();
try {
if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
executorService.shutdownNow();
if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
System.err.println("Thread pool did not terminate");
}
}
} catch (InterruptedException ie) {
executorService.shutdownNow();
Thread.currentThread().interrupt();
}
}
}
@@ -3,5 +3,6 @@ Companies using web3j
- `Amberdata <https://www.amberdata.io/>`_
- `blk.io <https://blk.io>`_
- `comitFS <http://www.comitfs.com/>`_
- `ConsenSys <https://consensys.net/>`_
- `Othera <http://www.othera.io/>`_
@@ -195,7 +195,8 @@ And this also can be invoked by calling the Java class:
org.web3j.codegen.TruffleJsonFunctionWrapperGenerator /path/to/<truffle-smart-contract-output>.json -o /path/to/src/main/java -p com.your.organisation.name
A wrapper generated this way ia "enhanced" to expose the per-network deployed address of the contract. These addresses are from the truffle deployment at the time the wrapper is generared.
A wrapper generated this way ia "enhanced" to expose the per-network deployed address of the
contract. These addresses are from the truffle deployment at the time the wrapper is generared.
.. _construction-and-deployment:
@@ -5,7 +5,6 @@ include 'codegen'
include 'console'
include 'core'
include 'crypto'
include 'ens'
include 'geth'
include 'infura'
include 'integration-tests'

0 comments on commit fc5c992

Please sign in to comment.