diff --git a/core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelClientState.java b/core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelClientState.java index e394a083..58d38a91 100644 --- a/core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelClientState.java +++ b/core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelClientState.java @@ -216,7 +216,6 @@ public class PaymentChannelClientState { StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates) wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID); channels.removeChannel(storedChannel); - wallet.addOrUpdateExtension(channels); storedChannel = null; } @@ -450,7 +449,7 @@ public class PaymentChannelClientState { storedChannel.valueToMe = valueToMe; StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates) wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID); - wallet.addOrUpdateExtension(channels); + channels.updatedChannel(storedChannel); } /** @@ -486,7 +485,6 @@ public class PaymentChannelClientState { checkState(channels.getChannel(id, multisigContract.getHash()) == null); storedChannel = new StoredClientChannel(id, multisigContract, refundTx, myKey, valueToMe, refundFees, true); channels.putChannel(storedChannel); - wallet.addOrUpdateExtension(channels); } /** diff --git a/core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelServerState.java b/core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelServerState.java index 783590e8..8f745bb0 100644 --- a/core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelServerState.java +++ b/core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelServerState.java @@ -473,7 +473,7 @@ public class PaymentChannelServerState { storedServerChannel.updateValueToMe(bestValueToMe, bestValueSignature); StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates) wallet.getExtensions().get(StoredPaymentChannelServerStates.EXTENSION_ID); - wallet.addOrUpdateExtension(channels); + channels.updatedChannel(storedServerChannel); } } @@ -500,6 +500,5 @@ public class PaymentChannelServerState { if (connectedHandler != null) checkState(storedServerChannel.setConnectedHandler(connectedHandler, false) == connectedHandler); channels.putChannel(storedServerChannel); - wallet.addOrUpdateExtension(channels); } } diff --git a/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelClientStates.java b/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelClientStates.java index ad5d9329..94b9b6fb 100644 --- a/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelClientStates.java +++ b/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelClientStates.java @@ -179,6 +179,15 @@ public class StoredPaymentChannelClientStates implements WalletExtension { } } + /** + * Notifies the set of stored states that a channel has been updated. Use to notify the wallet of an update to this + * wallet extension. + */ + void updatedChannel(final StoredClientChannel channel) { + log.info("Stored client channel {} was updated", channel.hashCode()); + containingWallet.addOrUpdateExtension(this); + } + /** * Adds the given channel to this set of stored states, broadcasting the contract and refund transactions when the * channel expires and notifies the wallet of an update to this wallet extension @@ -206,7 +215,7 @@ public class StoredPaymentChannelClientStates implements WalletExtension { lock.unlock(); } if (updateWallet) - containingWallet.addOrUpdateExtension(this); + updatedChannel(channel); } /** @@ -242,7 +251,7 @@ public class StoredPaymentChannelClientStates implements WalletExtension { } finally { lock.unlock(); } - containingWallet.addOrUpdateExtension(this); + updatedChannel(channel); } @Override diff --git a/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelServerStates.java b/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelServerStates.java index 1005d0b2..9d46c5ad 100644 --- a/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelServerStates.java +++ b/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelServerStates.java @@ -116,7 +116,7 @@ public class StoredPaymentChannelServerStates implements WalletExtension { } channel.state = null; } - wallet.addOrUpdateExtension(this); + updatedChannel(channel); } /** @@ -149,6 +149,15 @@ public class StoredPaymentChannelServerStates implements WalletExtension { } } + /** + * Notifies the set of stored states that a channel has been updated. Use to notify the wallet of an update to this + * wallet extension. + */ + public void updatedChannel(final StoredServerChannel channel) { + log.info("Stored server channel {} was updated", channel.hashCode()); + wallet.addOrUpdateExtension(this); + } + /** *

Puts the given channel in the channels map and automatically closes it 2 hours before its refund transaction * becomes spendable.

@@ -174,6 +183,7 @@ public class StoredPaymentChannelServerStates implements WalletExtension { } finally { lock.unlock(); } + updatedChannel(channel); } @Override