public class NativeWalletEventListener extends Object implements WalletEventListener
Modifier and Type | Field and Description |
---|---|
long |
ptr |
Constructor and Description |
---|
NativeWalletEventListener() |
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 |
onKeysAdded(List<ECKey> keys)
Called whenever a new key is added to the key chain, whether that be via an explicit addition or due to some
other automatic derivation.
|
void |
onReorganize(Wallet wallet)
This is called when a block is received that triggers a block chain re-organization.
|
void |
onScriptsChanged(Wallet wallet,
List<Script> scripts,
boolean isAddingScripts)
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.
|
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
WalletCoinsReceivedEventListener
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.onCoinsReceived
in interface WalletCoinsReceivedEventListener
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.public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
WalletCoinsSentEventListener
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.
onCoinsSent
in interface WalletCoinsSentEventListener
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.public void onReorganize(Wallet wallet)
WalletReorganizeEventListener
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.
onReorganize
in interface WalletReorganizeEventListener
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
TransactionConfidenceEventListener
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.
onTransactionConfidenceChanged
in interface TransactionConfidenceEventListener
public void onWalletChanged(Wallet wallet)
WalletChangeEventListener
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.
onWalletChanged
in interface WalletChangeEventListener
public void onKeysAdded(List<ECKey> keys)
KeyChainEventListener
KeyChain
implementation for details on what
can trigger this event.onKeysAdded
in interface KeyChainEventListener
public void onScriptsChanged(Wallet wallet, List<Script> scripts, boolean isAddingScripts)
ScriptsChangeEventListener
onScriptsChanged
in interface ScriptsChangeEventListener
isAddingScripts
- will be true if added scripts, false if removed scripts.Copyright © 2016. All rights reserved.