private Optional<TransactionReceipt> sendTransactionReceiptRequest( String transactionHash) throws Exception { EthGetTransactionReceipt transactionReceipt = web3j.ethGetTransactionReceipt(transactionHash).sendAsync().get(); return transactionReceipt.getTransactionReceipt(); }
public Optional<TransactionReceipt> getTransactionReceipt() { return Optional.ofNullable(getResult()); }
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(); } }
private static EthGetTransactionReceipt response(TransactionReceipt transactionReceipt) { EthGetTransactionReceipt response = new EthGetTransactionReceipt(); response.setResult(transactionReceipt); return response; } }
@Test(expected = RuntimeException.class) @SuppressWarnings("unchecked") public void testInvalidTransactionReceipt() throws Throwable { prepareNonceRequest(); prepareTransactionRequest(); EthGetTransactionReceipt ethGetTransactionReceipt = new EthGetTransactionReceipt(); ethGetTransactionReceipt.setError(new Response.Error(1, "Invalid transaction receipt")); Request<?, EthGetTransactionReceipt> getTransactionReceiptRequest = mock(Request.class); when(getTransactionReceiptRequest.sendAsync()) .thenReturn(Async.run(() -> ethGetTransactionReceipt)); when(web3j.ethGetTransactionReceipt(TRANSACTION_HASH)) .thenReturn((Request) getTransactionReceiptRequest); testErrorScenario(); }
@Override public Optional<TransactionReceipt> execute(final JsonRequestFactories node) { try { final EthGetTransactionReceipt result = node.eth().ethGetTransactionReceipt(input).send(); assertThat(result.hasError()).isFalse(); return result.getTransactionReceipt(); } catch (final IOException e) { throw new RuntimeException(e); } } }
when(web3j.ethGetTransactionReceipt(anyString())).thenReturn(ethSendTransactionReceipt); when(ethSendTransactionReceipt.send()).thenReturn(ethGetTransactionReceipt); when(ethGetTransactionReceipt.getTransactionReceipt()).thenReturn(Optional.of(rawTransactionalRecept)); when(ethGetTransactionReceipt.getResult()).thenReturn(rawTransactionalRecept); when(rawTransactionalRecept.getContractAddress()).thenReturn("testContractAddress");
@SuppressWarnings("unchecked") void prepareTransactionReceipt(TransactionReceipt transactionReceipt) throws IOException { EthGetTransactionReceipt ethGetTransactionReceipt = new EthGetTransactionReceipt(); ethGetTransactionReceipt.setResult(transactionReceipt); Request<?, EthGetTransactionReceipt> getTransactionReceiptRequest = mock(Request.class); when(getTransactionReceiptRequest.send()) .thenReturn(ethGetTransactionReceipt); when(web3j.ethGetTransactionReceipt(TRANSACTION_HASH)) .thenReturn((Request) getTransactionReceiptRequest); }
@Test public void testEthGetTransactionReceipt() throws Exception { EthGetTransactionReceipt ethGetTransactionReceipt = web3j.ethGetTransactionReceipt( config.validTransactionHash()).send(); assertTrue(ethGetTransactionReceipt.getTransactionReceipt().isPresent()); TransactionReceipt transactionReceipt = ethGetTransactionReceipt.getTransactionReceipt().get(); assertThat(transactionReceipt.getTransactionHash(), is(config.validTransactionHash())); }
assertThat(ethGetTransactionReceipt.getTransactionReceipt().get(), equalTo(transactionReceipt));
assertThat(ethGetTransactionReceipt.getTransactionReceipt().get(), equalTo(transactionReceipt));
public static Optional<TransactionReceipt> sendTransactionReceiptRequest( String transactionHash, Web3j web3j) throws Exception { EthGetTransactionReceipt transactionReceipt = web3j.ethGetTransactionReceipt(transactionHash).sendAsync().get(); return transactionReceipt.getTransactionReceipt(); }
/** * Returns the TransactionRecipt for the specified tx hash as an optional. */ public static Optional<TransactionReceipt> getReceipt(Web3j web3j, String transactionHash) throws Exception { EthGetTransactionReceipt receipt = web3j .ethGetTransactionReceipt(transactionHash) .sendAsync() .get(); return receipt.getTransactionReceipt(); }
/** * {inheritDoc} */ @Override public TransactionReceipt getTransactionReceipt(String txId) { try { final EthGetTransactionReceipt response = web3j.ethGetTransactionReceipt(txId).send(); return response .getTransactionReceipt() .map(receipt -> new Web3jTransactionReceipt(receipt)) .orElse(null); } catch (IOException e) { throw new BlockchainException("Unable to connect to the ethereum client", e); } }
@InvokeOnHeader(Web3jConstants.ETH_GET_TRANSACTION_RECEIPT) void ethGetTransactionReceipt(Message message) throws IOException { String transactionHash = message.getHeader(Web3jConstants.TRANSACTION_HASH, configuration::getTransactionHash, String.class); Request<?, EthGetTransactionReceipt> request = web3j.ethGetTransactionReceipt(transactionHash); setRequestId(message, request); EthGetTransactionReceipt response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.getTransactionReceipt()); } }
@Override public boolean hasNext() { if (logIter != null && logIter.hasNext()) { return true; } while (txIter.hasNext()) { EthBlock.TransactionResult tr = txIter.next(); EthBlock.TransactionObject tx = (EthBlock.TransactionObject) tr.get(); try { log.info("Getting tx receipts..."); Optional<TransactionReceipt> transactionReceiptOptional = web3j.ethGetTransactionReceipt(tx.getHash()) .send() .getTransactionReceipt() .filter(receipt -> receipt.getLogs() != null && !receipt.getLogs().isEmpty()); if (!transactionReceiptOptional.isPresent()) { continue; } this.logIter = transactionReceiptOptional.get().getLogs().iterator(); return true; } catch (IOException e) { throw new IllegalStateException("Unable to get transactionReceipt"); } } return false; }
public static Transaction fromEthGetTransactionReceipt( EthGetTransactionReceipt ethGetTransactionReceipt) { TransactionReceipt transactionReceipt = ethGetTransactionReceipt.getTransactionReceipt(); String hash = transactionReceipt.getTransactionHash(); String from = transactionReceipt.getFrom(); Log log = transactionReceipt.getLogs() .get(0); String to = log.getAddress(); String value = extractValueFromEthGetTransactionReceipt(log.getData()); Status status = parseStatus(transactionReceipt.getStatus()); String contractAddress = ethGetTransactionReceipt.getTransactionReceipt() .getTo(); return new Transaction(hash, from, to, value, status); }
@Override public Observable<Transaction> getTransactionByHash(String txHash) { return Observable.fromCallable(() -> web3j.ethGetTransactionReceipt(txHash) .send()) .flatMap(ethGetTransactionReceipt -> { if ((ethGetTransactionReceipt == null) || (ethGetTransactionReceipt.getTransactionReceipt() == null)) { EthTransaction send = web3j.ethGetTransactionByHash(txHash) .send(); return Observable.just(TransactionFactory.fromEthTransaction(send, Status.PENDING)); } else { return Observable.just( TransactionFactory.fromEthGetTransactionReceipt(ethGetTransactionReceipt)); } }) .retryWhen(attempts -> attempts.flatMap(i -> Observable.timer(5, TimeUnit.SECONDS))); }
@Override public BigInteger get(ByteArray createChannelTxHash) { return Observable.fromCallable( () -> web3j.ethGetTransactionReceipt(createChannelTxHash.toHexString(true)) .send() .getTransactionReceipt()) .retryWhen(flowable -> flowable.zipWith(Observable.interval(period, TimeUnit.SECONDS), (throwable, integer) -> integer)) .singleOrError() .timeout(timeout, TimeUnit.SECONDS, Single.error(new TransactionNotFoundException(createChannelTxHash.toHexString()))) .map(org.web3j.protocol.core.methods.response.TransactionReceipt::getBlockNumber) .blockingGet(); } }