/** * <p>Adds an event listener that will be run when this confidence object is updated. The listener will be locked and * is likely to be invoked on a peer thread.</p> * * <p>Note that this is NOT called when every block arrives. Instead it is called when the transaction * transitions between confidence states, ie, from not being seen in the chain to being seen (not necessarily in * the best chain). If you want to know when the transaction gets buried under another block, implement a * {@link BlockChainListener}, attach it to a {@link BlockChain} and then use the getters on the * confidence object to determine the new depth.</p> */ public void addEventListener(Listener listener) { addEventListener(Threading.USER_THREAD, listener); }
/** * <p>Adds an event listener that will be run when this confidence object is updated. The listener will be locked and * is likely to be invoked on a peer thread.</p> * * <p>Note that this is NOT called when every block arrives. Instead it is called when the transaction * transitions between confidence states, ie, from not being seen in the chain to being seen (not necessarily in * the best chain). If you want to know when the transaction gets buried under another block, implement a * {@link BlockChainListener}, attach it to a {@link BlockChain} and then use the getters on the * confidence object to determine the new depth.</p> */ public void addEventListener(Listener listener) { addEventListener(Threading.USER_THREAD, listener); }
/** * <p>Adds an event listener that will be run when this confidence object is updated. The listener will be locked and * is likely to be invoked on a peer thread.</p> * * <p>Note that this is NOT called when every block arrives. Instead it is called when the transaction * transitions between confidence states, ie, from not being seen in the chain to being seen (not necessarily in * the best chain). If you want to know when the transaction gets buried under another block, implement a * {@link BlockChainListener}, attach it to a {@link BlockChain} and then use the getters on the * confidence object to determine the new depth.</p> */ public void addEventListener(Listener listener) { addEventListener(Threading.USER_THREAD, listener); }
/** * <p>Adds an event listener that will be run when this confidence object is updated. The listener will be locked and * is likely to be invoked on a peer thread.</p> * * <p>Note that this is NOT called when every block arrives. Instead it is called when the transaction * transitions between confidence states, ie, from not being seen in the chain to being seen (not necessarily in * the best chain). If you want to know when the transaction gets buried under another block, implement a * {@link BlockChainListener}, attach it to a {@link BlockChain} and then use the getters on the * confidence object to determine the new depth.</p> */ public void addEventListener(Listener listener) { addEventListener(Threading.USER_THREAD, listener); }
/** * Returns a future that completes when the transaction has been confirmed by "depth" blocks. For instance setting * depth to one will wait until it appears in a block on the best chain, and zero will wait until it has been seen * on the network. */ public synchronized ListenableFuture<TransactionConfidence> getDepthFuture(final int depth, Executor executor) { final SettableFuture<TransactionConfidence> result = SettableFuture.create(); if (getDepthInBlocks() >= depth) { result.set(this); } addEventListener(executor, new Listener() { @Override public void onConfidenceChanged(TransactionConfidence confidence, ChangeReason reason) { if (getDepthInBlocks() >= depth) { removeEventListener(this); result.set(confidence); } } }); return result; }
/** * Returns a future that completes when the transaction has been confirmed by "depth" blocks. For instance setting * depth to one will wait until it appears in a block on the best chain, and zero will wait until it has been seen * on the network. */ public synchronized ListenableFuture<TransactionConfidence> getDepthFuture(final int depth, Executor executor) { final SettableFuture<TransactionConfidence> result = SettableFuture.create(); if (getDepthInBlocks() >= depth) { result.set(this); } addEventListener(executor, new Listener() { @Override public void onConfidenceChanged(TransactionConfidence confidence, ChangeReason reason) { if (getDepthInBlocks() >= depth) { removeEventListener(this); result.set(confidence); } } }); return result; }
/** * Returns a future that completes when the transaction has been confirmed by "depth" blocks. For instance setting * depth to one will wait until it appears in a block on the best chain, and zero will wait until it has been seen * on the network. */ public synchronized ListenableFuture<TransactionConfidence> getDepthFuture(final int depth, Executor executor) { final SettableFuture<TransactionConfidence> result = SettableFuture.create(); if (getDepthInBlocks() >= depth) { result.set(this); } addEventListener(executor, new Listener() { @Override public void onConfidenceChanged(TransactionConfidence confidence, ChangeReason reason) { if (getDepthInBlocks() >= depth) { removeEventListener(this); result.set(confidence); } } }); return result; }
/** * Returns a future that completes when the transaction has been confirmed by "depth" blocks. For instance setting * depth to one will wait until it appears in a block on the best chain, and zero will wait until it has been seen * on the network. */ public synchronized ListenableFuture<TransactionConfidence> getDepthFuture(final int depth, Executor executor) { final SettableFuture<TransactionConfidence> result = SettableFuture.create(); if (getDepthInBlocks() >= depth) { result.set(this); } addEventListener(executor, new Listener() { @Override public void onConfidenceChanged(TransactionConfidence confidence, ChangeReason reason) { if (getDepthInBlocks() >= depth) { removeEventListener(this); result.set(confidence); } } }); return result; }
private void trackTransactionForStatusChanges(BitcoinTransactionAdapter tx) { tx.getBitcoinjTransaction().getConfidence().addEventListener( new TransactionConfidence.Listener() { @Override public void onConfidenceChanged(TransactionConfidence confidence, ChangeReason reason) { if (reason.equals(ChangeReason.TYPE)) { if (confidence.getConfidenceType().equals(ConfidenceType.PENDING)) { processPendingTransactions(tx); // Continue tracking the transaction. } else if (confidence.getConfidenceType().equals(ConfidenceType.BUILDING)) { processBuildingTransaction(tx); // Continue tracking the transaction for confirmation. } else if (confidence.getConfidenceType().equals(DEAD)) { // Stop tracking the transaction. tx.getBitcoinjTransaction().getConfidence().removeEventListener(this); } } else if (reason.equals(ChangeReason.DEPTH)) { if (confidence.getDepthInBlocks() >= configHolder.getBitcoinConfirmationBlockdepth()) { confirmTransaction(tx); tx.getBitcoinjTransaction().getConfidence().removeEventListener(this); } } } }); }
tx.getConfidence().addEventListener(new ConfidenceChange());
tx.getConfidence().addEventListener(new ConfidenceChange());
tx.getConfidence().addEventListener(Threading.SAME_THREAD, txConfidenceListener);
tx.getConfidence().addEventListener(Threading.SAME_THREAD, txConfidenceListener);
tx.getConfidence().addEventListener(Threading.SAME_THREAD, txConfidenceListener);
tx.getConfidence().addEventListener(Threading.SAME_THREAD, txConfidenceListener);
tx.getConfidence().addEventListener(new ConfidenceChange());
tx.getConfidence().addEventListener(new ConfidenceChange());
@Test public void events() throws Exception { final TransactionConfidence.Listener.ChangeReason[] run = new TransactionConfidence.Listener.ChangeReason[1]; tx1.getConfidence().addEventListener(Threading.SAME_THREAD, new TransactionConfidence.Listener() { @Override public void onConfidenceChanged(TransactionConfidence confidence, ChangeReason reason) { run[0] = reason; } }); table.seen(tx1.getHash(), address1); assertEquals(TransactionConfidence.Listener.ChangeReason.SEEN_PEERS, run[0]); run[0] = null; table.seen(tx1.getHash(), address1); assertNull(run[0]); }
@Test public void pinHandlers() throws Exception { Transaction tx = PARAMS.getDefaultSerializer().makeTransaction(tx1.bitcoinSerialize()); Sha256Hash hash = tx.getHash(); table.seen(hash, address1); assertEquals(1, tx.getConfidence().numBroadcastPeers()); final int[] seen = new int[1]; tx.getConfidence().addEventListener(Threading.SAME_THREAD, new TransactionConfidence.Listener() { @Override public void onConfidenceChanged(TransactionConfidence confidence, ChangeReason reason) { seen[0] = confidence.numBroadcastPeers(); } }); tx = null; System.gc(); table.seen(hash, address2); assertEquals(2, seen[0]); }
send2.getConfidence().addEventListener(Threading.SAME_THREAD, listener); send3.getConfidence().addEventListener(Threading.SAME_THREAD, listener);