AustEcon / bitsv

BitSV: Bitcoin made easy. Documentation:
https://AustEcon.github.io/bitsv
MIT License
96 stars 28 forks source link

Add sendall() function to PrivateKey class #50

Closed AustEcon closed 4 years ago

AustEcon commented 4 years ago

Currently the way to 'sendall' to an address is to do: my_key.send([], leftover='ADDRESS_TO SENDALL_TO')

Which basically passes in an empty list for outputs and sends all of the remaining change (everything) to the desired address. This is not intuitive to figure this out though and could be described as a bit of a "hack".

I therefore propose adding a sendall() to PrivateKey class so that syntax can be: my_key.sendall('ADDRESS_TO SENDALL_TO')

ghost commented 4 years ago

In my opinion, if we add this it should be called sweep.

ferndot commented 4 years ago

@AustEcon what about just setting a boolean flag send_all=True or sweep=True?

AustEcon commented 4 years ago

I don't have strong feelings about it. That might work.

If 'sweep' is the more correct terminology then I guess we should go with that. Needs to have an unambiguous docstring explaining what it does - wouldn't be a very nice surprise...

Would it be very intuitive though to use these boolean flags? Because basically you would still need to provide an address and an amount as a list of tuples... then sweep will...?send the rest there? (but what if you have different addresses in that list... which one??).

This is the reason that (for something that could give someone a pretty bad day if it does this when they don't want it to) - I favour a specialised function. Put in the address and everything gets sent to there. Simple and no surprises. And I think this is more in line with what your average dev would be expecting to find when looking for this functionality.