@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; }
private String createContract( Credentials credentials, BigInteger initialSupply) throws Exception { String createTransactionHash = sendCreateContractTransaction(credentials, initialSupply); assertFalse(createTransactionHash.isEmpty()); TransactionReceipt createTransactionReceipt = waitForTransactionReceipt(createTransactionHash); assertThat(createTransactionReceipt.getTransactionHash(), is(createTransactionHash)); assertFalse("Contract execution ran out of gas", createTransactionReceipt.getGasUsed().equals(GAS_LIMIT)); String contractAddress = createTransactionReceipt.getContractAddress(); assertNotNull(contractAddress); return contractAddress; }
/** * Given the duration required to execute a transaction. * * @param data to send in transaction * @param weiValue in Wei to send in transaction * @return {@link Optional} containing our transaction receipt * @throws IOException if the call to the node fails * @throws TransactionException if the transaction was not mined while waiting */ TransactionReceipt executeTransaction( String data, BigInteger weiValue, String funcName) throws TransactionException, IOException { TransactionReceipt receipt = send(contractAddress, data, weiValue, gasProvider.getGasPrice(funcName), gasProvider.getGasLimit(funcName)); if (!receipt.isStatusOK()) { throw new TransactionException( String.format( "Transaction has failed with status: %s. " + "Gas used: %d. (not-enough gas?)", receipt.getStatus(), receipt.getGasUsed())); } return receipt; }
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)))); }
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 String getTransactionHash() { return super.getTransactionHash(); }
transactionHashAddressTextView.setText(transactionReceipt.getTransactionHash()); subDetailsTextView.setText("Gas Used: " + transactionReceipt.getGasUsed() + "\n" + "Block Hash: " + transactionReceipt.getBlockHash());
any(Unit.class))).thenReturn(transferRequest); when(transferRequest.send()).thenReturn(transactionReceipt); when(transactionReceipt.getStatus()).thenReturn("testStatus"); when(transactionReceipt.getBlockHash()).thenReturn("testBlockHash"); when(transactionReceipt.getBlockNumber()).thenReturn(BigInteger.valueOf(1)); when(web3j.ethCall(any(Transaction.class), any(DefaultBlockParameterName.class))).thenReturn(ethCallRequest); when(ethGetTransactionReceipt.getTransactionReceipt()).thenReturn(Optional.of(rawTransactionalRecept)); when(ethGetTransactionReceipt.getResult()).thenReturn(rawTransactionalRecept); when(rawTransactionalRecept.getContractAddress()).thenReturn("testContractAddress");
pendingTransactions.put(transactionReceipt.getTransactionHash(), new Object()); && !pendingTransactions.isEmpty(); i++) { for (TransactionReceipt transactionReceipt : transactionReceipts) { assertFalse(transactionReceipt.getBlockHash().isEmpty()); pendingTransactions.remove(transactionReceipt.getTransactionHash()); transactionReceipts.remove(transactionReceipt);
@Test public void testDeploySmartContract() throws Exception { BigInteger nonce = getNonce(ALICE.getAddress()); RawTransaction rawTransaction = createSmartContractTransaction(nonce); byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, ALICE); String hexValue = Numeric.toHexString(signedMessage); EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).sendAsync().get(); String transactionHash = ethSendTransaction.getTransactionHash(); assertFalse(transactionHash.isEmpty()); TransactionReceipt transactionReceipt = waitForTransactionReceipt(transactionHash); assertThat(transactionReceipt.getTransactionHash(), is(transactionHash)); assertFalse("Contract execution ran out of gas", rawTransaction.getGasLimit().equals(transactionReceipt.getGasUsed())); }
private void run(String walletFileLocation, String destinationAddress) { File walletFile = new File(walletFileLocation); Credentials credentials = getCredentials(walletFile); console.printf("Wallet for address " + credentials.getAddress() + " loaded\n"); if (!WalletUtils.isValidAddress(destinationAddress) && !EnsResolver.isValidEnsName(destinationAddress)) { exitError("Invalid destination address specified"); } Web3j web3j = getEthereumClient(); BigDecimal amountToTransfer = getAmountToTransfer(); Convert.Unit transferUnit = getTransferUnit(); BigDecimal amountInWei = Convert.toWei(amountToTransfer, transferUnit); confirmTransfer(amountToTransfer, transferUnit, amountInWei, destinationAddress); TransactionReceipt transactionReceipt = performTransfer( web3j, destinationAddress, credentials, amountInWei); console.printf("Funds have been successfully transferred from %s to %s%n" + "Transaction hash: %s%nMined block number: %s%n", credentials.getAddress(), destinationAddress, transactionReceipt.getTransactionHash(), transactionReceipt.getBlockNumber()); }
protected List<EventValuesWithLog> extractEventParametersWithLog( Event event, TransactionReceipt transactionReceipt) { return transactionReceipt.getLogs().stream() .map(log -> extractEventParametersWithLog(event, log)) .filter(Objects::nonNull) .collect(Collectors.toList()); }
gas.equals(transactionReceipt.getGasUsed())); List<Log> logs = transactionReceipt.getLogs(); assertFalse(logs.isEmpty());
String deployHash = txReceipt.getTransactionHash(); BigInteger deployFees = txReceipt .getCumulativeGasUsed() .multiply(Web3jConstants.GAS_PRICE);
private TransactionReceipt toReceipt(EthBlock.TransactionObject tx) { org.web3j.protocol.core.methods.response.TransactionReceipt receipt = web3JFacade.getReceipt(EthHash.of(tx.getHash())); boolean successful = !receipt.getGasUsed().equals(tx.getGas()); String error = ""; if(!successful) { error = "Error fromSeed RPC, all the gas was used"; } return new TransactionReceipt(EthHash.of(tx.getHash()), EthAddress.of(tx.getFrom()),EthAddress.of(tx.getTo()), EthAddress.of(receipt.getContractAddress()), error, EthData.empty(), successful); }
private static <T extends Contract> T create( T contract, String binary, String encodedConstructor, BigInteger value) throws IOException, TransactionException { TransactionReceipt transactionReceipt = contract.executeTransaction(binary + encodedConstructor, value, FUNC_DEPLOY); String contractAddress = transactionReceipt.getContractAddress(); if (contractAddress == null) { throw new RuntimeException("Empty contract address returned"); } contract.setContractAddress(contractAddress); contract.setTransactionReceipt(transactionReceipt); return contract; }
@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()); } }
@Override public void verify(final Node node) { final Optional<TransactionReceipt> response = node.execute(transaction); assertThat(response.isPresent()).isTrue(); assertThat(response.get().getStatus()).isEqualToIgnoringCase("0x1"); } }
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)))); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof TransactionReceipt)) { return false; } TransactionReceipt that = (TransactionReceipt) o; return getTransactionHash() != null ? getTransactionHash().equals(that.getTransactionHash()) : that.getTransactionHash() == null; }