Permalink
Browse files

Fix for tx deserialization. And some fixwallet hacks.

  • Loading branch information...
1 parent 4e16c2f commit ed4d941f8d81620883974a8008429874c4801282 @gavinandresen gavinandresen committed Jan 20, 2011
Showing with 26 additions and 10 deletions.
  1. 0 __init__.py
  2. +1 −7 deserialize.py
  3. +22 −1 fixwallet.py
  4. +3 −2 wallet.py
View
No changes.
View
@@ -118,16 +118,10 @@ def parse_WalletTx(vds):
first = vds.read_string()
second = vds.read_string()
d['orderForm'].append( (first, second) )
- # Versioning was messed up before bitcoin 0.3.14.04;
- # nVersion is actually fTimeReceivedIsTxTime before then.
- d['nVersion'] = vds.read_uint32()
+ d['fTimeReceivedIsTxTime'] = vds.read_boolean()
d['timeReceived'] = vds.read_uint32()
d['fromMe'] = vds.read_boolean()
d['spent'] = vds.read_boolean()
- if d['nVersion'] > 31404:
- d['fTimeReceivedIsTxTime'] = vds.read_boolean()
- d['fUnused'] = vds.read_boolean()
- d['fromAccount'] = vds.read_string()
return d
View
@@ -25,6 +25,10 @@ def main():
help="Look for files here (defaults to bitcoin default)")
parser.add_option("--out", dest="outfile", default="walletNEW.dat",
help="Name of output file (default: walletNEW.dat)")
+ parser.add_option("--skipkey", dest="skipkey",
+ help="Skip entries with keys that contain given string")
+ parser.add_option("--tweakspent", dest="tweakspent",
+ help="Tweak transaction to mark unspent")
(options, args) = parser.parse_args()
if options.datadir is None:
@@ -41,7 +45,24 @@ def main():
logging.error("Couldn't open "+DB_DIR)
sys.exit(1)
- rewrite_wallet(db_env, options.outfile)
+ if options.skipkey:
+ def pre_put_callback(type, data):
+ if options.skipkey in data['__key__']:
+ return False
+ return True
+ rewrite_wallet(db_env, options.outfile, pre_put_callback)
+ elif options.tweakspent:
+ txid = options.tweakspent.decode('hex_codec')[::-1]
+ def tweak_spent_callback(type, data):
+ if txid in data['__key__']:
+ import pdb
+ pdb.set_trace()
+ data['__value__'] = data['__value__'][:-1]+'\0'
+ return True
+ rewrite_wallet(db_env, options.outfile, tweak_spent_callback)
+ pass
+ else:
+ rewrite_wallet(db_env, options.outfile)
db_env.close()
View
@@ -169,7 +169,7 @@ def dump_accounts(db_env):
db.close()
-def rewrite_wallet(db_env, destFileName):
+def rewrite_wallet(db_env, destFileName, pre_put_callback=None):
db = open_wallet(db_env)
db_out = DB(db_env)
@@ -183,7 +183,8 @@ def rewrite_wallet(db_env, destFileName):
sys.exit(1)
def item_callback(type, d):
- db_out.put(d["__key__"], d["__value__"])
+ if (pre_put_callback is None or pre_put_callback(type, d)):
+ db_out.put(d["__key__"], d["__value__"])
parse_wallet(db, item_callback)

0 comments on commit ed4d941

Please sign in to comment.