3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-16 04:05:50 +00:00

Wallet.addWatchedScripts() now lets you update a script in the wallet with a new creation time. Add some discussion to the Javadoc about this issue.

This commit is contained in:
Mike Hearn 2015-04-21 14:56:18 +02:00
parent 4471709693
commit 70b78363ea

View File

@ -812,8 +812,11 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
} }
/** /**
* Adds the given output scripts to the wallet to be watched. Outputs can be retrieved * Adds the given output scripts to the wallet to be watched. Outputs can be retrieved by {@link #getWatchedOutputs(boolean)}.
* by {@link #getWatchedOutputs(boolean)}. * If a script is already being watched, the object is replaced with the one in the given list. As {@link Script}
* equality is defined in terms of program bytes only this lets you update metadata such as creation time. Note that
* you should be careful not to add scripts with a creation time of zero (the default!) because otherwise it will
* disable the important wallet checkpointing optimisation.
* *
* @return how many scripts were added successfully * @return how many scripts were added successfully
*/ */
@ -822,7 +825,10 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
keychainLock.lock(); keychainLock.lock();
try { try {
for (final Script script : scripts) { for (final Script script : scripts) {
if (watchedScripts.contains(script)) continue; // Script.equals/hashCode() only takes into account the program bytes, so this step lets the user replace
// a script in the wallet with an incorrect creation time.
if (watchedScripts.contains(script))
watchedScripts.remove(script);
if (script.getCreationTimeSeconds() == 0) if (script.getCreationTimeSeconds() == 0)
log.warn("Adding a script to the wallet with a creation time of zero, this will disable the checkpointing optimization! {}", script); log.warn("Adding a script to the wallet with a creation time of zero, this will disable the checkpointing optimization! {}", script);
watchedScripts.add(script); watchedScripts.add(script);