Bitcoin Forum

Bitcoin => Bitcoin Discussion => Topic started by: Andrew Vorobyov on June 02, 2012, 08:59:49 AM



Title: getreceivedbyaddress exists, where is getaddressbalance
Post by: Andrew Vorobyov on June 02, 2012, 08:59:49 AM
"getreceivedbyaddress" exists = shows total received...

Why there is no "getaddressbalance"?

How can I get balance of address?


Title: Re: getreceivedbyaddress exists, where is getaddressbalance
Post by: Pieter Wuille on June 02, 2012, 09:58:34 AM
That would require an index from each address to all blocks/transactions that spend to or from it. Since this is not required for normal operations, and quite expensive, it is not (yet?) implemented in the reference client.


Title: Re: getreceivedbyaddress exists, where is getaddressbalance
Post by: Andrew Vorobyov on June 02, 2012, 10:00:31 AM
It means, I can not get balance of specific address using official Bitcoin client??? Come on!


Title: Re: getreceivedbyaddress exists, where is getaddressbalance
Post by: Gavin Andresen on June 02, 2012, 02:16:48 PM
How would you use a 'getaddressbalance'?  What are you trying to do?

Start with an empty wallet.  I send you 100 BTC to address 'foo'. Then you send somebody else 1 BTC.

Internally, a new change address with 49 (edit: 99) bitcoins is created, so getaddressbalance 'foo' would return zero. Would that ever be the right answer?



Title: Re: getreceivedbyaddress exists, where is getaddressbalance
Post by: rjk on June 02, 2012, 02:23:57 PM
How would you use a 'getaddressbalance'?  What are you trying to do?

Start with an empty wallet.  I send you 100 BTC to address 'foo'. Then you send somebody else 1 BTC.

Internally, a new change address with 49 bitcoins is created, so getaddressbalance 'foo' would return zero. Would that ever be the right answer?


I think you mean 99 lol.


Title: Re: getreceivedbyaddress exists, where is getaddressbalance
Post by: Gavin Andresen on June 02, 2012, 02:26:21 PM
I think you mean 99 lol.
I should lie and say I'm feeling extra generous to miners this morning and wanted to give them an imaginary 50 BTC fee...


Title: Re: getreceivedbyaddress exists, where is getaddressbalance
Post by: Pieter Wuille on June 02, 2012, 02:39:22 PM
The core issue here is that the abstractions provided by the wallet and what you can see on blockchain explorers differs.

Wallets manage a set of keys, and a set of unspent coins available for those keys to spend. They can keep track of income per public address you create, but only the balance of the entire wallet that matters to you if you are looking at the wallet abstraction (i.e., the amount you're able to spend).

Internally, wallet create change addresses, and coins can be assigned to either public or change keys in the wallet. Blockchain explorer can however not see the entire wallet, they only see the individual addresses.

I think that when people want to know "the balance of an address", they really want the balance of a wallet, but have learnt to observe this through the only publically observable piece of information available: the individual addresses in it. The real solution is using watch-only deterministic wallets here, in my opinion (being worked on ...). That allows you to keep working in the wallet abstraction, without needing to be bothered with individual addresses and keys.

The alternative is using a lower-level wallet abstraction, where you micro-manage all keys and addresses yourself. There are certainly useful applications for this (for example satoshidice uses the specific input coins you sent them in your payouts, so they don't take a risk allowing low numbers of confirmations). This way of working is currently not supported in the reference client. There are plans to include this functionality, but it will only be the preferred solution for particular instances in my opinion. That said, it can be very educational.


Title: Re: getreceivedbyaddress exists, where is getaddressbalance
Post by: ThomasV on June 02, 2012, 03:14:40 PM
I think that when people want to know "the balance of an address", they really want the balance of a wallet

I think you are wrong. When people ask for something, chances are that they want that thing :)


Title: Re: getreceivedbyaddress exists, where is getaddressbalance
Post by: Gabi on June 02, 2012, 03:24:00 PM
Quote
They can keep track of income per public address you create, but only the balance of the entire wallet that matters to you if you are looking at the wallet abstraction (i.e., the amount you're able to spend).
Maybe not.

Maybe we have different addresses in a single wallet with btc coming from different sources and we want to keep them divided, and don't mix them.


Title: Re: getreceivedbyaddress exists, where is getaddressbalance
Post by: Pieter Wuille on June 02, 2012, 03:30:19 PM
Quote
They can keep track of income per public address you create, but only the balance of the entire wallet that matters to you if you are looking at the wallet abstraction (i.e., the amount you're able to spend).
Maybe not.

Maybe we have different addresses in a single wallet with btc coming from different sources and we want to keep them divided, and don't mix them.

That's certainly useful sometimes and very educational. It's also planned to be included in the client.

But it doesn't fit in the wallet abstraction provided by the client. Breaking that abstraction would confuse people who only want to use it, and do not care about the internal functioning. It's something for an expert mode, and belongs in what I call micro-management. Certainly people will want this, but it doesn't fit in what the client currently provides (the abstraction that it represents a wallet with money in).


Title: Re: getreceivedbyaddress exists, where is getaddressbalance
Post by: Killdozer on June 02, 2012, 05:05:28 PM
Quote
But it doesn't fit in the wallet abstraction provided by the client. Breaking that abstraction would confuse people who only want to use it, and do not care about the internal functioning. It's something for an expert mode, and belongs in what I call micro-management. Certainly people will want this, but it doesn't fit in what the client currently provides (the abstraction that it represents a wallet with money in).

Using the rpc IS the expert mode. Do you think that people who easily get confused will use the rpc for something? Adding a command does not "break" anything, for the people who won't even know about it, nothing will change. For the people that do know about this, things will only get easier. It is just a command that should've been there from the beginning.