mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-11 17:55:53 +00:00
Add Wallet.reset() to prepare the wallet for a blockchain replay.
This commit is contained in:
parent
e77089f739
commit
4d3297d334
@ -2474,6 +2474,25 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the wallet for a blockchain replay. Removes all transactions (as they would get in the way of the
|
||||
* replay) and makes the wallet think it has never seen a block. {@link WalletEventListener#onWalletChanged()} will
|
||||
* be fired.
|
||||
*/
|
||||
public void reset() {
|
||||
lock.lock();
|
||||
try {
|
||||
clearTransactions();
|
||||
lastBlockSeenHash = null;
|
||||
lastBlockSeenHeight = -1; // Magic value for 'never'.
|
||||
lastBlockSeenTimeSecs = 0;
|
||||
saveLater();
|
||||
maybeQueueOnWalletChanged();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes transactions which appeared above the given block height from the wallet, but does not touch the keys.
|
||||
* This is useful if you have some keys and wish to replay the block chain into the wallet in order to pick them up.
|
||||
@ -2483,11 +2502,7 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
||||
lock.lock();
|
||||
try {
|
||||
if (fromHeight == 0) {
|
||||
unspent.clear();
|
||||
spent.clear();
|
||||
pending.clear();
|
||||
dead.clear();
|
||||
transactions.clear();
|
||||
clearTransactions();
|
||||
saveLater();
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
@ -2497,6 +2512,14 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
||||
}
|
||||
}
|
||||
|
||||
private void clearTransactions() {
|
||||
unspent.clear();
|
||||
spent.clear();
|
||||
pending.clear();
|
||||
dead.clear();
|
||||
transactions.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the outputs that match addresses or scripts added via {@link #addWatchedAddress(Address)} or
|
||||
* {@link #addWatchedScripts(java.util.List)}.
|
||||
|
@ -107,7 +107,8 @@ public interface WalletEventListener extends KeyChainEventListener {
|
||||
* <li>A pending transaction changes confidence due to some non-new-block related event, such as being
|
||||
* announced by more peers or by a double-spend conflict being observed.</li>
|
||||
* <li>A re-organize occurs. Call occurs only if the re-org modified any of our transactions.</li>
|
||||
* <li>A new spend is committed to the wallet</li>
|
||||
* <li>A new spend is committed to the wallet.</li>
|
||||
* <li>The wallet is reset and all transactions removed.<li>
|
||||
* </ol>
|
||||
*
|
||||
* <p>When this is called you can refresh the UI contents from the wallet contents. It's more efficient to use
|
||||
|
Loading…
x
Reference in New Issue
Block a user