Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: adrian33 on July 26, 2013, 10:58:33 AM



Title: How to watch confirmations on set of transactions?
Post by: adrian33 on July 26, 2013, 10:58:33 AM
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 (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.


Title: Re: How to watch confirmations on set of transactions?
Post by: Mike Hearn on July 26, 2013, 05:33:39 PM
You can do this with bitcoinj if you are OK with Java.


Title: Re: How to watch confirmations on set of transactions?
Post by: piotr_n on July 26, 2013, 07:37:53 PM
I just wonder, why do you even need it?
Watching a set of transactions and their number of confirmations as they rise - seems pretty crazy for me ;)


Title: Re: How to watch confirmations on set of transactions?
Post by: piotr_n on July 26, 2013, 07:49:06 PM
I mean, I dont want to be mean, but if you explain you application maybe we could explain you better.


Title: Re: How to watch confirmations on set of transactions?
Post by: adrian33 on July 26, 2013, 11:03:29 PM
I just wonder, why do you even need it?
Watching a set of transactions and their number of confirmations as they rise - seems pretty crazy for me ;)

Thanks for responses.

I just want to know when a few transactions I will make have hit 4 confirmations. Can I do that with bitcoinj on transactions where I don't hold any keys... totally independent of me? Or rather, I don't want to link the web app in any way to my wallet, so I make the transaction, and then close my wallet app... but tell the confirmation app the transaction address(es) to track for subsequent confirmations.

I skimmed the documentation.. but not sure if I can do that with bitcoinj.


Title: Re: How to watch confirmations on set of transactions?
Post by: piotr_n on July 26, 2013, 11:13:53 PM
I just want to know when a few transactions I will make have hit 4 confirmations/
So you basically want to send a tx, from you wallet, and then get some alatm clock tiggered, when it reaches 4 confiscation.
How much secured you need to have ii?
If not, I belvbe any block explorer would ro.


Title: Re: How to watch confirmations on set of transactions?
Post by: adrian33 on July 26, 2013, 11:21:05 PM
I just want to know when a few transactions I will make have hit 4 confirmations/
So you basically want to send a tx, from you wallet, and then get some alatm clock tiggered, when it reaches 4 confiscation.
How much secured you need to have ii?
If not, I belvbe any block explorer would ro.

Thanks what's the easiest or fastest way to build my own block explorer.. or can bitcoinj do what is required if it knows the transactions to watch.. or does it require keys of some sort?


Title: Re: How to watch confirmations on set of transactions?
Post by: Come-from-Beyond on July 26, 2013, 11:25:08 PM
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


Title: Re: How to watch confirmations on set of transactions?
Post by: piotr_n on July 26, 2013, 11:25:38 PM
I just want to know when a few transactions I will make have hit 4 confirmations/
So you basically want to send a tx, from you wallet, and then get some alatm clock tiggered, when it reaches 4 confiscation.
How much secured you need to have ii?
If not, I belvbe any block explorer would ro.

Thanks what's the easiest or fastest way to build my own block explorer.. or can bitcoinj do what is required if it knows the transactions to watch.. or does it require keys of some sort?
So what are you going to do, after the alarm clock triggers the 4th confirmation?


Title: Re: How to watch confirmations on set of transactions?
Post by: adrian33 on July 26, 2013, 11:45:56 PM
[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.


Title: Re: How to watch confirmations on set of transactions?
Post by: Come-from-Beyond on July 27, 2013, 02:07:40 PM
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.


Title: Re: How to watch confirmations on set of transactions?
Post by: Abdussamad on July 27, 2013, 02:41:47 PM
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.


Title: Re: How to watch confirmations on set of transactions?
Post by: adrian33 on July 28, 2013, 12:47:37 PM
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.


Title: Re: How to watch confirmations on set of transactions?
Post by: assortmentofsorts on July 28, 2013, 02:21:16 PM
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.


Title: Re: How to watch confirmations on set of transactions?
Post by: adrian33 on July 28, 2013, 03:29:17 PM
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


Title: Re: How to watch confirmations on set of transactions?
Post by: Mike Hearn on July 29, 2013, 12:45:06 PM
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<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.


Title: Re: How to watch confirmations on set of transactions?
Post by: adrian33 on July 29, 2013, 01:06:47 PM
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.


Title: Re: How to watch confirmations on set of transactions?
Post by: Mike Hearn on July 29, 2013, 02:28:42 PM
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.


Title: Re: How to watch confirmations on set of transactions?
Post by: adrian33 on August 08, 2013, 02:46:52 PM
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.


Title: Re: How to watch confirmations on set of transactions?
Post by: adrian33 on September 21, 2013, 05:07:50 PM
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.


http://hackerbra.in/1.png

http://hackerbra.in/2.png

http://hackerbra.in/3.png


Would be happy to hear feedback or answer questions.


Title: Re: How to watch confirmations on set of transactions?
Post by: BitvoinVender on September 21, 2013, 07:07:52 PM
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?



Title: Re: How to watch confirmations on set of transactions?
Post by: dserrano5 on September 21, 2013, 07:12:15 PM
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.


Title: Re: How to watch confirmations on set of transactions?
Post by: adrian33 on September 22, 2013, 07:10:00 AM
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.


Title: Re: How to watch confirmations on set of transactions?
Post by: Eternity on September 23, 2013, 11:53:58 AM
Quote from: dserrano5

Read about the -walletnotify parameter to bitcoind.

When installed in ubuntu doesnot show that


Title: Re: How to watch confirmations on set of transactions?
Post by: dserrano5 on September 23, 2013, 12:28:48 PM
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 ;).


Title: Re: How to watch confirmations on set of transactions?
Post by: Eternity on September 24, 2013, 07:10:00 AM
Works thank you


Title: Re: How to watch confirmations on set of transactions?
Post by: adrian33 on November 23, 2013, 06:06:50 PM
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.


Title: Re: How to watch confirmations on set of transactions?
Post by: Amitabh S on January 14, 2015, 08:23:00 PM
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<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 :)


Title: Re: How to watch confirmations on set of transactions?
Post by: oldbute on January 15, 2015, 01:25:40 AM
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.