Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into android
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/org/web3j/tx/ManagedTransaction.java
  • Loading branch information
conor10 committed Mar 7, 2017
1 parent 0c7c903 commit 01bdfa3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/web3j/tx/Contract.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public void setTransactionReceipt(TransactionReceipt transactionReceipt) {
*
* @return the TransactionReceipt generated at contract deployment
*/
public Optional<TransactionReceipt> getTransactionReceipt() {
return Optional.ofNullable(transactionReceipt);
public TransactionReceipt getTransactionReceipt() {
return transactionReceipt;
}

/**
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/org/web3j/tx/TransactionManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.web3j.tx;

import java.math.BigInteger;
import java.util.Optional;
import java.util.concurrent.ExecutionException;

import org.web3j.protocol.Web3j;
Expand Down Expand Up @@ -52,7 +51,7 @@ public abstract EthSendTransaction sendTransaction(

public abstract String getFromAddress();

private TransactionReceipt processResponse(EthSendTransaction transactionResponse)
protected TransactionReceipt processResponse(EthSendTransaction transactionResponse)
throws InterruptedException, ExecutionException, TransactionTimeoutException {
if (transactionResponse.hasError()) {
throw new RuntimeException("Error processing transaction request: " +
Expand All @@ -75,14 +74,14 @@ private TransactionReceipt getTransactionReceipt(
String transactionHash, int sleepDuration, int attempts)
throws InterruptedException, ExecutionException, TransactionTimeoutException {

Optional<TransactionReceipt> receiptOptional =
TransactionReceipt receiptOptional =
sendTransactionReceiptRequest(transactionHash);
for (int i = 0; i < attempts; i++) {
if (!receiptOptional.isPresent()) {
if (receiptOptional == null) {
Thread.sleep(sleepDuration);
receiptOptional = sendTransactionReceiptRequest(transactionHash);
} else {
return receiptOptional.get();
return receiptOptional;
}
}

Expand All @@ -91,7 +90,7 @@ private TransactionReceipt getTransactionReceipt(
" seconds for transaction: " + transactionHash));
}

private Optional<TransactionReceipt> sendTransactionReceiptRequest(
private TransactionReceipt sendTransactionReceiptRequest(
String transactionHash) throws InterruptedException, ExecutionException {
EthGetTransactionReceipt transactionReceipt =
web3j.ethGetTransactionReceipt(transactionHash).sendAsync().get();
Expand Down
8 changes: 5 additions & 3 deletions src/test/java/org/web3j/tx/ContractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
Expand Down Expand Up @@ -70,7 +72,7 @@ public void testGetContractAddress() {

@Test
public void testGetContractTransactionReceipt() {
assertFalse(contract.getTransactionReceipt().isPresent());
assertNull(contract.getTransactionReceipt());
}

@Test
Expand All @@ -90,8 +92,8 @@ public void testDeploy() throws Exception {
ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT,
"0xcafed00d", encodedConstructor, BigInteger.ZERO).get();
assertThat(deployedContract.getContractAddress(), is(ADDRESS));
assertTrue(deployedContract.getTransactionReceipt().isPresent());
assertThat(deployedContract.getTransactionReceipt().get(), equalTo(transactionReceipt));
assertNotNull(deployedContract.getTransactionReceipt());
assertThat(deployedContract.getTransactionReceipt(), equalTo(transactionReceipt));
}

@Test(expected = RuntimeException.class)
Expand Down

0 comments on commit 01bdfa3

Please sign in to comment.