bitshares / python-bitshares

Fully featured client-side library for the BitShares Blockchain - written entirely in python.
http://docs.pybitshares.com/
MIT License
162 stars 167 forks source link

Need a method to remove existing sqlite database state and file #52

Closed ThomasFreedman closed 6 years ago

ThomasFreedman commented 6 years ago

There may be a way to accomplish this but if so it is missing from the documentation.

There is currently no way to "start fresh" or clear the self.created flag of the wallet class.

The idea is to code a robust, integrated solution so a PyBitShares program is standalone, without the need for uptick or some external program to initialize the wallet. This is no problem if no wallet has ever been created, however once a wallet has been created there is no way to get rid of it and recreate a new one.

A simple reset method to clear the "created" flag would probably do the trick. Of course it would be best if the method also removed the bitshares.sqlite DB file and cleaned up any other state associated with the old wallet. The method should result in a state identical to one in which no wallet was ever created.

grctest commented 6 years ago

Can't you delete the local wallet sqlite file? I did this when I forgot the password for my local python-bitshares setup.

ThomasFreedman commented 6 years ago

No, that doesn't reset the "wallet exists" state. Look at the TLDR code I sent you both in Telegram. I describe the use case that screws up wallet "REcreation". Deleting the .sqlite file still leaves state info in memory, which causes the wallet.newWallet() to fail.

xeroc commented 6 years ago

there is now a wallet.wipe() that keeps the settings but removes all the keys

ThomasFreedman commented 6 years ago

I'm not sure that will do the job. The wipe() needs to reset the "wallet exists" state so a brand new wallet can be created. If that is possible (after calling this new wipe method I need to be able to use the new_wallet method) great, but it sounds from your description you are retaining the wallet exists state and would thus prevent using new_wallet and after calling wipe() would still say a wallet exists.

If I understand your mod correctly, what password would one need to use to unlock the (old / previous / wiped) wallet? That is the use case I want a fully standalone Python-BitShares program to handle, a wallet exists but the password is unknown. I should be able to reCreate a new wallet with a new password if the old password is unknown.

I wasn't going to implement use of the new wipe method until you roll it into the master branch. I'm in no hurry so please take your time.

Lastly the name you gave this method, "wipe" conveys a "destroy" meaning. Sounds more like a "reset" if the wallet exists state is unchanged by wipe.

xeroc commented 6 years ago

"wallet exists" checks if there is a masterkey.. if there is, then the wallet exists. Wipe() removes keys and the masterkey.

ThomasFreedman commented 6 years ago

Yep, tested and it works properly, and after calling the wipe() method I can test for wallet's existence and it shows none exists, and calling new wallet succeeds in creating a brand new wallet.