Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: hippich on August 27, 2010, 02:44:50 AM



Title: getreceivedbyaddress JSON
Post by: hippich on August 27, 2010, 02:44:50 AM
I need to get received amounts for specific address, but it looks like there is not such JSON RPC call yet. Is this something implemented and just not mentioned in Documentation, or it's not implemented at all for some reason?


Title: Re: getreceivedbyaddress JSON
Post by: jgarzik on August 27, 2010, 04:56:37 AM

This patch (not in official SVN repo or official bitcoin client) will list transactions in your wallet:
http://bitcointalk.org/index.php?topic=611.0



Title: Re: getreceivedbyaddress JSON
Post by: hippich on August 27, 2010, 05:56:48 AM
This is nice feature to show list of transactions for user, thanks!

But right now I just need getreceivedbyaddress RPC call. This thread mentions that this is already implemented, but there is nothing about it in wiki - http://www.bitcoin.org/wiki/doku.php?id=api

is getreceivedbyaddress also somewhere in svn? I want to avoid compiling client, since I had some problems with it and I need to do it on several machines with different hardware. So I'd better download binaries =))

ps: right now, since app and bitcoind runs on the same machine, just execute 'bitcoind getreceivedbyaddress [address]' =)


Title: Re: getreceivedbyaddress JSON
Post by: jgarzik on August 27, 2010, 06:21:05 AM
It's there, not sure why you're not seeing it...  Type 'help' to list all JSON RPC calls:

Code:
getaddressesbylabel <label>
getbalance
getblock height
getblockcount
getblocknumber
getconnectioncount
getdifficulty
getgenerate
gethashespersec
getinfo
getlabel <bitcoinaddress>
getnewaddress [label]
getreceivedbyaddress <bitcoinaddress> [minconf=1]
getreceivedbylabel <label> [minconf=1]
help [command]
listreceivedbyaddress [minconf=1] [includeempty=false]
listreceivedbylabel [minconf=1] [includeempty=false]
listtransactions [count=10] [minconf=1] [includegenerated=true]
sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to]
setgenerate <generate> [genproclimit]
setlabel <bitcoinaddress> <label>
stop


Title: Re: getreceivedbyaddress JSON
Post by: theymos on August 27, 2010, 07:36:56 AM
I added it to the wiki. getreceivedbyaddress has been around since 0.2.9.


Title: Re: getreceivedbyaddress JSON
Post by: hippich on August 27, 2010, 01:06:08 PM
Oh. Thank you!

For some reason it didn't worked for me first time i tried and I thought that since it's not on wiki it's not supported =)

Now everything works as intendend. Looking forward for inclusion of listtransactions patch into main branch =)


Title: Re: getreceivedbyaddress JSON
Post by: payb.tc on March 20, 2012, 12:20:19 PM
sorry couldn't find this answer anywhere...

how does one get the 'minconf=0' balance of addresses that aren't in their wallet?

it's easy to get the 'confirmed' balance using something like blockexplorer's api.

but as far as i know, getreceivedbyaddress($address,0) only works on addresses that are in your own wallet.

so, for eg. how does this page work? http://bitcoincharts.com/bitcoin/txlist/

thanks.


edit: okay so i found out blockexplorer's api allows you to add 'minconf' to the url, so one could theoretically use that, HOWEVER, i'm still interested in finding out how to do it more directly if possible, rather than rely on blockexplorer (or other 3rd party) which may not be always online.


Title: Re: getreceivedbyaddress JSON
Post by: Pieter Wuille on March 20, 2012, 02:32:01 PM
Calculating how much was received by addresses that are not your own (i.e. transactions that are not in your wallet) would require either a full blockchain rescan, or an index with the balances of all addresses to be kept. Since this information is not needed in normal operation, such an index is not implemented.

Short answer: currently not possible with the reference client.


