public interface WalletEventListener extends KeyChainEventListener
Implementors are called when the contents of the wallet changes, for instance due to receiving/sending money
or a block chain re-organize. It may be convenient to derive from AbstractWalletEventListener
instead.
Modifier and Type | Method and Description |
---|---|
void |
onCoinsReceived(Wallet wallet,
Transaction tx,
Coin prevBalance,
Coin newBalance)
This is called when a transaction is seen that sends coins to this wallet, either because it
was broadcast across the network or because a block was received.
|
void |
onCoinsSent(Wallet wallet,
Transaction tx,
Coin prevBalance,
Coin newBalance)
This is called when a transaction is seen that sends coins from this wallet, either
because it was broadcast across the network or because a block was received.
|
void |
onReorganize(Wallet wallet)
This is called when a block is received that triggers a block chain re-organization.
|
void |
onScriptsAdded(Wallet wallet,
List<Script> scripts)
Called whenever a new watched script is added to the wallet.
|
void |
onTransactionConfidenceChanged(Wallet wallet,
Transaction tx)
Called when a transaction changes its confidence level.
|
void |
onWalletChanged(Wallet wallet)
Designed for GUI applications to refresh their transaction lists.
|
onKeysAdded
void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
TransactionConfidence
event listener using
the object retrieved via Transaction.getConfidence()
. It's safe to modify the
wallet in this callback, for example, by spending the transaction just received.wallet
- The wallet object that received the coinstx
- The transaction which sent us the coins.prevBalance
- Balance before the coins were received.newBalance
- Current balance of the wallet. This is the 'estimated' balance.void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
It's safe to modify the wallet from inside this callback, but if you're replaying the block chain you should be careful to avoid such modifications. Otherwise your changes may be overridden by new data from the chain.
wallet
- The wallet object that this callback relates to (that sent the coins).tx
- The transaction that sent the coins to someone else.prevBalance
- The wallets balance before this transaction was seen.newBalance
- The wallets balance after this transaction was seen. This is the 'estimated' balance.void onReorganize(Wallet wallet)
This is called when a block is received that triggers a block chain re-organization.
A re-organize means that the consensus (chain) of the network has diverged and now changed from what we believed it was previously. Usually this won't matter because the new consensus will include all our old transactions assuming we are playing by the rules. However it's theoretically possible for our balance to change in arbitrary ways, most likely, we could lose some money we thought we had.
It is safe to use methods of wallet whilst inside this callback.
void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
Called when a transaction changes its confidence level. You can also attach event listeners to the individual transactions, if you don't care about all of them. Usually you would save the wallet to disk after receiving this callback unless you already set up autosaving.
You should pay attention to this callback in case a transaction becomes dead, that is, a transaction you believed to be active (send or receive) becomes overridden by the network. This can happen if
Wallet
will then re-use the same outputs when creating the next spend.
To find if the transaction is dead, you can use tx.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.DEAD. If it is, you should notify the user in some way so they know the thing they bought may not arrive/the thing they sold should not be dispatched.
Note that this callback will be invoked for every transaction in the wallet, for every new block that is received (because the depth has changed). If you want to update a UI view from the contents of the wallet it is more efficient to use onWalletChanged instead.
void onWalletChanged(Wallet wallet)
Designed for GUI applications to refresh their transaction lists. This callback is invoked in the following situations:
When this is called you can refresh the UI contents from the wallet contents. It's more efficient to use this rather than onTransactionConfidenceChanged() + onReorganize() because you only get one callback per block rather than one per transaction per block. Note that this is not called when a key is added.
Copyright © 2015. All rights reserved.