diff --git a/block.py b/block.py index b022d35..bff0744 100644 --- a/block.py +++ b/block.py @@ -178,10 +178,6 @@ def search_odd_scripts(datadir, cursor, block_data): block_string = _dump_block(datadir, block_data['nFile'], block_data['nBlockPos'], block_data['hash256'], block_data['hashNext'], False) - import pdb - if block_data['nHeight'] == 71036: - pdb.set_trace() - found_nonstandard = False for m in re.finditer(r'TxIn:(.*?)$', block_string, re.MULTILINE): s = m.group(1) diff --git a/deserialize.py b/deserialize.py index c99f2ef..534d57d 100644 --- a/deserialize.py +++ b/deserialize.py @@ -41,7 +41,7 @@ def parse_TxIn(vds): d['scriptSig'] = vds.read_bytes(vds.read_compact_size()) d['sequence'] = vds.read_uint32() return d -def deserialize_TxIn(d, transaction_index=None): +def deserialize_TxIn(d, transaction_index=None, owner_keys=None): if d['prevout_hash'] == "\x00"*32: result = "TxIn: COIN GENERATED" result += " coinbase:"+d['scriptSig'].encode('hex_codec') @@ -62,11 +62,15 @@ def parse_TxOut(vds): d['value'] = vds.read_int64() d['scriptPubKey'] = vds.read_bytes(vds.read_compact_size()) return d -def deserialize_TxOut(d): + +def deserialize_TxOut(d, owner_keys=None): result = "TxOut: value: %f"%(d['value']/1.0e8,) pk = extract_public_key(d['scriptPubKey']) result += " pubkey: "+pk result += " Script: "+decode_script(d['scriptPubKey']) + if owner_keys is not None: + if pk in owner_keys: result += " Own: True" + else: result += " Own: False" return result def parse_Transaction(vds): @@ -82,12 +86,12 @@ def parse_Transaction(vds): d['txOut'].append(parse_TxOut(vds)) d['lockTime'] = vds.read_uint32() return d -def deserialize_Transaction(d, transaction_index=None): +def deserialize_Transaction(d, transaction_index=None, owner_keys=None): result = "%d tx in, %d out\n"%(len(d['txIn']), len(d['txOut'])) for txIn in d['txIn']: result += deserialize_TxIn(txIn, transaction_index) + "\n" for txOut in d['txOut']: - result += deserialize_TxOut(txOut) + "\n" + result += deserialize_TxOut(txOut, owner_keys) + "\n" return result def parse_MerkleTx(vds): @@ -98,8 +102,8 @@ def parse_MerkleTx(vds): d['nIndex'] = vds.read_int32() return d -def deserialize_MerkleTx(d, transaction_index=None): - result = deserialize_Transaction(d, transaction_index) +def deserialize_MerkleTx(d, transaction_index=None, owner_keys=None): + result = deserialize_Transaction(d, transaction_index, owner_keys) result = "Merkle hashBlock: "+short_hex(d['hashBlock'][::-1])+"\n" + result return result @@ -129,8 +133,8 @@ def parse_WalletTx(vds): return d -def deserialize_WalletTx(d, transaction_index=None): - result = deserialize_MerkleTx(d, transaction_index) +def deserialize_WalletTx(d, transaction_index=None, owner_keys=None): + result = deserialize_MerkleTx(d, transaction_index, owner_keys) result += "mapValue:"+str(d['mapValue']) if len(d['orderForm']) > 0: diff --git a/fixwallet.py b/fixwallet.py index 3c5716b..dda57a4 100755 --- a/fixwallet.py +++ b/fixwallet.py @@ -48,8 +48,6 @@ def pre_put_callback(type, data): 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) diff --git a/wallet.py b/wallet.py index 41c6d66..2286385 100644 --- a/wallet.py +++ b/wallet.py @@ -4,7 +4,6 @@ from bsddb.db import * import logging -import pdb import re import sys import time @@ -167,43 +166,50 @@ def dump_wallet(db_env, print_wallet, print_wallet_transactions, transaction_fil wallet_transactions = [] transaction_index = { } + owner_keys = { } def item_callback(type, d): if type == "tx": wallet_transactions.append( d ) transaction_index[d['tx_id']] = d - elif print_wallet: - if type == "name": - print("ADDRESS "+d['hash']+" : "+d['name']) - elif type == "version": - print("Version: %d"%(d['version'],)) - elif type == "setting": - print(d['setting']+": "+str(d['value'])) - elif type == "key": - print("PubKey "+ short_hex(d['public_key']) + " " + public_key_to_bc_address(d['public_key']) + - ": PriKey "+ short_hex(d['private_key'])) - elif type == "wkey": - print("WPubKey 0x"+ short_hex(d['public_key']) + " " + public_key_to_bc_address(d['public_key']) + - ": WPriKey 0x"+ short_hex(d['private_key'])) - print(" Created: "+time.ctime(d['created'])+" Expires: "+time.ctime(d['expires'])+" Comment: "+d['comment']) - elif type == "defaultkey": - print("Default Key: 0x"+ short_hex(d['key']) + " " + public_key_to_bc_address(d['key'])) - elif type == "pool": - print("Change Pool key %d: %s (Time: %s)"% (d['n'], public_key_to_bc_address(d['public_key']), time.ctime(d['nTime']))) - elif type == "acc": - print("Account %s (current key: %s)"%(d['account'], public_key_to_bc_address(d['public_key']))) - elif type == "acentry": - print("Move '%s' %d (other: '%s', time: %s, entry %d) %s"% - (d['account'], d['nCreditDebit'], d['otherAccount'], time.ctime(d['nTime']), d['n'], d['comment'])) - else: - print "Unknown key type: "+type + elif type == "key": + owner_keys[public_key_to_bc_address(d['public_key'])] = d['private_key'] + + if not print_wallet: + return + if type == "tx": + return + elif type == "name": + print("ADDRESS "+d['hash']+" : "+d['name']) + elif type == "version": + print("Version: %d"%(d['version'],)) + elif type == "setting": + print(d['setting']+": "+str(d['value'])) + elif type == "key": + print("PubKey "+ short_hex(d['public_key']) + " " + public_key_to_bc_address(d['public_key']) + + ": PriKey "+ short_hex(d['private_key'])) + elif type == "wkey": + print("WPubKey 0x"+ short_hex(d['public_key']) + " " + public_key_to_bc_address(d['public_key']) + + ": WPriKey 0x"+ short_hex(d['private_key'])) + print(" Created: "+time.ctime(d['created'])+" Expires: "+time.ctime(d['expires'])+" Comment: "+d['comment']) + elif type == "defaultkey": + print("Default Key: 0x"+ short_hex(d['key']) + " " + public_key_to_bc_address(d['key'])) + elif type == "pool": + print("Change Pool key %d: %s (Time: %s)"% (d['n'], public_key_to_bc_address(d['public_key']), time.ctime(d['nTime']))) + elif type == "acc": + print("Account %s (current key: %s)"%(d['account'], public_key_to_bc_address(d['public_key']))) + elif type == "acentry": + print("Move '%s' %d (other: '%s', time: %s, entry %d) %s"% + (d['account'], d['nCreditDebit'], d['otherAccount'], time.ctime(d['nTime']), d['n'], d['comment'])) + else: + print "Unknown key type: "+type parse_wallet(db, item_callback) if print_wallet_transactions: keyfunc = lambda i: i['timeReceived'] for d in sorted(wallet_transactions, key=keyfunc): - tx_value = deserialize_WalletTx(d, transaction_index) + tx_value = deserialize_WalletTx(d, transaction_index, owner_keys) if len(transaction_filter) > 0 and re.search(transaction_filter, tx_value) is None: continue print("==WalletTransaction== "+long_hex(d['tx_id'][::-1]))