PeerGroup: Update bloom filter also if coins were sent.
Fixes
@@ -32,6 +32,7 @@ import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.listeners.KeyChainEventListener;
import org.bitcoinj.wallet.listeners.ScriptsChangeEventListener;
import org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener;
+import org.bitcoinj.wallet.listeners.WalletCoinsSentEventListener;
import org.slf4j.*;
import javax.annotation.*;
@@ -175,6 +176,18 @@ public class PeerGroup implements TransactionBroadcaster {
private final WalletCoinsReceivedEventListener walletCoinsReceivedEventListener = new WalletCoinsReceivedEventListener() {
@Override
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
+ onCoinsReceivedOrSent(wallet, tx);
+ }
+ };
+
+ private final WalletCoinsSentEventListener walletCoinsSentEventListener = new WalletCoinsSentEventListener() {
+ @Override
+ public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
+ onCoinsReceivedOrSent(wallet, tx);
+ }
+ };
+
+ private void onCoinsReceivedOrSent(Wallet wallet, Transaction tx) {
// We received a relevant transaction. We MAY need to recalculate and resend the Bloom filter, but only
// if we have received a transaction that includes a relevant P2PK or P2WPKH output.
//
@@ -210,7 +223,6 @@ public class PeerGroup implements TransactionBroadcaster {
}
}
}
- };
// Exponential backoff for peers starts at 1 second and maxes at 10 minutes.
private final ExponentialBackoff.Params peerBackoffParams = new ExponentialBackoff.Params(1000, 1.5f, 10 * 60 * 1000);
@@ -1142,6 +1154,7 @@ public class PeerGroup implements TransactionBroadcaster {
wallets.add(wallet);
wallet.setTransactionBroadcaster(this);
wallet.addCoinsReceivedEventListener(Threading.SAME_THREAD, walletCoinsReceivedEventListener);
+ wallet.addCoinsSentEventListener(Threading.SAME_THREAD, walletCoinsSentEventListener);
wallet.addKeyChainEventListener(Threading.SAME_THREAD, walletKeyEventListener);
wallet.addScriptsChangeEventListener(Threading.SAME_THREAD, walletScriptsEventListener);
addPeerFilterProvider(wallet);
@@ -1214,6 +1227,7 @@ public class PeerGroup implements TransactionBroadcaster {
wallets.remove(checkNotNull(wallet));
peerFilterProviders.remove(wallet);
wallet.removeCoinsReceivedEventListener(walletCoinsReceivedEventListener);
+ wallet.removeCoinsSentEventListener(walletCoinsSentEventListener);
wallet.removeKeyChainEventListener(walletKeyEventListener);
wallet.removeScriptsChangeEventListener(walletScriptsEventListener);
wallet.setTransactionBroadcaster(null);
