Pages:
Author

Topic: How to watch confirmations on set of transactions? (Read 4919 times)

jr. member
Activity: 59
Merit: 10
Curious to know how programs like this (block explorers, watchers) handle re-orgs.   What is the process to discover a block has been replaced?  Seems possible # of confirmations on a TX could be decreased in same cases which would invalidate those types of notifications.
legendary
Activity: 1001
Merit: 1005
With bitcoinj you can use a depth future. Something like the following would work (not compiled or testing, just typed from memory):

Code:

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 future = tx.getConfidence().getDepthFuture(4);
        Futures.addCallback(future, new FutureCallback() {
            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 Smiley
member
Activity: 118
Merit: 10
Just out of interest, are there any Lisp people out there that would want to work on this site... maybe to make it open source...

http://donebit.com

- anyone that works on it could receive some equity in it.
full member
Activity: 196
Merit: 100
Works thank you
legendary
Activity: 1974
Merit: 1030
Quote from: dserrano5

Read about the -walletnotify parameter to bitcoind.

When installed in ubuntu doesnot show that

It's not an RPC command, but a command line parameter that is to be used when you first run bitcoind. So shutdown bitcoind and run:

Code:
bitcoind --help

To see that it's actually there. Then run:

Code:
bitcoind -walletnotify='some command here' &

To enjoy the action Wink.
full member
Activity: 196
Merit: 100
Quote from: dserrano5

Read about the -walletnotify parameter to bitcoind.

When installed in ubuntu doesnot show that
member
Activity: 118
Merit: 10
Bitcoind is informing a Lisp program of new blocks and the blockchain is stored using an indexed postgresql database for specific lookups (it's much faster to do it that way.) Then there's user and notification functionality on top of that. I didn't code it. I have some other ideas, but was wondering if anyone has any feature requests.
legendary
Activity: 1974
Merit: 1030
bitcoin-qt has a pop up window in the gui, is it really that big a stretch to get bitcoind to be able to run(or just trigger) a 3rd party script for notification when it receives a payment?

Read about the -walletnotify parameter to bitcoind.
newbie
Activity: 46
Merit: 0
bitcoin-qt has a pop up window in the gui, is it really that big a stretch to get bitcoind to be able to run(or just trigger) a 3rd party script for notification when it receives a payment?

member
Activity: 118
Merit: 10
We've finally got something up. -- http://donebit.com

The site gives information on any transaction or any address, with ability to setup email notifications on transactions (regarding confirmations) and addresses (regarding input and outputs according to certain triggers.)

Check it out.









Would be happy to hear feedback or answer questions.
member
Activity: 118
Merit: 10
A London-based hacker has been working on this site idea with me, to my delight, and we'll have something up in the next week that will alert on confirmations, with some other lookup goodies in the pipeline.
legendary
Activity: 1526
Merit: 1134
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.
member
Activity: 118
Merit: 10
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.
legendary
Activity: 1526
Merit: 1134
With bitcoinj you can use a depth future. Something like the following would work (not compiled or testing, just typed from memory):

Code:

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 future = tx.getConfidence().getDepthFuture(4);
        Futures.addCallback(future, new FutureCallback() {
            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.
member
Activity: 118
Merit: 10
Yeah, I found this Lua script that uses twilio and mailgun that is used to curl to alert via email, sms, or phone when something completes.

http://gist.github.com/jnankin/6089984
member
Activity: 91
Merit: 10
HI there, I am interested in building a web page that watches a set of transactions and their number of confirmations as they rise. As a novice developer, what's the best and/or easiest way to do this? I checked http://blockchain.info/api/blockchain_api and confirmed transactions doesn't appear part of their api for Single transaction. How could I get the necessary data  realtime?

cheers.

[block_height acquired via http://blockchain.info/latestblock] minus [block_height of ur transaction] plus 1

The way I do it is.. using http://blockchain.info/api/api_websocket api, I subscribe to new blocks. Every time a block is found, I store the block height from the JSON payload that is sent back (as a key in redis). I store my 0-confirmation transaction indexes (which I again fetch from blockchain: http://blockchain.info/rawtx/$tx_hash) in a collection (pending_transactions) in mongodb. The JSON payload for a new block contains a list of transaction indexes (block.x.txIndexes) which I match against the ones stored in my mongodb collection (and increment their confirmation count by 1). I also increment confirmation counts of all those transactions(excluding the txIndexes sent in the payload) that already have 1 confirmation (note: I don't increment 0 confirmations). When it hits 6 confirmations, I move the transaction from pending_transactions collection to confirmed_transactions collection.

The reason I do all this nonsense is that sometimes 0 confirmation transactions never get included in the new blocks (ex: when you send with 0 fee). So doing a latest_block_height - block_height_of_transaction + 1 may not work for such edge cases.

Also there are times where your server might crash due to unknown bugs. When the server reboots, I fetch all blocks from where I left off (use the last stored block height in redis and then fetch block heights from blockchain. Example: http://blockchain.info/block-height/246536?format=json) and catch-up to the latest block (and repeat the whole process again).

This is temporary though. My future plan is to write my own client with these features (esp notifications on confirmations; it sucks that there is no API to subscribe for notifications) or fork the bitcoin client and make these necessary changes.
member
Activity: 118
Merit: 10
Cheers. I just found this:

"Bitcoin blockchain in a MongoDB database to allow querying of block and transaction data.. In order to use bitcoinquery you need a Bitcoind RPC server. "

http://github.com/thelinuxkid/bitcoinquery

Long term, probably better to move away from third party APIs if opening to outside users.
legendary
Activity: 3710
Merit: 1586
See here:

http://blockchain.info/q/

See under address lookups

Also in future if you ever find yourself wondering how to do something bitcoin related go through the ENTIRE page below:

http://blockchain.info/api/

Blockchain.info has half a dozen different APIs and it is easy to miss a few.
legendary
Activity: 2142
Merit: 1010
Newbie
But I can also get block height from http://blockchain.info/api/api_websocket -- "Receive notifications when a new block is found."?

.. better than polling for latestblock.

It's better to keep things simple. I would poll the latest block each 10 sec.
member
Activity: 118
Merit: 10
[block_height acquired via http://blockchain.info/latestblock] minus [block_height of ur transaction] plus 1

cheers. block_height of transaction I can grab from http://blockchain.info/rawtx/43384a79232a8844f9ec1f5149ed2aa7d7800f6197d194b02c948785e795d6c9

But I can also get block height from http://blockchain.info/api/api_websocket -- "Receive notifications when a new block is found."?

.. better than polling for latestblock.

After that, I wipe the sweat from my brow.
Pages:
Jump to: