remove completablefuture
This commit is contained in:
		
							parent
							
								
									5aed1b89bb
								
							
						
					
					
						commit
						415ecc6421
					
				| @ -32,8 +32,8 @@ public class EthereumRestController { | ||||
| 
 | ||||
|         return CompletableFuture.supplyAsync(() -> { | ||||
|             try { | ||||
|                 CompletableFuture<EthBlockNumber> result = web3Service.getBlockNumber(); | ||||
|                 responseTransfer.setMessage(result.get().toString()); | ||||
|                 EthBlockNumber result = web3Service.getBlockNumber(); | ||||
|                 responseTransfer.setMessage(result.toString()); | ||||
|             } catch (Exception e) { | ||||
|                 responseTransfer.setMessage(GENERIC_EXCEPTION); | ||||
|             } | ||||
| @ -51,8 +51,8 @@ public class EthereumRestController { | ||||
| 
 | ||||
|         return CompletableFuture.supplyAsync(() -> { | ||||
|             try { | ||||
|                 CompletableFuture<EthAccounts> result = web3Service.getEthAccounts(); | ||||
|                 responseTransfer.setMessage(result.get().toString()); | ||||
|                 EthAccounts result = web3Service.getEthAccounts(); | ||||
|                 responseTransfer.setMessage(result.toString()); | ||||
|             } catch (Exception e) { | ||||
|                 responseTransfer.setMessage(GENERIC_EXCEPTION); | ||||
|             } | ||||
| @ -70,8 +70,8 @@ public class EthereumRestController { | ||||
|         Instant start = TimeHelper.start(); | ||||
|         return CompletableFuture.supplyAsync(() -> { | ||||
|             try { | ||||
|                 CompletableFuture<EthGetTransactionCount> result = web3Service.getTransactionCount(); | ||||
|                 responseTransfer.setMessage(result.get().toString()); | ||||
|                 EthGetTransactionCount result = web3Service.getTransactionCount(); | ||||
|                 responseTransfer.setMessage(result.toString()); | ||||
|             } catch (Exception e) { | ||||
|                 responseTransfer.setMessage(GENERIC_EXCEPTION); | ||||
|             } | ||||
| @ -88,8 +88,8 @@ public class EthereumRestController { | ||||
|         Instant start = TimeHelper.start(); | ||||
|         return CompletableFuture.supplyAsync(() -> { | ||||
|             try { | ||||
|                 CompletableFuture<EthGetBalance> result = web3Service.getEthBalance(); | ||||
|                 responseTransfer.setMessage(result.get().toString()); | ||||
|                 EthGetBalance result = web3Service.getEthBalance(); | ||||
|                 responseTransfer.setMessage(result.toString()); | ||||
|             } catch (Exception e) { | ||||
|                 responseTransfer.setMessage(GENERIC_EXCEPTION); | ||||
|             } | ||||
|  | ||||
| @ -47,47 +47,47 @@ public class Web3Service { | ||||
|         return "0x" + binary; | ||||
|     } | ||||
| 
 | ||||
|     public CompletableFuture<EthBlockNumber> getBlockNumber() { | ||||
|     public EthBlockNumber getBlockNumber() { | ||||
|         EthBlockNumber result = new EthBlockNumber(); | ||||
|         try { | ||||
|             result = this.web3j.ethBlockNumber().sendAsync().get(); | ||||
|         } catch (Exception ex) { | ||||
|             System.out.println(GENERIC_EXCEPTION); | ||||
|         } | ||||
|         return CompletableFuture.completedFuture(result); | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     public CompletableFuture<EthAccounts> getEthAccounts() { | ||||
|     public EthAccounts getEthAccounts() { | ||||
|         EthAccounts result = new EthAccounts(); | ||||
|         try { | ||||
|              result = this.web3j.ethAccounts().sendAsync().get(); | ||||
|         } catch (Exception ex) { | ||||
|             System.out.println(GENERIC_EXCEPTION); | ||||
|         } | ||||
|         return CompletableFuture.completedFuture(result); | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     public CompletableFuture<EthGetTransactionCount> getTransactionCount() { | ||||
|     public EthGetTransactionCount getTransactionCount() { | ||||
|         EthGetTransactionCount result = new EthGetTransactionCount(); | ||||
|         try { | ||||
|              result = this.web3j.ethGetTransactionCount(DEFAULT_ADDRESS, DefaultBlockParameter.valueOf("latest")).sendAsync().get(); | ||||
|         } catch (Exception ex) { | ||||
|             System.out.println(GENERIC_EXCEPTION); | ||||
|         } | ||||
|         return CompletableFuture.completedFuture(result); | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     public CompletableFuture<EthGetBalance> getEthBalance() { | ||||
|     public EthGetBalance getEthBalance() { | ||||
|         EthGetBalance result = new EthGetBalance(); | ||||
|         try { | ||||
|             result = this.web3j.ethGetBalance(DEFAULT_ADDRESS, DefaultBlockParameter.valueOf("latest")).sendAsync().get(); | ||||
|         } catch (Exception ex) { | ||||
|             System.out.println(GENERIC_EXCEPTION); | ||||
|         } | ||||
|         return CompletableFuture.completedFuture(result); | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     public CompletableFuture<String> fromScratchContractExample() { | ||||
|     public String fromScratchContractExample() { | ||||
| 
 | ||||
|         String contractAddress = ""; | ||||
| 
 | ||||
| @ -108,13 +108,13 @@ public class Web3Service { | ||||
| 
 | ||||
|         } catch (Exception ex) { | ||||
|             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 | ||||
|     public CompletableFuture<String> sendTx() { | ||||
|     public String sendTx() { | ||||
|         String transactionHash = ""; | ||||
| 
 | ||||
|         try { | ||||
| @ -135,10 +135,10 @@ public class Web3Service { | ||||
| 
 | ||||
|         } catch (Exception ex) { | ||||
|             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.Test; | ||||
| 
 | ||||
| import java.util.concurrent.CompletableFuture; | ||||
| 
 | ||||
| public class EthereumContractUnitTest { | ||||
| 
 | ||||
|     private Web3Service web3Service; | ||||
| @ -17,14 +15,14 @@ public class EthereumContractUnitTest { | ||||
| 
 | ||||
|     @Test | ||||
|     public void testContract() { | ||||
|         CompletableFuture<String> result = web3Service.fromScratchContractExample(); | ||||
|         assert (result instanceof CompletableFuture); | ||||
|         String result = web3Service.fromScratchContractExample(); | ||||
|         assert (result instanceof String); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void sendTx() { | ||||
|         CompletableFuture<String> result = web3Service.sendTx(); | ||||
|         assert (result instanceof CompletableFuture); | ||||
|         String result = web3Service.sendTx(); | ||||
|         assert (result instanceof String); | ||||
|     } | ||||
| 
 | ||||
|     @After | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user