Author

Topic: Electrum not using change addresses (Read 1528 times)

sr. member
Activity: 475
Merit: 252
July 25, 2014, 11:26:05 PM
#7
Thanks for the issue report on Github:

Everyone else follow the issue here:

https://github.com/spesmilo/electrum/issues/769
sr. member
Activity: 475
Merit: 252
July 25, 2014, 09:42:11 PM
#6
I found the bug. (err... more like a good-intention feature gone wrong)

https://github.com/spesmilo/electrum/blob/f92b483942d3f8ee51506e0436d9b524db33a336/lib/wallet.py#L1142

The change selection method checks the first input, and if account == -1 (aka if the input is from imported keys) then it sets the change address as the address of the first input.
As your first input was from an imported address, it will send the change to your first input's imported address.

https://github.com/spesmilo/electrum/blob/master/lib/wallet.py#L602

It looks like this is how it still works with the current development HEAD as well.


My two cents: I think changing

Code:
if not self.use_change or account == -1:

to

Code:
if not self.use_change:

would be a good fix... as even if the input is from an imported key, if the user has change enabled, it shouldn't matter.



I assume this feature was created with this idea in mind:  "If the user imports a paper wallet into Electrum, then uses Electrum to send, then deletes Electrum... we want to make sure their paper wallet still has the change."


Another way to prevent your issue would be to add a loop that continues to check inputs as long as the inputs are from imported keys... if it finds even one input from a non-imported address, it should assume the user would like to follow the self.use_change option (the option you have set in the preferences)

If you have Electrum installed (using an installer) or are building it from source. Make the change I mentioned in "My two cents"... the line I mention is Line 1142 in the /lib/wallet.py file
newbie
Activity: 25
Merit: 0
July 25, 2014, 07:55:22 PM
#5
That one is, yes, though I did a regular "Send" transaction, not a custom one, so whether the source addresses are imported or not shouldn't matter to me. I would expect all change to go to a "Change" address - that is the whole point of them. It didn't even return the change to the imported address, just to one of my other regular addresses.

This seems like a bug to me.
legendary
Activity: 3682
Merit: 1580
newbie
Activity: 25
Merit: 0
July 24, 2014, 10:58:51 PM
#3
No, it's not imported.
legendary
Activity: 3682
Merit: 1580
July 19, 2014, 04:34:43 AM
#2
Is 1K2 the address of an imported private key? I believe Electrum sends change back to an imported private key. If I'm wrong please correct me.
newbie
Activity: 25
Merit: 0
July 17, 2014, 03:48:37 PM
#1
I recently made this transaction with Electrum 1.9.8:
https://blockchain.info/tx/7ba987f202323c302b7cc736436a1858579255b131e4f7332caced3a96d945ed

You'll notice that some change from the transaction went back to 1K2TZGCiP8F2sZHtZ73LtyMQJUygFxwUUH, which is also one of the source addresses.

Why is Electrum returning funds to the same address instead of to a change address?

"Use change addresses" is turned on in the Settings.
Jump to: