mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-02 05:27:17 +00:00
Remove duplicate extension update calls to the wallet.
Make the StoredPaymentChannel{Client|Server}States in charge of notifying the
wallet when the stored state has changed. Reduced the duplicate calls to update
and subsequently save the wallet to disk.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Puts the given channel in the channels map and automatically closes it 2 hours before its refund transaction
|
||||
* becomes spendable.</p>
|
||||
@@ -174,6 +183,7 @@ public class StoredPaymentChannelServerStates implements WalletExtension {
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
updatedChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user