Bitcoin Forum

Bitcoin => Electrum => Topic started by: smartwombat on August 31, 2018, 11:38:39 AM



Title: Electrum 3.0.5 list receiving addresses
Post by: smartwombat on August 31, 2018, 11:38:39 AM
In the console, or in the wallet UI, how can I extract a list of only receiving addresses ?

>> listaddresses()

Will return all addresses it seems, both change and receiving.

In the UI on the addresses tab I can filter to just receiving or just change addresses.
And then filter to unused, funded, used.

But there appears no way to extract that list.




Title: Re: Electrum 3.0.5 list receiving addresses
Post by: HCP on August 31, 2018, 12:16:58 PM
listaddresses() takes optional arguments...

def listaddresses(self, receiving=False, change=False, labels=False, frozen=False, unused=False, funded=False, balance=False):
"""List wallet addresses. Returns the list of all addresses in your wallet. Use optional arguments to filter the results."""

So, listaddresses(True) will give you receive. listaddresses(False,True) will give you change...


Title: Re: Electrum 3.0.5 list receiving addresses
Post by: smartwombat on August 31, 2018, 02:03:44 PM
Thanks for that.
Documentation, instead of reading the code, would be useful.

Also the error reporting from the console is, how can I put it politely, sub-optimal.
"Traceback (most recent call last):" tells me absolutely nothing useful when (not if) I make a mistake.

For my use I think I need this:
Code:
listaddresses(True,False,False,False,True)
Because I don't want to re-use addrresses ... but it returns 14407 rows the same as listaddresses(True)

So it appears that this code:
Code:
        for addr in self.wallet.get_addresses():
            if frozen and not self.wallet.is_frozen(addr):
                continue
            if receiving and self.wallet.is_change(addr):
                continue
            if change and not self.wallet.is_change(addr):
                continue
            if unused and self.wallet.is_used(addr):
                continue
            if funded and self.wallet.is_empty(addr):
                continue
            item = addr
Doesn't work.
Because unused was passed as True and it returns the same list as when left as default (=False).
So perhaps self.wallet.is_used() doesn't mean what I guess it does.


By adding random parentheses to a non-working example, I found this gets the unused addresses as well:
Code:
print ("\n".join(i for i in wallet.get_receiving_addresses() if len(wallet.history.get(i,{})) == 0))
And returning only 5165 rows, I think it's more like the right answer.


Title: Re: Electrum 3.0.5 list receiving addresses
Post by: jackg on August 31, 2018, 02:28:11 PM
def listaddresses(self, receiving=False, change=False, labels=False, frozen=False, unused=False, funded=False, balance=False):
"""List wallet addresses. Returns the list of all addresses in your wallet. Use optional arguments to filter the results."""

Based on what HCP posted,
Can't you just use
Code:
listaddresses(true,false,false,false,true,false)
which will get all of the receiving addresses that aren't frozen or with labells or bitcoin in them and have not been used...


Title: Re: Electrum 3.0.5 list receiving addresses
Post by: HCP on September 01, 2018, 12:40:38 AM
Thanks for that.
Documentation, instead of reading the code, would be useful.
You'll need to take that up with the devs...

Quote
Also the error reporting from the console is, how can I put it politely, sub-optimal.
"Traceback (most recent call last):" tells me absolutely nothing useful when (not if) I make a mistake.

The console is more or less a cut down Python console. So what you see is basically just a Python interpretor error... Unfortunately, these aren't very helpful a lot of the time :P

Quote
For my use I think I need this:
Code:
listaddresses(True,False,False,False,True)
Because I don't want to re-use addrresses ... but it returns 14407 rows the same as listaddresses(True)
Thankfully, I only have 23 rows to count... But using that command I get 22 returned... It is definitely leaving out the one address which received then spent all funds.

However there are 2 other addresses which have received, but are still included when unused=True...

Quote
So perhaps self.wallet.is_used() doesn't mean what I guess it does.
I'd have to agree to a certain extent... I'm not 100% sure as I haven't gone digging into the code yet. Perhaps ask the devs direct on the Electrum GitHub?? https://github.com/spesmilo/electrum/issues

Based on what HCP posted,
Can't you just use
Code:
listaddresses(true,false,false,false,true,false)
which will get all of the receiving addresses that aren't frozen or with labells or bitcoin in them and have not been used...
He said it didn't work... I've tested it and it "sort of" works... But perhaps not as one might imagine... So I think the definition of "unused" is slightly different to what the OP is expecting.

Also, note that you need to use True and False... Capitalisation is important. ;)