Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: SRoulette on April 20, 2013, 01:47:06 PM



Title: [ANN] wallet_tool: A simple address & privkey dumper/importer
Post by: SRoulette on April 20, 2013, 01:47:06 PM
Greetings,
I was having trouble importing and exporting bulk keys from old wallets into new. pywallet did look promising but I could not get it to work 100%.
I asked my sites coder (codemonkey) who already had a tool he was using. After separating it from our casino engines libraries he packaged it up for me to use on windows and added some short documentation :D
The bonus for me is it just works, no installing extra libraries or perl etc.

It works for bitcoin, ppcoin (the currency I needed it for), teracoin, litecoin and novacoin. In theory it will work for every bitcoin clone that supports bitcoins dumpprivkey and importprivkey rpc commands.


Install:
Extract the files somewhere easy, ie c:\

Configure your %appdata%/bitcoin/bitcoin.conf like so:

Code:
server=1
rpcuser=ppuser
rpcpass=pppasss
rpcpassword=pppasss


Help:

Code:
C:\wallet_tool>wallet_tool.exe --help

===============================================================================
wallet_tool.pl 1.0-RC1
===============================================================================

A free tool provided by satoshiroulette.com
written by codemonkey@satoshiroulette.com

This tool does 2 things very well.
* Dumping private keys from a local or remote wallet
* Importing private keys to a local or remote wallet

Options can be set via command line arguments or a config file.

Options names are compatible with bitcoin.conf's names.
For local dumps and imports you can use your bitcoins bitcoin.conf file as
the wallet tool's config file.

Tested on BTC, LTC, TRC, PPC & NVC

===============================================================================
Command Line Options
===============================================================================
--ip=IP ADDRESS         Defaults to 127.0.0.1
--rpcport=RPC PORT      Defaults to: 8339 (bitcoins default), also

Dumping Private Keys:

  wallet_tool.pl --dump=/path/to/dump/file.txt --config=/path/to/bitcoin.conf
  wallet_tool.pl --dump=/dump.txt --rpcpassword=PASS --rpcuser=USER

Importing Private Keys:

  wallet_tool.pl --import=/path/to/dump/file.txt --config=/path/to/bitcoin.conf

===============================================================================
Config File Options
===============================================================================

The following options are read from the config file

rpcport=PORT
rpcuser=USER
rpcpassword=PASSWORD

===============================================================================

Usage:

Dumping Private Keys
note the addresses are empty, I made them for the demonstration :P

Code:
C:\wallet_tool>wallet_tool.exe --dump=c:\wallet_tool\dump.txt --config="c:\Documents and Settings\Administrator\Application Data\PPcoin\PPcoin.conf" --rpcport=9902
[STATUS] Reading Command Line Arguments:
[INFO] out file = c:\wallet_tool\dump.txt
[INFO] config file = c:\Documents and Settings\Administrator\Application Data\PPcoin\PPcoin.conf
[INFO] RPC Port = 9902
[STATUS] Reading Config File:
[INFO] rpcuser = 'ppuser'
[INFO] rpcpassword = 'pppasss'
PAEA4AVioDLxksqCaqs7PzJU4qd1ynCKqG - UC8b3sc79V3rdFAmg7osjn5sGZVGqXL9e3JKy8eFmKHTo7LrFHpq
PM2bttDPnBDM4bWnav6aQ1JN56f4UFZKqQ - U7WXcusbAxL64WGJNxBxqWrQDQoL8rqyGS2drTFSdHee6DrfnqaH
PPRzm8AtSmFBP6nVniSMiFNacxuCimjmAA - UCpHekcFFxeYFmXdkEHqJeJ2UHyiKugN337GqYhgKSZtrVnqvGYe
PUupg6LbGFR5j29SeuhS7ZYn3sScHjcb3W - U9CMemQerueAdH21v3vmiTAyczKzuUfoLWWkxpi9aU3dHKgM9AH7
PWTLu2z5bFpaiwsMZFiw1RXRPAwJjGxTdi - U7viX4FWkYnyTLLiETP4VyuqEeojsBw1n1Yk6Sg1TNKS6AbtPrMG

