primal100 / pybitcointools

Simple, common-sense Bitcoin-themed Python ECC library
Other
335 stars 151 forks source link

Sweep TX Fees #56

Open x011 opened 1 year ago

x011 commented 1 year ago

Hi, What's the best approach regarding calculating fees on a sweep tx? Thanks.

primal100 commented 1 year ago

What's a sweep Tx compared with a regular transaction? There is a calculate_fee method on each coin class.

x011 commented 1 year ago

Could you please be kind enough to provide simple example how to send all funds from one wallet to another? ( I called it "sweep" but this may have a different meaning)

primal100 commented 1 year ago

A lot of the code for wallet management was in the original library by Vitalik, so it was carried over to the fork and honestly I can't really remember how it all works because it's been a few years since i looked at it. The next stage of this project will be to tidy up all the wallet code and modernise it.

What makes it complicated is there are different formulas for deriving private keys from the wallet words. There is a standardised formula, but Electrum using it's own formula. I remember I did add functions for the Electrum formula. And there have probably been changes to that in the last few years which of course makes backward compatibility tricky and of course backward compatibility is essential for old wallets!

So when I get around to it I need to study all this again and then tidy up the code to and test everything. Not a trivial task. But all the code needed is there, it's just a matter of me tidying it up, and writing updated tests and documentation.

But the code is robust and tested extensively when dealing with individual private keys.

There are functions where you can enter your wallet words and get your private keys. You can then loop through the private keys, get the address and run get_balance. Then create txs to spend each of those balances. You would need to do the same for any change address in the wallets which are derived separately.

Anyway if you tell me the mechanism by which the wallet was created (e.g. Electrum) and if it's legacy or native segwit address type I can try to help. At least once you get the private keys it should be easy from there!