Make WalletEventListener an interface with a no-op implementation. Add an onChange() method to the default implementation that is called by the others, for cases where you don't care about what specifically changed, just that a change happened.

This commit is contained in:
Mike Hearn
2011-09-18 20:09:26 +00:00
parent 6f36e96f66
commit bbe133be88
6 changed files with 96 additions and 40 deletions

View File

@@ -51,7 +51,7 @@ public class ChainSplitTests {
// TODO: Change this test to not use coinbase transactions as they are special (maturity rules).
final boolean[] reorgHappened = new boolean[1];
reorgHappened[0] = false;
wallet.addEventListener(new WalletEventListener() {
wallet.addEventListener(new AbstractWalletEventListener() {
@Override
public void onReorganize() {
reorgHappened[0] = true;
@@ -185,7 +185,7 @@ public class ChainSplitTests {
// double spend on the new best chain.
final boolean[] eventCalled = new boolean[1];
wallet.addEventListener(new WalletEventListener() {
wallet.addEventListener(new AbstractWalletEventListener() {
@Override
public void onDeadTransaction(Transaction deadTx, Transaction replacementTx) {
eventCalled[0] = true;
@@ -225,7 +225,7 @@ public class ChainSplitTests {
final Transaction[] eventDead = new Transaction[1];
final Transaction[] eventReplacement = new Transaction[1];
wallet.addEventListener(new WalletEventListener() {
wallet.addEventListener(new AbstractWalletEventListener() {
@Override
public void onDeadTransaction(Transaction deadTx, Transaction replacementTx) {
eventDead[0] = deadTx;

View File

@@ -101,7 +101,7 @@ public class WalletTest {
public void listeners() throws Exception {
final Transaction fakeTx = createFakeTx(params, Utils.toNanoCoins(1, 0), myAddress);
final boolean[] didRun = new boolean[1];
WalletEventListener listener = new WalletEventListener() {
WalletEventListener listener = new AbstractWalletEventListener() {
public void onCoinsReceived(Wallet w, Transaction tx, BigInteger prevBalance, BigInteger newBalance) {
assertTrue(prevBalance.equals(BigInteger.ZERO));
assertTrue(newBalance.equals(Utils.toNanoCoins(1, 0)));
@@ -249,7 +249,7 @@ public class WalletTest {
// isn't tested because today BitCoinJ only learns about such transactions when they appear in the chain.
final Transaction[] eventDead = new Transaction[1];
final Transaction[] eventReplacement = new Transaction[1];
wallet.addEventListener(new WalletEventListener() {
wallet.addEventListener(new AbstractWalletEventListener() {
@Override
public void onDeadTransaction(Transaction deadTx, Transaction replacementTx) {
eventDead[0] = deadTx;