Bitcoin Forum
May 05, 2024, 08:48:00 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: bitcoind listunspent for account  (Read 1783 times)
Kazuldur (OP)
Legendary
*
Offline Offline

Activity: 971
Merit: 1000


View Profile
March 31, 2013, 03:29:30 PM
 #1

Is it possible to list unspent transaction outputs only for one account using bitcoind RPC API?
I have:
Code:
bitcoind listaccounts
{
    "" : 0.00285696,
    "account1" : 0.11652234,
    "account2" : 0.00000000
}
and I would like to get unspent transaction outputs only for "account1", not all accounts. I've tried using getaddressesbyaccount and then feeding listunspent with it, but I think it doesn't include these auto-generated addresses used for a change (and I need these too). Is there a way to get all addresses associated with an account?

Unless stated otherwise, all opinions are of my own, not FaucetBOX.com's.
1714898880
Hero Member
*
Offline Offline

Posts: 1714898880

View Profile Personal Message (Offline)

Ignore
1714898880
Reply with quote  #2

1714898880
Report to moderator
1714898880
Hero Member
*
Offline Offline

Posts: 1714898880

View Profile Personal Message (Offline)

Ignore
1714898880
Reply with quote  #2

1714898880
Report to moderator
Remember that Bitcoin is still beta software. Don't put all of your money into BTC!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714898880
Hero Member
*
Offline Offline

Posts: 1714898880

View Profile Personal Message (Offline)

Ignore
1714898880
Reply with quote  #2

1714898880
Report to moderator
1714898880
Hero Member
*
Offline Offline

Posts: 1714898880

View Profile Personal Message (Offline)

Ignore
1714898880
Reply with quote  #2

1714898880
Report to moderator
Stephen Gornick
Legendary
*
Offline Offline

Activity: 2506
Merit: 1010


View Profile
March 31, 2013, 08:36:05 PM
 #2

Is there a way to get all addresses associated with an account?

You can use
 listaddressgroupings
to get all the addresses in the wallet and then getaccount to determine which account each address is in.
You could filter that with the ones you already know from getaddressesbyaccount and that would leave a smaller list (just of change addresses that exist for all accounts).

Unichange.me

            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █


Kazuldur (OP)
Legendary
*
Offline Offline

Activity: 971
Merit: 1000


View Profile
April 01, 2013, 05:19:15 PM
 #3

Well either I'm doing something wrong or there's something wrong with my bitcoind.
Code:
$ bitcoind getaddressesbyaccount bitcoiner
[
    "17A1QM8Tjjd8cyHPYmzC3M4ou9Q8RXWjKv",
    "14iRpAsjszmbUY1HrU9yarPJm1sbtKM6Ew",
    "19ZZ8DZsb5qgchuKPZWET7Uj8rDoj4KgmB"
]
$ bitcoind listaddressgroupings | grep 17A1QM8Tjjd8cyHPYmzC3M4ou9Q8RXWjKv
(nothing here...)
$ bitcoind listaddressgroupings | grep 14iRpAsjszmbUY1HrU9yarPJm1sbtKM6Ew  #just to check...
            "14iRpAsjszmbUY1HrU9yarPJm1sbtKM6Ew",
So the first thing is that listaddressgroupings doesn't list all addresses in the wallet.
The second thing is that for every address returned by listaddressgroupings (except for these returned by getaddressesbyaccount) getaccount gives nothing. Here's an output of a little script implementing Stephen's idea (checking for bitcoiner account):
Code:
$ php test.php
array(2) {
  [0]=>
  string(34) "14iRpAsjszmbUY1HrU9yarPJm1sbtKM6Ew"
  [1]=>
  string(34) "19ZZ8DZsb5qgchuKPZWET7Uj8rDoj4KgmB"
}
Code:
Code fragment using jsonRPCClient.php:
$addresses = $this->conn->listaddressgroupings();
$addresses = $addresses[0];
$ret = array();
foreach($addresses as $address) {
    if($this->conn->getaccount($address[0]) == $account)
        $ret[] = $address[0];
}
var_dump($ret);

Unless stated otherwise, all opinions are of my own, not FaucetBOX.com's.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!