Permalink
Browse files

1. Added TransactionReceiptProcessors to provide flexibility on how w…

…eb3j manages querying for transactions that have yet to be mined.

2. Migrated tuples into their own module.
3. Added module descriptions to all Gradle build files.
  • Loading branch information...
conor10 committed Oct 19, 2017
1 parent 07abcb5 commit a1b55ded98c7d4970e9dbd0dc2e12779eb620c18
Showing with 650 additions and 134 deletions.
  1. +2 −0 abi/build.gradle
  2. +3 −0 build.gradle
  3. +2 −0 codegen/build.gradle
  4. +1 −1 codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java
  5. +3 −3 codegen/src/main/java/org/web3j/codegen/TupleGenerator.java
  6. +2 −2 codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperTest.java
  7. +2 −0 console/build.gradle
  8. +3 −0 core/build.gradle
  9. +9 −0 core/src/main/java/org/web3j/tx/ClientTransactionManager.java
  10. +16 −0 core/src/main/java/org/web3j/tx/FastRawTransactionManager.java
  11. +15 −1 core/src/main/java/org/web3j/tx/RawTransactionManager.java
  12. +14 −56 core/src/main/java/org/web3j/tx/TransactionManager.java
  13. +12 −0 core/src/main/java/org/web3j/tx/response/Callback.java
  14. +185 −0 core/src/main/java/org/web3j/tx/response/EmptyTransactionReceipt.java
  15. +24 −0 core/src/main/java/org/web3j/tx/response/NoOpProcessor.java
  16. +55 −0 core/src/main/java/org/web3j/tx/response/PollingTransactionReceiptProcessor.java
  17. +126 −0 core/src/main/java/org/web3j/tx/response/QueuingTransactionReceiptProcessor.java
  18. +37 −0 core/src/main/java/org/web3j/tx/response/TransactionReceiptProcessor.java
  19. +2 −0 geth/build.gradle
  20. +2 −0 infura/build.gradle
  21. +4 −1 integration-tests/build.gradle
  22. +1 −1 integration-tests/src/test/java/org/web3j/generated/ShipIt.java
  23. +78 −27 integration-tests/src/test/java/org/web3j/protocol/scenarios/FastRawTransactionManagerIT.java
  24. +2 −0 parity/build.gradle
  25. +2 −0 rlp/build.gradle
  26. +2 −0 settings.gradle
  27. +2 −0 tuples/build.gradle
  28. +1 −1 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/EmptyTuple.java
  29. +1 −1 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/Tuple.java
  30. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple1.java
  31. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple10.java
  32. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple11.java
  33. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple12.java
  34. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple13.java
  35. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple14.java
  36. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple15.java
  37. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple16.java
  38. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple17.java
  39. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple18.java
  40. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple19.java
  41. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple2.java
  42. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple20.java
  43. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple3.java
  44. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple4.java
  45. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple5.java
  46. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple6.java
  47. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple7.java
  48. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple8.java
  49. +2 −2 {core/src/main/java/org/web3j/utils → tuples/src/main/java/org/web3j}/tuples/generated/Tuple9.java
  50. +2 −0 utils/build.gradle
