Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: mav on June 17, 2012, 07:40:15 AM



Title: bitcoind - get no. of confirmations for an address
Post by: mav on June 17, 2012, 07:40:15 AM
I want to know how many confirmations each of the transfers into a given address has.

I can achieve this in an inefficient way using

Code:
bitcoind listreceivedbyaddress

and manually filtering the result for only the address I'm interested in.

My concern is that if I have a lot of transactions, this command results in a very long list containing all my addresses. Is there a way to get this same list but only for a specific address, so that I don't have to filter through it?

Another way I could do it is using

Code:
bitcoind getreceivedbyaddress ADDRESS X

and iterate over a suitable range for X until I see a balance change, and then I know that there was a transaction to that address which has X confirmations.

I feel like I'm missing something here and I'm making this harder than it is. Anyone got some ideas what I should do?


Title: Re: bitcoind - get no. of confirmations for an address
Post by: Revalin on June 17, 2012, 07:47:54 AM
An address doesn't have a discrete number of confirmations.  Only a transaction does.

Try this:
Code:
bitcoind gettransaction <txid>


Title: Re: bitcoind - get no. of confirmations for an address
Post by: mav on June 17, 2012, 08:03:54 AM
Yep that makes sense about transactions having confirmations not addresses

To be able to use gettransaction I need to have a transaction id which is not something I automatically have for a deposit, only for a send.

I can get a list of incoming transaction ids using

Code:
bitcoind listtransactions ACCOUNT

however I still have the problem of having to do lots of filtering if ACCOUNT has a lot of transactions. I guess I could keep track of how many transactions were returned the last time I called it and use that in the 'from' parameter to narrow down the list.

Thanks for the ideas. Still doesn't seem like a neat solution, but listtransactions is better than the previous ideas I had.

edit:
I might clarify the reason I made this title 'address confirmations' and not 'transaction confirmations' is that I plan to have each address used only once, and hence address should be analogous to a transaction. Of course I cannot assume that the address will indeed only be used once since someone may pay to it multiple times, so I am also thinking about how to deal with that scenario should it arise.


Title: Re: bitcoind - get no. of confirmations for an address
Post by: Revalin on June 17, 2012, 08:23:00 AM
That's what I'd recommend: use one address per sale.  Then you don't get a big long list back.  You just get (usually) one transaction, and you deliver the goods when it confirms.  If any unexpected transactions come in you should notice it in your net balance.

Also check out 'listsinceblock <blockhash> <confirmations>'.


Title: Re: bitcoind - get no. of confirmations for an address
Post by: kano on June 19, 2012, 02:43:04 PM
 listtransactions '*' N

lists the last N transactions.