public String resolve(String contractId) { if (isValidEnsName(contractId)) { PublicResolver resolver = obtainPublicResolver(contractId); byte[] nameHash = NameHash.nameHashAsBytes(contractId); String contractAddress = null; try { contractAddress = resolver.addr(nameHash).send(); } catch (Exception e) { throw new RuntimeException("Unable to execute Ethereum request", e); } if (!WalletUtils.isValidAddress(contractAddress)) { throw new RuntimeException("Unable to resolve address for name: " + contractId); } else { return contractAddress; } } else { return contractId; } }
public static <T extends Contract> RemoteCall<T> deployRemoteCall( Class<T> type, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor, BigInteger value) { return new RemoteCall<>(() -> deploy( type, web3j, transactionManager, gasPrice, gasLimit, binary, encodedConstructor, value)); }
private TransactionReceipt performTransfer( Web3j web3j, String destinationAddress, Credentials credentials, BigDecimal amountInWei) { console.printf("Commencing transfer (this may take a few minutes) "); try { Future<TransactionReceipt> future = Transfer.sendFunds( web3j, credentials, destinationAddress, amountInWei, Convert.Unit.WEI) .sendAsync(); while (!future.isDone()) { console.printf("."); Thread.sleep(500); } console.printf("$%n%n"); return future.get(); } catch (InterruptedException | ExecutionException | TransactionException | IOException e) { exitError("Problem encountered transferring funds: \n" + e.getMessage()); } throw new RuntimeException("Application exit failure"); }
public Flowable<T> flowable() { return new RemoteCall<>(this::send).flowable(); } }
@Test public void testSimpleStorageContract() throws Exception { BigInteger value = BigInteger.valueOf(1000L); SimpleStorage simpleStorage = SimpleStorage.deploy( web3j, ALICE, GAS_PRICE, GAS_LIMIT).send(); assertNotNull(simpleStorage.set(value).send()); assertThat(simpleStorage.get().send(), is(value)); } }
public static <T extends Contract> RemoteCall<T> deployRemoteCall( Class<T> type, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) { return new RemoteCall<>(() -> deploy( type, web3j, transactionManager, contractGasProvider, binary, encodedConstructor, value)); }
@Test public void testTransactionPolling() throws Exception { List<Future<TransactionReceipt>> transactionReceipts = new LinkedList<>(); FastRawTransactionManager transactionManager = new FastRawTransactionManager( web3j, ALICE, new PollingTransactionReceiptProcessor( web3j, POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH)); Transfer transfer = new Transfer(web3j, transactionManager); BigInteger gasPrice = transfer.requestCurrentGasPrice(); for (int i = 0; i < COUNT; i++) { Future<TransactionReceipt> transactionReceiptFuture = createTransaction(transfer, gasPrice).sendAsync(); transactionReceipts.add(transactionReceiptFuture); } for (int i = 0; i < DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH && !transactionReceipts.isEmpty(); i++) { for (Iterator<Future<TransactionReceipt>> iterator = transactionReceipts.iterator(); iterator.hasNext(); ) { Future<TransactionReceipt> transactionReceiptFuture = iterator.next(); if (transactionReceiptFuture.isDone()) { TransactionReceipt transactionReceipt = transactionReceiptFuture.get(); assertFalse(transactionReceipt.getBlockHash().isEmpty()); iterator.remove(); } } Thread.sleep(POLLING_FREQUENCY); } assertTrue(transactionReceipts.isEmpty()); }
void testErrorScenario() throws Throwable { try { contract.performTransaction( new Address(BigInteger.TEN), new Uint256(BigInteger.ONE)).send(); } catch (InterruptedException e) { throw e; } catch (ExecutionException e) { throw e.getCause(); } }
public static <T extends Contract> RemoteCall<T> deployRemoteCall( Class<T> type, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, String binary, String encodedConstructor) { return new RemoteCall<>(() -> deploy( type, web3j, transactionManager, contractGasProvider, binary, encodedConstructor, BigInteger.ZERO)); }
public CompletableFuture<String> authorize(final String identifier, final String authorizedEthereumAddress, final String authorizedIndentity) { return ((Authorization) contract).authorize(identifier, authorizedEthereumAddress, authorizedIndentity) .sendAsync() // replace the complete receipt with the transaction hash only. .thenApply(TransactionReceipt::getTransactionHash); }
/** * Reverse name resolution as documented in the * <a href="https://docs.ens.domains/en/latest/userguide.html#reverse-name-resolution">specification</a>. * @param address an ethereum address, example: "0x314159265dd8dbb310642f98f50c066173c1259b" * @return a EnsName registered for provided address */ public String reverseResolve(String address) { if (WalletUtils.isValidAddress(address)) { String reverseName = Numeric.cleanHexPrefix(address) + REVERSE_NAME_SUFFIX; PublicResolver resolver = obtainPublicResolver(reverseName); byte[] nameHash = NameHash.nameHashAsBytes(reverseName); String name = null; try { name = resolver.name(nameHash).send(); } catch (Exception e) { throw new RuntimeException("Unable to execute Ethereum request", e); } if (!isValidEnsName(name)) { throw new RuntimeException("Unable to resolve name for address: " + address); } else { return name; } } else { throw new EnsResolutionException("Address is invalid: " + address); } }
public static <T extends Contract> RemoteCall<T> deployRemoteCall( Class<T> type, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor, BigInteger value) { return new RemoteCall<>(() -> deploy( type, web3j, credentials, gasPrice, gasLimit, binary, encodedConstructor, value)); }
public CompletableFuture<Integer> getPointsAmountByRing(Integer ringIndex) { return instance.getPointsAmountByRing(BigInteger.valueOf(ringIndex)).sendAsync().thenApply(BigInteger::intValue); }
@Test public void testTransfer() throws Exception { TransactionReceipt transactionReceipt = Transfer.sendFunds( web3j, ALICE, BOB.getAddress(), BigDecimal.valueOf(0.2), Convert.Unit.ETHER) .send(); assertFalse(transactionReceipt.getBlockHash().isEmpty()); } }
public static <T extends Contract> RemoteCall<T> deployRemoteCall( Class<T> type, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider, String binary, String encodedConstructor) { return new RemoteCall<>(() -> deploy( type, web3j, credentials, contractGasProvider, binary, encodedConstructor, BigInteger.ZERO)); }
public CompletableFuture<TransactionReceipt> deleteOracledAddress(String oracled) { return instance.deleteOracledAddress(oracled).sendAsync(); }
protected TransactionReceipt sendFunds(Credentials credentials, String toAddress, BigDecimal value, Convert.Unit unit) throws Exception { return new Transfer(web3j, getVerifiedTransactionManager(credentials)) .sendFunds(toAddress, value, unit).send(); } }
public static <T extends Contract> RemoteCall<T> deployRemoteCall( Class<T> type, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) { return new RemoteCall<>(() -> deploy( type, web3j, credentials, contractGasProvider, binary, encodedConstructor, value)); }
public CompletableFuture<TransactionReceipt> makeImmutable() { return instance.makeImmutable().sendAsync(); }
@Test public void testFibonacci() throws Exception { Fibonacci fibonacci = Fibonacci.load( "0x3c05b2564139fb55820b18b72e94b2178eaace7d", Web3j.build(new HttpService()), ALICE, STATIC_GAS_PROVIDER); BigInteger result = fibonacci.fibonacci(BigInteger.valueOf(10)).send(); assertThat(result, equalTo(BigInteger.valueOf(55))); }