View
@@ -1,4 +1,6 @@
description 'Ethereum Application Binary Interface (ABI) for working with smart contracts'
dependencies {
compile project(':utils')
}
View
@@ -11,6 +11,7 @@ buildscript {
// test dependencies
ext.equalsverifierVersion = '2.1.7'
ext.junitVersion = '4.11'
ext.junitBenchmarkVersion = '0.7.2'
ext.logbackVersion = '1.2.3'
ext.mockitoVersion = '1.10.19'
@@ -36,6 +37,8 @@ apply plugin: 'idea'
apply plugin: 'io.codearte.nexus-staging'
apply plugin: 'jacoco'
description 'web3j base project'
allprojects {
sourceCompatibility = 1.8
View
@@ -1,4 +1,6 @@
description 'web3j project code generators'
dependencies {
compile project(':core'), "com.squareup:javapoet:$javapoetVersion"
}
@@ -441,7 +441,7 @@ private void buildConstantFunction(
ParameterizedTypeName tupleType = ParameterizedTypeName.get(
ClassName.get(
"org.web3j.utils.tuples.generated",
"org.web3j.tuples.generated",
"Tuple" + returnTypes.size()),
returnTypes.toArray(
new TypeName[returnTypes.size()]));
@@ -10,16 +10,16 @@
import com.squareup.javapoet.TypeSpec;
import com.squareup.javapoet.TypeVariableName;
import org.web3j.tuples.Tuple;
import org.web3j.utils.Strings;
import org.web3j.utils.tuples.Tuple;
/**
* A class for generating arbitrary sized tuples.
*/
public class TupleGenerator extends Generator {
static final int LIMIT = 20;
static final String PACKAGE_NAME = "org.web3j.utils.tuples.generated";
static final String PACKAGE_NAME = "org.web3j.tuples.generated";
static final String CLASS_NAME = "Tuple";
private static final String SIZE = "SIZE";
@@ -31,7 +31,7 @@ public static void main(String[] args) throws IOException {
if (args.length == 1) {
tupleGenerator.generate(args[0]);
} else {
tupleGenerator.generate(System.getProperty("user.dir") + "/core/src/main/java/");
tupleGenerator.generate(System.getProperty("user.dir") + "/tuples/src/main/java/");
}
}
@@ -209,13 +209,13 @@ public void testBuildFunctionConstantMultipleValueReturn() throws Exception {
MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);
//CHECKSTYLE:OFF
String expected = "public org.web3j.utils.tuples.generated.Tuple2<java.math.BigInteger, java.math.BigInteger> functionName(java.math.BigInteger param1, java.math.BigInteger param2) throws java.io.IOException {\n"
String expected = "public org.web3j.tuples.generated.Tuple2<java.math.BigInteger, java.math.BigInteger> functionName(java.math.BigInteger param1, java.math.BigInteger param2) throws java.io.IOException {\n"
+ " org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\"functionName\", \n"
+ " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param1), \n"
+ " new org.web3j.abi.datatypes.generated.Uint32(param2)), \n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Int8>() {}, new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Int32>() {}));\n"
+ " java.util.List<org.web3j.abi.datatypes.Type> results = executeCallMultipleValueReturn(function);\n"
+ " return new org.web3j.utils.tuples.generated.Tuple2<java.math.BigInteger, java.math.BigInteger>(\n"
+ " return new org.web3j.tuples.generated.Tuple2<java.math.BigInteger, java.math.BigInteger>(\n"
+ " (java.math.BigInteger) results.get(0).getValue(), \n"
+ " (java.math.BigInteger) results.get(1).getValue());\n"
+ "}\n";
View
@@ -1,6 +1,8 @@
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'application'
description 'web3j command line tools'
dependencies {
compile project(':codegen'), project(':infura')
testCompile project(path: ':core', configuration: 'archives')
View
@@ -1,8 +1,11 @@
import java.text.SimpleDateFormat
description 'Core web3j components'
dependencies {
compile project(':rlp'),
project(':abi'),
project(':tuples'),
"com.fasterxml.jackson.core:jackson-databind:$jacksonVersion",
"com.github.jnr:jnr-unixsocket:$jnr_unixsocketVersion",
"com.squareup:javapoet:$javapoetVersion",
@@ -6,6 +6,7 @@
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.request.Transaction;
import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.tx.response.TransactionReceiptProcessor;
/**
* TransactionManager implementation for using an Ethereum node to transact.
@@ -31,6 +32,14 @@ public ClientTransactionManager(
this.fromAddress = fromAddress;
}
public ClientTransactionManager(
Web3j web3j, String fromAddress,
TransactionReceiptProcessor transactionReceiptProcessor) {
super(transactionReceiptProcessor);
this.web3j = web3j;
this.fromAddress = fromAddress;
}
@Override
public EthSendTransaction sendTransaction(
BigInteger gasPrice, BigInteger gasLimit, String to,
@@ -5,6 +5,9 @@
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.tx.response.Callback;
import org.web3j.tx.response.QueuingTransactionReceiptProcessor;
import org.web3j.tx.response.TransactionReceiptProcessor;
/**
* Simple RawTransactionManager derivative that manages nonces to facilitate multiple transactions
@@ -22,9 +25,22 @@ public FastRawTransactionManager(Web3j web3j, Credentials credentials) {
super(web3j, credentials);
}
public FastRawTransactionManager(
Web3j web3j, Credentials credentials,
TransactionReceiptProcessor transactionReceiptProcessor) {
super(web3j, credentials, ChainId.NONE, transactionReceiptProcessor);
}
public FastRawTransactionManager(
Web3j web3j, Credentials credentials, byte chainId,
TransactionReceiptProcessor transactionReceiptProcessor) {
super(web3j, credentials, chainId, transactionReceiptProcessor);
}
@Override
synchronized BigInteger getNonce() throws IOException {
if (nonce.signum() == -1) {
// obtain lock
nonce = super.getNonce();
} else {
nonce = nonce.add(BigInteger.ONE);
@@ -10,6 +10,7 @@
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.tx.response.TransactionReceiptProcessor;
import org.web3j.utils.Numeric;
/**
@@ -28,15 +29,28 @@
public RawTransactionManager(Web3j web3j, Credentials credentials, byte chainId) {
super(web3j);
this.web3j = web3j;
this.credentials = credentials;
this.chainId = chainId;
}
public RawTransactionManager(
Web3j web3j, Credentials credentials, byte chainId,
TransactionReceiptProcessor transactionReceiptProcessor) {
super(transactionReceiptProcessor);
this.web3j = web3j;
this.credentials = credentials;
this.chainId = chainId;
}
public RawTransactionManager(
Web3j web3j, Credentials credentials, byte chainId, int attempts, int sleepDuration) {
Web3j web3j, Credentials credentials, byte chainId, int attempts, long sleepDuration) {
super(web3j, attempts, sleepDuration);
this.web3j = web3j;
this.credentials = credentials;
@@ -2,38 +2,37 @@
import java.io.IOException;
import java.math.BigInteger;
import java.util.Optional;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.response.EthGetTransactionReceipt;
import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.exceptions.TransactionException;
import org.web3j.tx.response.PollingTransactionReceiptProcessor;
import org.web3j.tx.response.TransactionReceiptProcessor;
/**
* Transaction manager abstraction for executing transactions with Ethereum client via
* various mechanisms.
*/
public abstract class TransactionManager {
private static final int SLEEP_DURATION = 15000;
private static final int ATTEMPTS = 40;
public static final int DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH = 40;
public static final long DEFAULT_POLLING_FREQUENCY = 1000 * 15;
private final int sleepDuration;
private final int attempts;
private final TransactionReceiptProcessor transactionReceiptProcessor;
private final Web3j web3j;
protected TransactionManager(TransactionReceiptProcessor transactionReceiptProcessor) {
this.transactionReceiptProcessor = transactionReceiptProcessor;
}
protected TransactionManager(Web3j web3j) {
this.web3j = web3j;
this.attempts = ATTEMPTS;
this.sleepDuration = SLEEP_DURATION;
this.transactionReceiptProcessor = new PollingTransactionReceiptProcessor(
web3j, DEFAULT_POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
}
protected TransactionManager(Web3j web3j, int attempts, int sleepDuration) {
this.web3j = web3j;
this.attempts = attempts;
this.sleepDuration = sleepDuration;
protected TransactionManager(Web3j web3j, int attempts, long sleepDuration) {
this.transactionReceiptProcessor = new PollingTransactionReceiptProcessor(
web3j, sleepDuration, attempts);
}
TransactionReceipt executeTransaction(
@@ -62,49 +61,8 @@ private TransactionReceipt processResponse(EthSendTransaction transactionRespons
String transactionHash = transactionResponse.getTransactionHash();
return waitForTransactionReceipt(transactionHash);
return transactionReceiptProcessor.waitForTransactionReceipt(transactionHash);
}
TransactionReceipt waitForTransactionReceipt(
String transactionHash)
throws IOException, TransactionException {
return getTransactionReceipt(transactionHash, sleepDuration, attempts);
}
private TransactionReceipt getTransactionReceipt(
String transactionHash, int sleepDuration, int attempts)
throws IOException, TransactionException {
Optional<TransactionReceipt> receiptOptional =
sendTransactionReceiptRequest(transactionHash);
for (int i = 0; i < attempts; i++) {
if (!receiptOptional.isPresent()) {
try {
Thread.sleep(sleepDuration);
} catch (InterruptedException e) {
throw new TransactionException(e);
}
receiptOptional = sendTransactionReceiptRequest(transactionHash);
} else {
return receiptOptional.get();
}
}
throw new TransactionException("Transaction receipt was not generated after "
+ ((sleepDuration * attempts) / 1000
+ " seconds for transaction: " + transactionHash));
}
private Optional<TransactionReceipt> sendTransactionReceiptRequest(
String transactionHash) throws IOException, TransactionException {
EthGetTransactionReceipt transactionReceipt =
web3j.ethGetTransactionReceipt(transactionHash).send();
if (transactionReceipt.hasError()) {
throw new TransactionException("Error processing request: "
+ transactionReceipt.getError().getMessage());
}
return transactionReceipt.getTransactionReceipt();
}
}
@@ -0,0 +1,12 @@
package org.web3j.tx.response;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
/**
* Transaction receipt processor callback.
*/
public interface Callback {
void accept(TransactionReceipt transactionReceipt);
void exception(Exception exception);
}
Oops, something went wrong.

0 comments on commit a1b55de

Please sign in to comment.