@Override public int hashCode() { int result = getHash() != null ? getHash().hashCode() : 0; result = 31 * result + (getNonceRaw() != null ? getNonceRaw().hashCode() : 0); result = 31 * result + (getBlockHash() != null ? getBlockHash().hashCode() : 0); result = 31 * result + (getBlockNumberRaw() != null ? getBlockNumberRaw().hashCode() : 0); result = 31 * result + (getTransactionIndexRaw() != null ? getTransactionIndexRaw().hashCode() : 0); result = 31 * result + (getFrom() != null ? getFrom().hashCode() : 0); result = 31 * result + (getTo() != null ? getTo().hashCode() : 0); result = 31 * result + (getValueRaw() != null ? getValueRaw().hashCode() : 0); result = 31 * result + (getGasPriceRaw() != null ? getGasPriceRaw().hashCode() : 0); result = 31 * result + (getGasRaw() != null ? getGasRaw().hashCode() : 0); result = 31 * result + (getInput() != null ? getInput().hashCode() : 0); result = 31 * result + (getCreates() != null ? getCreates().hashCode() : 0); result = 31 * result + (getPublicKey() != null ? getPublicKey().hashCode() : 0); result = 31 * result + (getRaw() != null ? getRaw().hashCode() : 0); result = 31 * result + (getR() != null ? getR().hashCode() : 0); result = 31 * result + (getS() != null ? getS().hashCode() : 0); result = 31 * result + BigInteger.valueOf(getV()).hashCode(); return result; } }
private static void newTransactionFilter(Web3j web3j) { Subscription subscription = web3j. transactionObservable(). subscribe(transaction -> { System.out.println("transaction come in"); System.out.println("transaction txHash " + transaction.getHash()); }); }
@Override public String getTransactionId() throws MissingTransactionInformationException { try { String id = web3jTransaction.getHash(); if (id == null || id.isEmpty()) throw new NoSuchElementException(); return id; } catch (Exception e) { throw new MissingTransactionInformationException("Couldn't fetch transaction id.", e); } }
private static void catchUpFilter(Web3j web3j) { BigInteger startBlock = BigInteger.valueOf(2000000); /** * 遍历旧区块,监听新区块 */ Subscription subscription = web3j.catchUpToLatestAndSubscribeToNewBlocksObservable( DefaultBlockParameter.valueOf(startBlock), false) .subscribe(block -> { System.out.println("block"); System.out.println(block.getBlock().getNumber()); }); /** * 遍历旧交易,监听新交易 */ Subscription subscription2 = web3j.catchUpToLatestAndSubscribeToNewTransactionsObservable( DefaultBlockParameter.valueOf(startBlock)) .subscribe(tx -> { System.out.println("transaction"); System.out.println(tx.getHash()); }); } }
private static void replayFilter(Web3j web3j) { BigInteger startBlock = BigInteger.valueOf(2000000); BigInteger endBlock = BigInteger.valueOf(2010000); /** * 遍历旧区块 */ Subscription subscription = web3j. replayBlocksObservable( DefaultBlockParameter.valueOf(startBlock), DefaultBlockParameter.valueOf(endBlock), false). subscribe(ethBlock -> { System.out.println("replay block"); System.out.println(ethBlock.getBlock().getNumber()); }); /** * 遍历旧交易 */ Subscription subscription1 = web3j. replayTransactionsObservable( DefaultBlockParameter.valueOf(startBlock), DefaultBlockParameter.valueOf(endBlock)). subscribe(transaction -> { System.out.println("replay transaction"); System.out.println("txHash " + transaction.getHash()); }); }
public static Transaction fromEthTransaction(EthTransaction ethTransaction, Status status) { org.web3j.protocol.core.methods.response.Transaction transaction = ethTransaction.getTransaction(); String hash = transaction.getHash(); String from = transaction.getFrom(); String input = ethTransaction.getTransaction() .getInput(); String to = extractToFromEthTransaction(input); String value = extractValueFromEthTransaction(input); String contractAddress = ethTransaction.getTransaction() .getTo(); return new Transaction(hash, from, to, value, status); }