Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: CryptoPanda on July 29, 2014, 01:30:38 PM



Title: Salvaging only used addresses and moving them to new wallet.dat?
Post by: CryptoPanda on July 29, 2014, 01:30:38 PM
What would be the best way to salvage only the addresses that actually received anything and move them to new wallet.dat?
the old one is corrupt for some reason and is 90mb so we need some automatic way?


Title: Re: Salvaging only used addresses and moving them to new wallet.dat?
Post by: bitsta on July 29, 2014, 03:50:46 PM
this would require a script with the following logic:

pseudocode: (rpc functions existent)
Code:

dyn array accounts[] = listaccounts(); //all accounts
array keys[accounts.length()];  //array for the private keys
dyn array addresses[]; //array for the addresses
//this for-loop just puts every private-key from a public-key which has at least one transaction
//into an array (key[]). this array will be later used to import the keys into the new wallet.
for(i<accounts.length();i++) {

       if( listtransactions(accounts[i]) != empty){
       addresses[i]=getaddressesbyaccount(accounts[i]);
       key[i]=importprivkey(accounts[i]);
       
       }

       

}

fstream f;

f.write(file, keys); //now save the private keys on a file

//this for loop will be used on the
fstream.f;
dyn array keys[];

f.read(file, keys[]); //open the saved keys and put them into this 

for(i<keys.lenght();i++){

     importprivkey(keys[i]); //import every single key to the new wallet.dat

}


inform yourself about json-rpc and its methods and usage on the
different languages. i recommend the usage of an python or php
file as it s probably the fastest way. java is also simple via http reqs.
hope it s clear now.

cheers,
bitsta


P.S. if you wan to manually do this procedure manually
you can list all accounts and check them all manually.
afterwards just export those keys with associated tx.


Title: Re: Salvaging only used addresses and moving them to new wallet.dat?
Post by: Bungeebones on July 29, 2014, 09:56:19 PM
Along the lines of bitsta post use listaccounts and check if any fields such as txid have values. The confirmations field would be a good one to check too to make sure you don't send it out before the confirmations come in (maybe).