protected List<EventValues> extractEventParameters( Event event, TransactionReceipt transactionReceipt) { return transactionReceipt.getLogs().stream() .map(log -> extractEventParameters(event, log)) .filter(Objects::nonNull) .collect(Collectors.toList()); }
@Override public int hashCode() { int result = getTransactionHash() != null ? getTransactionHash().hashCode() : 0; result = 31 * result + (transactionIndex != null ? transactionIndex.hashCode() : 0); result = 31 * result + (getBlockHash() != null ? getBlockHash().hashCode() : 0); result = 31 * result + (blockNumber != null ? blockNumber.hashCode() : 0); result = 31 * result + (cumulativeGasUsed != null ? cumulativeGasUsed.hashCode() : 0); result = 31 * result + (gasUsed != null ? gasUsed.hashCode() : 0); result = 31 * result + (getContractAddress() != null ? getContractAddress().hashCode() : 0); result = 31 * result + (getRoot() != null ? getRoot().hashCode() : 0); result = 31 * result + (getStatus() != null ? getStatus().hashCode() : 0); result = 31 * result + (getFrom() != null ? getFrom().hashCode() : 0); result = 31 * result + (getTo() != null ? getTo().hashCode() : 0); result = 31 * result + (getLogs() != null ? getLogs().hashCode() : 0); result = 31 * result + (getLogsBloom() != null ? getLogsBloom().hashCode() : 0); return result; }
protected List<EventValuesWithLog> extractEventParametersWithLog( Event event, TransactionReceipt transactionReceipt) { return transactionReceipt.getLogs().stream() .map(log -> extractEventParametersWithLog(event, log)) .filter(Objects::nonNull) .collect(Collectors.toList()); }
private void sendTransferTokensTransaction( Credentials credentials, String to, String contractAddress, BigInteger qty) throws Exception { Function function = transfer(to, qty); String functionHash = execute(credentials, function, contractAddress); TransactionReceipt transferTransactionReceipt = waitForTransactionReceipt(functionHash); assertThat(transferTransactionReceipt.getTransactionHash(), is(functionHash)); List<Log> logs = transferTransactionReceipt.getLogs(); assertFalse(logs.isEmpty()); Log log = logs.get(0); // verify the event was called with the function parameters List<String> topics = log.getTopics(); assertThat(topics.size(), is(3)); Event transferEvent = transferEvent(); // check function signature - we only have a single topic our event signature, // there are no indexed parameters in this example String encodedEventSignature = EventEncoder.encode(transferEvent); assertThat(topics.get(0), is(encodedEventSignature)); assertThat(new Address(topics.get(1)), is(new Address(credentials.getAddress()))); assertThat(new Address(topics.get(2)), is(new Address(to))); // verify qty transferred List<Type> results = FunctionReturnDecoder.decode( log.getData(), transferEvent.getNonIndexedParameters()); assertThat(results, equalTo(Collections.singletonList(new Uint256(qty)))); }
private void sendApproveTransaction( Credentials credentials, String spender, BigInteger value, String contractAddress) throws Exception { Function function = approve(spender, value); String functionHash = execute(credentials, function, contractAddress); TransactionReceipt transferTransactionReceipt = waitForTransactionReceipt(functionHash); assertThat(transferTransactionReceipt.getTransactionHash(), is(functionHash)); List<Log> logs = transferTransactionReceipt.getLogs(); assertFalse(logs.isEmpty()); Log log = logs.get(0); // verify the event was called with the function parameters List<String> topics = log.getTopics(); assertThat(topics.size(), is(3)); // event Transfer(address indexed _from, address indexed _to, uint256 _value); Event event = approvalEvent(); // check function signature - we only have a single topic our event signature, // there are no indexed parameters in this example String encodedEventSignature = EventEncoder.encode(event); assertThat(topics.get(0), is(encodedEventSignature)); assertThat(new Address(topics.get(1)), is(new Address(credentials.getAddress()))); assertThat(new Address(topics.get(2)), is(new Address(spender))); // verify our two event parameters List<Type> results = FunctionReturnDecoder.decode( log.getData(), event.getNonIndexedParameters()); assertThat(results, equalTo(Collections.singletonList(new Uint256(value)))); }
public void sendTransferFromTransaction( Credentials credentials, String from, String to, BigInteger value, String contractAddress) throws Exception { Function function = transferFrom(from, to, value); String functionHash = execute(credentials, function, contractAddress); TransactionReceipt transferTransactionReceipt = waitForTransactionReceipt(functionHash); assertThat(transferTransactionReceipt.getTransactionHash(), is(functionHash)); List<Log> logs = transferTransactionReceipt.getLogs(); assertFalse(logs.isEmpty()); Log log = logs.get(0); Event transferEvent = transferEvent(); List<String> topics = log.getTopics(); // check function signature - we only have a single topic our event signature, // there are no indexed parameters in this example String encodedEventSignature = EventEncoder.encode(transferEvent); assertThat(topics.get(0), is(encodedEventSignature)); assertThat(new Address(topics.get(1)), is(new Address(from))); assertThat(new Address(topics.get(2)), is(new Address(to))); // verify qty transferred List<Type> results = FunctionReturnDecoder.decode( log.getData(), transferEvent.getNonIndexedParameters()); assertThat(results, equalTo(Collections.singletonList(new Uint256(value)))); }
gas.equals(transactionReceipt.getGasUsed())); List<Log> logs = transactionReceipt.getLogs(); assertFalse(logs.isEmpty());
@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 Web3jTransactionReceipt( org.web3j.protocol.core.methods.response.TransactionReceipt web3TransactionReceipt) { logs = convertLogs(web3TransactionReceipt.getLogs()); try { final ModelMapper modelMapper = ModelMapperFactory.getInstance().createModelMapper(); //Skip logs modelMapper.getConfiguration().setPropertyCondition(ctx -> !ctx.getMapping().getLastDestinationProperty().getName().equals("logs")); modelMapper.map(web3TransactionReceipt, this); } catch (RuntimeException re) { re.printStackTrace(); throw re; } }
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); }