Skip to content
This repository has been archived by the owner on Apr 20, 2020. It is now read-only.

Commit

Permalink
#21: Actually call onBalanceChanged.
Browse files Browse the repository at this point in the history
  • Loading branch information
nschum committed Feb 1, 2014
1 parent b17ae79 commit a047eb4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
7 changes: 5 additions & 2 deletions BitcoinJKit/HIBitcoinManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ - (id)init

_balanceChecker = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(checkBalance:)
selector:@selector(verifyBalance:)
userInfo:nil
repeats:YES];

Expand Down Expand Up @@ -857,15 +857,18 @@ - (uint64_t)estimatedBalance
return [self callLongMethodWithName:"getEstimatedBalance" signature:"()J"];
}

- (void)checkBalance:(NSTimer *)timer
- (void)verifyBalance:(NSTimer *)timer
{
// This shouldn't be necessary, but let's check if we missed anything.
if (self.availableBalance != _lastAvailableBalance)
{
HILogError(@"BitcoinKit missed a change notification. This is a bug.");
[self onAvailableBalanceChanged];
}

if (self.estimatedBalance != _lastEstimatedBalance)
{
HILogError(@"BitcoinKit missed a change notification. This is a bug.");
[self onEstimatedBalanceChanged];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.google.bitcoin.crypto.KeyCrypterScrypt;
import com.google.bitcoin.net.discovery.DnsDiscovery;
import com.google.bitcoin.params.MainNetParams;
import com.google.bitcoin.params.RegTestParams;
import com.google.bitcoin.params.TestNet3Params;
import com.google.bitcoin.script.Script;
import com.google.bitcoin.store.BlockStore;
Expand All @@ -28,7 +27,6 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.nio.CharBuffer;
import java.text.SimpleDateFormat;
import java.util.Arrays;
Expand Down Expand Up @@ -198,13 +196,28 @@ private void useWallet(Wallet wallet) throws BlockStoreException, IOException
public void onCoinsReceived(Wallet w, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
{
BitcoinManager.this.onCoinsReceived(w, tx, prevBalance, newBalance);
BitcoinManager.this.onBalanceChanged();
}

// get notified when we send a transaction, or when we restore an outgoing transaction from the blockchain
@Override
public void onCoinsSent(Wallet w, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
{
BitcoinManager.this.onCoinsSent(w, tx, prevBalance, newBalance);
BitcoinManager.this.onBalanceChanged();
}

@Override
public void onReorganize(Wallet wallet)
{
BitcoinManager.this.onBalanceChanged();
}

@Override
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
{
super.onTransactionConfidenceChanged(wallet, tx);
BitcoinManager.this.onBalanceChanged();

This comment has been minimized.

Copy link
@mackuba

mackuba Feb 10, 2014

Member

Bad idea, this is called for every transaction in the wallet every time there's a new block... the interesting transactions are tracked separately, directly through the transaction, not through the wallet. Fixed here: 34c3f81

}
});

Expand Down Expand Up @@ -745,7 +758,7 @@ public String getExceptionStackTrace(Throwable exception)
public void updateLastWalletChange(Wallet wallet)
{
LastWalletChangeExtension ext =
(LastWalletChangeExtension) wallet.getExtensions().get(LastWalletChangeExtension.EXTENSION_ID);
(LastWalletChangeExtension) wallet.getExtensions().get(LastWalletChangeExtension.EXTENSION_ID);

ext.setLastWalletChangeDate(new Date());
}
Expand All @@ -758,7 +771,7 @@ public Date getLastWalletChange()
}

LastWalletChangeExtension ext =
(LastWalletChangeExtension) wallet.getExtensions().get(LastWalletChangeExtension.EXTENSION_ID);
(LastWalletChangeExtension) wallet.getExtensions().get(LastWalletChangeExtension.EXTENSION_ID);

return ext.getLastWalletChangeDate();
}
Expand Down

0 comments on commit a047eb4

Please sign in to comment.