Title: Re: getreceivedbyaddress JSON
Post by: payb.tc on March 20, 2012, 02:51:41 PM
Calculating how much was received by addresses that are not your own (i.e. transactions that are not in your wallet) would require either a full blockchain rescan, or an index with the balances of all addresses to be kept. Since this information is not needed in normal operation, such an index is not implemented.

Short answer: currently not possible with the reference client.

so i'm guessing then, merchants who generate a pool of addresses offline using bitaddress.org and then import them into a db to give out to customers (instead of generating addresses on-the-fly), just use the blockexplorer api to check for incoming payments.


Title: Re: getreceivedbyaddress JSON
Post by: Pieter Wuille on March 20, 2012, 03:08:55 PM
Calculating how much was received by addresses that are not your own (i.e. transactions that are not in your wallet) would require either a full blockchain rescan, or an index with the balances of all addresses to be kept. Since this information is not needed in normal operation, such an index is not implemented.

Short answer: currently not possible with the reference client.

so i'm guessing then, merchants who generate a pool of addresses offline using bitaddress.org and then import them into a db to give out to customers (instead of generating addresses on-the-fly), just use the blockexplorer api to check for incoming payments.

One other possibility is using a wallet with a large pool of pregenerated keys, encrypting it, and put the encrypted wallet but not the password on the webserver. This way the bitcoind on the webserver can observe incoming (and outgoing) payments, but not spend it by itself.

Type-2 determinstic wallets (https://bitcointalk.org/index.php?topic=19137.0) would bring a cleaner solution here. They're not yet supported in bitcoind, but I'm working on it.


Title: Re: getreceivedbyaddress JSON
Post by: payb.tc on April 21, 2012, 12:55:52 PM
i was just re-visiting this problem today and found out that blockexplorer won't work after all... putting 0 for the minconf results in:

Quote
ERROR: you must use an integer above 0 for minconf


Title: Re: getreceivedbyaddress JSON
Post by: romsa9 on August 27, 2013, 04:07:03 PM
Does getreceivedaddress count the change received from outgoing transactions?

If I send 0.001 BTC and it uses a 1 BTC input, does the 0.999 count in getreceivedbyaddress next time?


Title: Re: getreceivedbyaddress JSON
Post by: payb.tc on August 27, 2013, 09:39:08 PM
Does getreceivedaddress count the change received from outgoing transactions?

yes, if the change is going back to the same address. change amounts are no different to other inputs in that respect. normally though, change will go to a newly generated 'change' address each time.



Title: Re: getreceivedbyaddress JSON
Post by: romsa9 on September 01, 2013, 04:26:08 AM
What about getreceivedbyaccount? The reason I ask is that I'm looking for a way to track users balances, and be able to manually alter them. For example a user deposits 100 BTC, then wins 10 BTC from another player in the system, heis now able to withdraw 110 BTC. Will he get a negative balance on the client then? If so that's okay.

But now what if the player buys an item from the house, his balance will decrease. Now how does the house spend those coins without making it look like a player withdrew bitcoins (not touching anyone's account balance)


Title: Re: getreceivedbyaddress JSON
Post by: dragonfruit on September 01, 2013, 05:10:14 AM
What about getreceivedbyaccount? The reason I ask is that I'm looking for a way to track users balances, and be able to manually alter them. For example a user deposits 100 BTC, then wins 10 BTC from another player in the system, heis now able to withdraw 110 BTC. Will he get a negative balance on the client then? If so that's okay.

But now what if the player buys an item from the house, his balance will decrease. Now how does the house spend those coins without making it look like a player withdrew bitcoins (not touching anyone's account balance)

You can use getbalance and specify an account. It is possible for accounts to have negative balances.


Title: Re: getreceivedbyaddress JSON
Post by: gmaxwell on September 01, 2013, 06:18:14 AM
You can do this sort of thing with accounts, but its highly inadvisable:  there is no live replication for the database, so it's possible for you to fail and lose all the moves since your last backup.

Normally the advice is that for anything serious you should be doing the accounting in your own system and just letting bitcoind notice when payments come in.