With bitcoinj you can use a depth future. Something like the following would work (not compiled or testing, just typed from memory):
byte[] pubkeybytes = ....;
Wallet wallet = new Wallet(params);
wallet.addKey(new ECKey(null, pubkeybytes));
... (insert usual boilerplate setup here) ...
wallet.addEventListener(new AbstractWalletEventListener() {
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance) {
// Transaction was received. Get a callback when 4 confirmations have occurred.
ListenableFuture<Transaction> future = tx.getConfidence().getDepthFuture(4);
Futures.addCallback(future, new FutureCallback<Transaction>() {
public void onSuccess(Transaction tx) {
System.out.println("Transaction " + tx + " now has 4 confirmations - party time!!");
}
});
}
});
The syntax is a bit verbose - languages like Java 8 or Kotlin have some features to make it more fluid, if you don't mind what language you use. Also, if your app restarts, you'll have to re-register the confidence listeners on the loaded wallet of course.
Thanks Mike - I think the key is to differentiate watching confirmations for a private wallet and watching them for a public blockchain. For my application, it's all about OPCs -- other people's confirmations, because I want to separate the new app from my wallet app. Does bitcoinj allow that?
A Confirmation Party site would be good... you could have a $20,000 confirmation party room and a $500,000 room - social networking for high rollers.
The key issue is scalability. If you want to monitor tens of thousands of keys/transactions, bitcoinj probably won't scale to what you need. If you want to monitor less than that, it might work. You could try it.
Hi Mike,
How about the ability to watch for confirmations on arbitrary addresses since the last app start. Does this exist? If not I'm thinking of the following
1. Listen for tx, assign 0 conf.
2. Keep track of blocks, and the tx inside them, incrementing the confirmations
3. As it reaches threshold, notify and remove from list
Would be great if this already exists.
BTW, Scala is also quite less verbose than Java