Attempting to import the same keys that already exist:
eg on the same wallet produces the following warnings.
Code:
C:\wallet_tool>wallet_tool.exe --import=c:\wallet_tool\dump.txt --config="c:\Documents and Settings\Administrator\Application Data\PPcoin\PPcoin.conf" --rpcport=9902
[STATUS] Reading Command Line Arguments:
[INFO] in file = c:\wallet_tool\dump.txt
[INFO] config file = c:\Documents and Settings\Administrator\Application Data\PPcoin\PPcoin.conf
[INFO] RPC Port = 9902
[STATUS] Reading Config File:
[INFO] rpcuser = 'ppuser'
[INFO] rpcpassword = 'pppasss'
[STATUS] Importing privkey for address PAEA4AVioDLxksqCaqs7PzJU4qd1ynCKqG, 1 of 5
[INFO] Wallet Already owns address PAEA4AVioDLxksqCaqs7PzJU4qd1ynCKqG, not importing privkey
[WARN] do you already have PAEA4AVioDLxksqCaqs7PzJU4qd1ynCKqG in this wallet
[STATUS] Importing privkey for address PM2bttDPnBDM4bWnav6aQ1JN56f4UFZKqQ, 2 of 5
[INFO] Wallet Already owns address PM2bttDPnBDM4bWnav6aQ1JN56f4UFZKqQ, not importing privkey
[WARN] do you already have PM2bttDPnBDM4bWnav6aQ1JN56f4UFZKqQ in this wallet
[STATUS] Importing privkey for address PPRzm8AtSmFBP6nVniSMiFNacxuCimjmAA, 3 of 5
[INFO] Wallet Already owns address PPRzm8AtSmFBP6nVniSMiFNacxuCimjmAA, not importing privkey
[WARN] do you already have PPRzm8AtSmFBP6nVniSMiFNacxuCimjmAA in this wallet
[STATUS] Importing privkey for address PUupg6LbGFR5j29SeuhS7ZYn3sScHjcb3W, 4 of 5
[INFO] Wallet Already owns address PUupg6LbGFR5j29SeuhS7ZYn3sScHjcb3W, not importing privkey
[WARN] do you already have PUupg6LbGFR5j29SeuhS7ZYn3sScHjcb3W in this wallet
[STATUS] Importing privkey for address PWTLu2z5bFpaiwsMZFiw1RXRPAwJjGxTdi, 5 of 5
[INFO] Wallet Already owns address PWTLu2z5bFpaiwsMZFiw1RXRPAwJjGxTdi, not importing privkey
[WARN] do you already have PWTLu2z5bFpaiwsMZFiw1RXRPAwJjGxTdi in this wallet

Importing the above private keys to a new wallet:

Code:
C:\wallet_tool>wallet_tool.exe --import=c:\wallet_tool\dump.txt --config="c:\Documents and Settings\Administrator\Application Data\PPcoin\PPcoin.conf" --rpcport=9902
[STATUS] Reading Command Line Arguments:
[INFO] in file = c:\wallet_tool\dump.txt
[INFO] config file = c:\Documents and Settings\Administrator\Application Data\PPcoin\PPcoin.conf
[INFO] RPC Port = 9902
[STATUS] Reading Config File:
[INFO] rpcuser = 'ppuser'
[INFO] rpcpassword = 'pppasss'
[STATUS] Importing privkey for address PAEA4AVioDLxksqCaqs7PzJU4qd1ynCKqG, 1 of 5
importprivkey OK
[STATUS] Importing privkey for address PM2bttDPnBDM4bWnav6aQ1JN56f4UFZKqQ, 2 of 5
importprivkey OK
[STATUS] Importing privkey for address PPRzm8AtSmFBP6nVniSMiFNacxuCimjmAA, 3 of 5
importprivkey OK
[STATUS] Importing privkey for address PUupg6LbGFR5j29SeuhS7ZYn3sScHjcb3W, 4 of 5
importprivkey OK
[STATUS] Importing privkey for address PWTLu2z5bFpaiwsMZFiw1RXRPAwJjGxTdi, 5 of 5
importprivkey OK

Download:

1.0-RC1 (http://satoshiroulette.com/downloads/wallet_tool.7z)
CRC32: 999E67A9
MD5: C644D23E00C4061A9ECF2CAAF57CCA21
SHA-1: 182BDA546F66D936B7528FC3AF2DD22F34AEA13F


Title: Re: [ANN] wallet_tool: A simple address & privkey dumper/importer
Post by: dserrano5 on April 20, 2013, 04:50:50 PM
That Perl code is from the 90s…

  • You should use some Getopt::* module for command-line arguments parsing. I'm fond of Getopt::Long, which is in the core Perl distribution these days.
  • Check out Pod::Usage too (a core module as well).
  • And some module for reading the INI file, there are tons (http://search.cpan.org/search?query=ini&mode=all) of them.
  • You shouldn't call methods with the '&' prefix unless you know what you're doing.
  • The syntax 'new Object' is deprecated, use 'Object->new'.
  • You should use lexically-scoped file descriptors (ie 'open my $file' instead of 'open FILE').
  • You should use 3-arg open.
  • And some other minor nits.
Feel free to send me a PM ;).


Title: Re: [ANN] wallet_tool: A simple address & privkey dumper/importer
Post by: SRoulette on April 21, 2013, 04:25:06 AM
Everyone is a critic :P

Monkeys Response:
Quote
timtowtdi !!!

That Perl code is from the 90s…
- Well its about when I started :) excuse me for showing my age.

Use Pod::Usage
- what for ? its a single file script thats being aimed at NON perl users hence the binary.

You shouldn't call methods with the '&' prefix unless you know what you're doing.
- Im pretty sure I know what Im doing, but if you care to give a specific example from my code and highlight the dangers you are claiming It would be appreciated.

The syntax 'new Object' is deprecated, use 'Object->new'.
- orly ?

You should use lexically-scoped file descriptors (ie 'open my $file' instead of 'open FILE').
- http://perldoc.perl.org/functions/open.html disagrees and FILE is easier for readability.

You should use 3-arg open.
- Why ? how is the current method impeding my application ?

And some other minor nits
- That being yourself you nit :P

Feel free to send me a PM .
- Pass, the application works perfectly Im not about to reformat it to suite one person.
I do however welcome any improvements in the form of a patch you can provide :)

So thats the monkeys response, I thank you for your feed back :)