Merge pull request #6009 from eugenp/web3j-fix
remove completablefuture
This commit is contained in:
commit
f03d62ce1f
|
@ -32,8 +32,8 @@ public class EthereumRestController {
|
||||||
|
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
CompletableFuture<EthBlockNumber> result = web3Service.getBlockNumber();
|
EthBlockNumber result = web3Service.getBlockNumber();
|
||||||
responseTransfer.setMessage(result.get().toString());
|
responseTransfer.setMessage(result.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
responseTransfer.setMessage(GENERIC_EXCEPTION);
|
responseTransfer.setMessage(GENERIC_EXCEPTION);
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ public class EthereumRestController {
|
||||||
|
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
CompletableFuture<EthAccounts> result = web3Service.getEthAccounts();
|
EthAccounts result = web3Service.getEthAccounts();
|
||||||
responseTransfer.setMessage(result.get().toString());
|
responseTransfer.setMessage(result.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
responseTransfer.setMessage(GENERIC_EXCEPTION);
|
responseTransfer.setMessage(GENERIC_EXCEPTION);
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,8 @@ public class EthereumRestController {
|
||||||
Instant start = TimeHelper.start();
|
Instant start = TimeHelper.start();
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
CompletableFuture<EthGetTransactionCount> result = web3Service.getTransactionCount();
|
EthGetTransactionCount result = web3Service.getTransactionCount();
|
||||||
responseTransfer.setMessage(result.get().toString());
|
responseTransfer.setMessage(result.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
responseTransfer.setMessage(GENERIC_EXCEPTION);
|
responseTransfer.setMessage(GENERIC_EXCEPTION);
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,8 @@ public class EthereumRestController {
|
||||||
Instant start = TimeHelper.start();
|
Instant start = TimeHelper.start();
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
CompletableFuture<EthGetBalance> result = web3Service.getEthBalance();
|
EthGetBalance result = web3Service.getEthBalance();
|
||||||
responseTransfer.setMessage(result.get().toString());
|
responseTransfer.setMessage(result.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
responseTransfer.setMessage(GENERIC_EXCEPTION);
|
responseTransfer.setMessage(GENERIC_EXCEPTION);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,47 +47,47 @@ public class Web3Service {
|
||||||
return "0x" + binary;
|
return "0x" + binary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<EthBlockNumber> getBlockNumber() {
|
public EthBlockNumber getBlockNumber() {
|
||||||
EthBlockNumber result = new EthBlockNumber();
|
EthBlockNumber result = new EthBlockNumber();
|
||||||
try {
|
try {
|
||||||
result = this.web3j.ethBlockNumber().sendAsync().get();
|
result = this.web3j.ethBlockNumber().sendAsync().get();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println(GENERIC_EXCEPTION);
|
System.out.println(GENERIC_EXCEPTION);
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(result);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<EthAccounts> getEthAccounts() {
|
public EthAccounts getEthAccounts() {
|
||||||
EthAccounts result = new EthAccounts();
|
EthAccounts result = new EthAccounts();
|
||||||
try {
|
try {
|
||||||
result = this.web3j.ethAccounts().sendAsync().get();
|
result = this.web3j.ethAccounts().sendAsync().get();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println(GENERIC_EXCEPTION);
|
System.out.println(GENERIC_EXCEPTION);
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(result);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<EthGetTransactionCount> getTransactionCount() {
|
public EthGetTransactionCount getTransactionCount() {
|
||||||
EthGetTransactionCount result = new EthGetTransactionCount();
|
EthGetTransactionCount result = new EthGetTransactionCount();
|
||||||
try {
|
try {
|
||||||
result = this.web3j.ethGetTransactionCount(DEFAULT_ADDRESS, DefaultBlockParameter.valueOf("latest")).sendAsync().get();
|
result = this.web3j.ethGetTransactionCount(DEFAULT_ADDRESS, DefaultBlockParameter.valueOf("latest")).sendAsync().get();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println(GENERIC_EXCEPTION);
|
System.out.println(GENERIC_EXCEPTION);
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(result);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<EthGetBalance> getEthBalance() {
|
public EthGetBalance getEthBalance() {
|
||||||
EthGetBalance result = new EthGetBalance();
|
EthGetBalance result = new EthGetBalance();
|
||||||
try {
|
try {
|
||||||
result = this.web3j.ethGetBalance(DEFAULT_ADDRESS, DefaultBlockParameter.valueOf("latest")).sendAsync().get();
|
result = this.web3j.ethGetBalance(DEFAULT_ADDRESS, DefaultBlockParameter.valueOf("latest")).sendAsync().get();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println(GENERIC_EXCEPTION);
|
System.out.println(GENERIC_EXCEPTION);
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(result);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<String> fromScratchContractExample() {
|
public String fromScratchContractExample() {
|
||||||
|
|
||||||
String contractAddress = "";
|
String contractAddress = "";
|
||||||
|
|
||||||
|
@ -108,13 +108,13 @@ public class Web3Service {
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println(PLEASE_SUPPLY_REAL_DATA);
|
System.out.println(PLEASE_SUPPLY_REAL_DATA);
|
||||||
return CompletableFuture.completedFuture(PLEASE_SUPPLY_REAL_DATA);
|
return PLEASE_SUPPLY_REAL_DATA;
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(contractAddress);
|
return contractAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
public CompletableFuture<String> sendTx() {
|
public String sendTx() {
|
||||||
String transactionHash = "";
|
String transactionHash = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -135,10 +135,10 @@ public class Web3Service {
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println(PLEASE_SUPPLY_REAL_DATA);
|
System.out.println(PLEASE_SUPPLY_REAL_DATA);
|
||||||
return CompletableFuture.completedFuture(PLEASE_SUPPLY_REAL_DATA);
|
return PLEASE_SUPPLY_REAL_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CompletableFuture.completedFuture(transactionHash);
|
return transactionHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@ import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
public class EthereumContractUnitTest {
|
public class EthereumContractUnitTest {
|
||||||
|
|
||||||
private Web3Service web3Service;
|
private Web3Service web3Service;
|
||||||
|
@ -17,14 +15,14 @@ public class EthereumContractUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContract() {
|
public void testContract() {
|
||||||
CompletableFuture<String> result = web3Service.fromScratchContractExample();
|
String result = web3Service.fromScratchContractExample();
|
||||||
assert (result instanceof CompletableFuture);
|
assert (result instanceof String);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendTx() {
|
public void sendTx() {
|
||||||
CompletableFuture<String> result = web3Service.sendTx();
|
String result = web3Service.sendTx();
|
||||||
assert (result instanceof CompletableFuture);
|
assert (result instanceof String);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
Loading…
Reference in New Issue