make most commands available in the console

This commit is contained in:
thomasv 2013-02-26 13:56:48 +01:00
parent dc466142d3
commit 42a10164ea
6 changed files with 381 additions and 294 deletions

396
electrum
View File

@ -62,13 +62,13 @@ options:
-b: show the balance of addresses""",
'history':"Shows the transaction history",
'label':'Assign a label to an item\nSyntax: label <tx_hash> <label>',
'setlabel':'Assign a label to an item\nSyntax: label <tx_hash> <label>',
'mktx':
"""Create a signed transaction, password protected.
Syntax: mktx <recipient> <amount> [label]
options:\n --fee, -f: set transaction fee\n --fromaddr, -s: send from address -\n --changeaddr, -c: send change to address
""",
'seed':
'get_seed':
"Print the generation seed of your wallet.",
'importprivkey':
'Import a private key\nSyntax: importprivkey <privatekey>',
@ -94,17 +94,18 @@ options:\n --fee, -f: set transaction fee\n --fromaddr, -s: send from address
'createrawtransaction':'similar to bitcoind\'s command',
'decoderawtransaction':'similar to bitcoind\'s command',
'signrawtransaction':'similar to bitcoind\'s command',
'get_history': 'get history for an address'
}
offline_commands = [ 'password', 'mktx',
'label', 'contacts',
'setlabel', 'contacts',
'help', 'validateaddress',
'signmessage', 'verifymessage',
'eval', 'set', 'get', 'create', 'addresses',
'importprivkey', 'seed',
'importprivkey', 'get_seed',
'deseed',
'freeze','unfreeze',
'prioritize','unprioritize',
@ -113,7 +114,6 @@ offline_commands = [ 'password', 'mktx',
]
protected_commands = ['payto', 'password', 'mktx', 'seed', 'importprivkey','signmessage', 'signrawtransaction','dumpprivkey' ]
# get password routine
def prompt_password(prompt, confirm=True):
@ -367,18 +367,6 @@ if __name__ == '__main__':
if password:
wallet.update_password(wallet.seed, None, password)
# check syntax
if cmd in ['payto', 'mktx']:
try:
to_address = args[1]
amount = int( 100000000 * Decimal(args[2]) )
change_addr = None
label = ' '.join(args[3:])
if options.tx_fee:
options.tx_fee = int( 100000000 * Decimal(options.tx_fee) )
except:
firstarg = cmd
cmd = 'help'
# open session
if cmd not in offline_commands and not options.offline:
@ -393,13 +381,7 @@ if __name__ == '__main__':
wallet.update()
wallet.save()
# check if --from_addr not in wallet (for mktx/payto)
is_temporary = False
from_addr = None
if options.from_addr:
from_addr = options.from_addr
if from_addr not in wallet.all_addresses():
is_temporary = True
# important warning
if cmd=='addresses' and options.show_keys:
@ -409,7 +391,7 @@ if __name__ == '__main__':
# commands needing password
if cmd in protected_commands or ( cmd=='addresses' and options.show_keys):
if wallet.use_encryption and not is_temporary:
if wallet.use_encryption:
password = prompt_password('Password:', False)
if not password:
print_msg("Error: Password required")
@ -423,20 +405,106 @@ if __name__ == '__main__':
else:
password = None
seed = wallet.seed
else:
password = None
# check and format the arguments
if cmd == 'importprivkey':
# See if they specificed a key on the cmd line, if not prompt
if len(args) > 1:
sec = args[1]
else:
sec = prompt_password('Enter PrivateKey (will not echo):', False)
try:
addr = wallet.import_key(sec,password)
wallet.save()
print_msg("Keypair imported: ", addr)
except BaseException as e:
print_msg("Error: Keypair import failed: " + str(e))
if len(args) == 1:
args[1] = prompt_password('Enter PrivateKey (will not echo):', False)
elif cmd == 'signmessage':
if len(args) < 3:
print_msg("Error: Invalid usage of signmessage.")
print_msg(known_commands[cmd])
sys.exit(1)
address = args[1]
message = ' '.join(args[2:])
if len(args) > 3:
print_msg("Warning: Message was reconstructed from several arguments:", repr(message))
args = [ cmd, address, message ]
elif cmd == 'verifymessage':
try:
address = args[1]
signature = args[2]
message = ' '.join(args[3:])
except:
print_msg("Error: Not all parameters were given, displaying help instead.")
print_msg(known_commands[cmd])
sys.exit(1)
if len(args) > 4:
print_msg("Warning: Message was reconstructed from several arguments:", repr(message))
args = [ cmd, address, signature, message]
elif cmd == 'signrawtransaction':
args = [ cmd, args[1], ast.literal_eval(args[2]) if len(args)>2 else [], ast.literal_eval(args[3]) if len(args)>3 else []]
elif cmd == 'createmultisig':
args = [ cmd, int(args[1]), ast.literal_eval(args[2])]
elif cmd == 'createrawtransaction':
args = [ cmd, ast.literal_eval(args[1]), ast.literal_eval(args[2])]
elif cmd == 'setlabel':
try:
tx = args[1]
label = ' '.join(args[2:])
except:
print_msg("Error. Syntax: label <tx_hash> <text>")
sys.exit(1)
args = [ cmd, tx, label ]
elif cmd in ['payto', 'mktx']:
#is_temporary = False
from_addr = None
if options.from_addr:
from_addr = options.from_addr
if from_addr not in wallet.all_addresses():
#is_temporary = True
raise BaseException("address not in wallet")
try:
to_address = args[1]
amount = Decimal(args[2])
change_addr = None
label = ' '.join(args[3:])
if options.tx_fee:
options.tx_fee = Decimal(options.tx_fee)
except:
firstarg = cmd
cmd = 'help'
#if from_addr and is_temporary:
# if from_addr.find(":") == -1:
# keypair = from_addr + ":" + prompt_password('Private key:', False)
# else:
# keypair = from_addr
# from_addr = keypair.split(':')[0]
# if not wallet.import_key(keypair,password):
# print_msg("Error: Invalid key pair")
# exit(1)
# wallet.history[from_addr] = interface.retrieve_history(from_addr)
# wallet.update_tx_history()
# change_addr = from_addr
if options.change_addr:
change_addr = options.change_addr
args = [ 'mktx', to_address, amount, options.tx_fee, options.change_addr, from_addr ]
#if is_temporary:
# wallet.imported_keys.pop(from_addr)
# del(wallet.history[from_addr])
#wallet.save()
# run the command
if cmd == 'help':
cmd2 = firstarg
if cmd2 not in known_commands:
@ -447,9 +515,6 @@ if __name__ == '__main__':
else:
print_msg(known_commands[cmd2])
elif cmd == 'seed':
print_msg(seed + ' "' + ' '.join(mnemonic_encode(seed)) + '"')
elif cmd == 'deseed':
if not wallet.seed:
print_msg("Error: This wallet has no seed")
@ -466,43 +531,6 @@ if __name__ == '__main__':
else:
print_msg("Action canceled.")
elif cmd == 'validateaddress':
addr = args[1]
is_valid = wallet.is_valid(addr)
out = { 'isvalid':is_valid }
if is_valid:
is_mine = wallet.is_mine(addr)
out['address'] = addr
out['ismine'] = is_mine
if is_mine:
out['pubkey'] = wallet.get_public_key(addr)
print_json(out)
elif cmd == 'balance':
try:
addrs = args[1:]
except:
pass
if addrs == []:
c, u = wallet.get_balance()
if u:
print_msg(Decimal( c ) / 100000000 , Decimal( u ) / 100000000)
else:
print_msg(Decimal( c ) / 100000000)
else:
for addr in addrs:
c, u = wallet.get_addr_balance(addr)
if u:
print_msg("%s %s, %s" % (addr, str(Decimal(c)/100000000), str(Decimal(u)/100000000)))
else:
print_msg("%s %s" % (addr, str(Decimal(c)/100000000)))
elif cmd in [ 'contacts']:
for addr in wallet.addressbook:
print_msg(addr, " ", wallet.labels.get(addr))
elif cmd == 'eval':
print_msg(eval(args[1]))
wallet.save()
@ -541,225 +569,19 @@ if __name__ == '__main__':
m_addr += ':' + str(wallet.get_private_key(addr, password))
print_msg(flags, m_addr, b, label)
if cmd == 'history':
import datetime
balance = 0
for item in wallet.get_tx_history():
tx_hash, conf, is_mine, value, fee, balance, timestamp = item
try:
time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3]
except:
time_str = "----"
label, is_default_label = wallet.get_label(tx_hash)
if not label: label = tx_hash
else: label = label + ' '*(64 - len(label) )
print_msg("%17s"%time_str, " " + label + " " + format_satoshis(value)+ " "+ format_satoshis(balance))
print_msg("# balance: ", format_satoshis(balance))
elif cmd == 'label':
try:
tx = args[1]
label = ' '.join(args[2:])
except:
print_msg("Error. Syntax: label <tx_hash> <text>")
sys.exit(1)
wallet.labels[tx] = label
wallet.save()
elif cmd in ['payto', 'mktx']:
if from_addr and is_temporary:
if from_addr.find(":") == -1:
keypair = from_addr + ":" + prompt_password('Private key:', False)
else:
keypair = from_addr
from_addr = keypair.split(':')[0]
if not wallet.import_key(keypair,password):
print_msg("Error: Invalid key pair")
exit(1)
wallet.history[from_addr] = interface.retrieve_history(from_addr)
wallet.update_tx_history()
change_addr = from_addr
if options.change_addr:
change_addr = options.change_addr
for k, v in wallet.labels.items():
if v == to_address:
to_address = k
print_msg("alias", to_address)
break
if change_addr and v == change_addr:
change_addr = k
try:
tx = wallet.mktx( [(to_address, amount)], label, password,
fee = options.tx_fee, change_addr = change_addr, from_addr = from_addr )
except:
import traceback
traceback.print_exc(file=sys.stdout)
tx = None
if tx and cmd=='payto':
r, h = wallet.sendtx( tx )
print_msg(h)
else:
out = {"hex":str(tx), "complete":tx.is_complete}
if not tx.is_complete:
import json
out['input_info'] = repr(tx.input_info).replace(' ','')
print_json(out)
if is_temporary:
wallet.imported_keys.pop(from_addr)
del(wallet.history[from_addr])
wallet.save()
elif cmd == 'sendrawtransaction':
tx = Transaction(args[1])
r, h = wallet.sendtx( tx )
print_msg(h)
elif cmd == 'password':
new_password = prompt_password('New password:')
wallet.update_password(seed, password, new_password)
elif cmd == 'signmessage':
if len(args) < 3:
print_msg("Error: Invalid usage of signmessage.")
print_msg(known_commands[cmd])
sys.exit(1)
address = args[1]
message = ' '.join(args[2:])
if len(args) > 3:
print_msg("Warning: Message was reconstructed from several arguments:", repr(message))
print_msg(wallet.sign_message(address, message, password))
elif cmd == 'verifymessage':
try:
address = args[1]
signature = args[2]
message = ' '.join(args[3:])
except:
print_msg("Error: Not all parameters were given, displaying help instead.")
print_msg(known_commands[cmd])
sys.exit(1)
if len(args) > 4:
print_msg("Warning: Message was reconstructed from several arguments:", repr(message))
EC_KEY.verify_message(address, signature, message)
try:
EC_KEY.verify_message(address, signature, message)
print_msg(True)
except BaseException as e:
print_error("Verification error: {0}".format(e))
print_msg(False)
elif cmd == 'freeze':
addr = args[1]
print_msg(wallet.freeze(addr))
elif cmd == 'unfreeze':
addr = args[1]
print_msg(wallet.unfreeze(addr))
elif cmd == 'prioritize':
addr = args[1]
print_msg(wallet.prioritize(addr))
elif cmd == 'unprioritize':
addr = args[1]
print_msg(wallet.unprioritize(addr))
elif cmd == 'dumpprivkey':
addr = args[1]
sec = wallet.get_private_key(addr, password)
print_msg( sec )
elif cmd == 'createmultisig':
num = int(args[1])
pubkeys = ast.literal_eval(args[2])
assert isinstance(pubkeys,list)
print_json( Transaction.multisig_script(pubkeys, num) )
elif cmd == 'createrawtransaction':
inputs = ast.literal_eval(args[1])
outputs = ast.literal_eval(args[2])
# convert to own format
for i in inputs:
i['tx_hash'] = i['txid']
i['index'] = i['vout']
outputs = map(lambda x: (x[0],int(1e8*x[1])), outputs.items())
tx = Transaction.from_io(inputs, outputs)
print_msg( tx )
elif cmd == 'decoderawtransaction':
tx = Transaction(args[1])
print_json( tx.deserialize() )
elif cmd == 'signrawtransaction':
tx = Transaction(args[1])
input_info = ast.literal_eval(args[2]) if len(args)>2 else []
private_keys = ast.literal_eval(args[3]) if len(args)>3 else []
unspent_coins = wallet.get_unspent_coins()
# convert private_keys to dict
pk = {}
for sec in private_keys:
address = bitcoin.address_from_private_key(sec)
pk[address] = sec
private_keys = pk
for txin in tx.inputs:
# convert to own format
txin['tx_hash'] = txin['prevout_hash']
txin['index'] = txin['prevout_n']
for item in input_info:
if item.get('txid') == txin['tx_hash'] and item.get('vout') == txin['index']:
txin['raw_output_script'] = item['scriptPubKey']
txin['redeemScript'] = item.get('redeemScript')
txin['electrumKeyID'] = item.get('electrumKeyID')
break
else:
for item in unspent_coins:
if txin['tx_hash'] == item['tx_hash'] and txin['index'] == item['index']:
txin['raw_output_script'] = item['raw_output_script']
break
else:
# if neither, we might want to get it from the server..
raise
# find the address:
from lib import deserialize
if txin.get('electrumKeyID'):
n, for_change = txin.get('electrumKeyID')
sec = wallet.sequence.get_private_key(n, for_change, seed)
address = bitcoin.address_from_private_key(sec)
txin['address'] = address
private_keys[address] = sec
elif txin.get("redeemScript"):
txin['address'] = bitcoin.hash_160_to_bc_address(bitcoin.hash_160(txin.get("redeemScript").decode('hex')), 5)
elif txin.get("raw_output_script"):
addr = deserialize.get_address_from_output_script(txin.get("raw_output_script").decode('hex'))
sec = wallet.get_private_key(addr, password)
if sec:
private_keys[addr] = sec
txin['address'] = addr
tx.sign( private_keys )
print_json({ "hex":str(tx),"complete":tx.is_complete})
elif cmd == 'listunspent':
print_json(wallet.get_unspent_coins())
else:
cmd_runner = Commands(wallet, interface)
func = eval('cmd_runner.' + cmd)
if password:
args.append( password )
func(*args[1:])
if cmd not in offline_commands and not options.offline:

View File

@ -10,3 +10,4 @@ import bitcoin
from bitcoin import Transaction, EC_KEY
from mnemonic import mn_encode as mnemonic_encode
from mnemonic import mn_decode as mnemonic_decode
from commands import protected_commands, Commands

View File

@ -481,7 +481,7 @@ class Transaction:
self.outputs = outputs
extras = []
for i in self.inputs:
e = { 'txid':i['tx_hash'], 'vout':i['index'],'scriptPubKey':i['raw_output_script'] }
e = { 'txid':i['tx_hash'], 'vout':i['index'], 'scriptPubKey':i.get('raw_output_script') }
extras.append(e)
self.input_info = extras
return self

254
lib/commands.py Normal file
View File

@ -0,0 +1,254 @@
#!/usr/bin/env python
#
# Electrum - lightweight Bitcoin client
# Copyright (C) 2011 thomasv@gitorious
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from util import *
from bitcoin import *
from decimal import Decimal
import bitcoin
protected_commands = ['payto', 'password', 'mktx', 'get_seed', 'importprivkey','signmessage', 'signrawtransaction','dumpprivkey' ]
class Commands:
def __init__(self, wallet, interface):
self.wallet = wallet
self.interface = interface
def _run(self, method, args, password_getter):
if method in protected_commands:
pw = apply(password_getter,())
args += (pw,)
f = eval('self.'+method)
apply(f,args)
def get_history(self, addr):
h = self.wallet.get_history(addr)
if h is None: h = self.wallet.interface.synchronous_get([ ('blockchain.address.get_history',[addr]) ])[0]
print_json(h)
def listunspent(self):
print_json(self.wallet.get_unspent_coins())
def createrawtransaction(self, inputs, outputs):
# convert to own format
for i in inputs:
i['tx_hash'] = i['txid']
i['index'] = i['vout']
outputs = map(lambda x: (x[0],int(1e8*x[1])), outputs.items())
tx = Transaction.from_io(inputs, outputs)
print_msg( tx )
def signrawtransaction(self, raw_tx, input_info, private_keys, password):
tx = Transaction(raw_tx)
unspent_coins = self.wallet.get_unspent_coins()
# convert private_keys to dict
pk = {}
for sec in private_keys:
address = bitcoin.address_from_private_key(sec)
pk[address] = sec
private_keys = pk
for txin in tx.inputs:
# convert to own format
txin['tx_hash'] = txin['prevout_hash']
txin['index'] = txin['prevout_n']
for item in input_info:
if item.get('txid') == txin['tx_hash'] and item.get('vout') == txin['index']:
txin['raw_output_script'] = item['scriptPubKey']
txin['redeemScript'] = item.get('redeemScript')
txin['electrumKeyID'] = item.get('electrumKeyID')
break
else:
for item in unspent_coins:
if txin['tx_hash'] == item['tx_hash'] and txin['index'] == item['index']:
txin['raw_output_script'] = item['raw_output_script']
break
else:
# if neither, we might want to get it from the server..
raise
# find the address:
import deserialize
if txin.get('electrumKeyID'):
n, for_change = txin.get('electrumKeyID')
sec = wallet.sequence.get_private_key(n, for_change, seed)
address = bitcoin.address_from_private_key(sec)
txin['address'] = address
private_keys[address] = sec
elif txin.get("redeemScript"):
txin['address'] = bitcoin.hash_160_to_bc_address(bitcoin.hash_160(txin.get("redeemScript").decode('hex')), 5)
elif txin.get("raw_output_script"):
addr = deserialize.get_address_from_output_script(txin.get("raw_output_script").decode('hex'))
sec = wallet.get_private_key(addr, password)
if sec:
private_keys[addr] = sec
txin['address'] = addr
tx.sign( private_keys )
print_json({ "hex":str(tx),"complete":tx.is_complete})
def decoderawtransaction(self, raw):
tx = Transaction(raw)
print_json( tx.deserialize() )
def sendrawtransaction(self, raw):
tx = Transaction(raw)
r, h = wallet.sendtx( tx )
print_msg(h)
def createmultisig(self, num, pubkeys):
assert isinstance(pubkeys, list)
print_json( Transaction.multisig_script(pubkeys, num) )
def freeze(self,addr):
print_msg(self.wallet.freeze(addr))
def unfreeze(self,addr):
print_msg(self.wallet.unfreeze(addr))
def prioritize(self, addr):
print_msg(self.wallet.prioritize(addr))
def unprioritize(self, addr):
print_msg(self.wallet.unprioritize(addr))
def dumpprivkey(self, addr, password):
sec = self.wallet.get_private_key(addr, password)
print_msg( sec )
def validateaddress(self,addr):
is_valid = self.wallet.is_valid(addr)
out = { 'isvalid':is_valid }
if is_valid:
is_mine = self.wallet.is_mine(addr)
out['address'] = addr
out['ismine'] = is_mine
if is_mine:
out['pubkey'] = self.wallet.get_public_key(addr)
print_json(out)
def balance(self, addresses = []):
if addresses == []:
c, u = self.wallet.get_balance()
if u:
print_msg(Decimal( c ) / 100000000 , Decimal( u ) / 100000000)
else:
print_msg(Decimal( c ) / 100000000)
else:
for addr in addresses:
c, u = wallet.get_addr_balance(addr)
if u:
print_msg("%s %s, %s" % (addr, str(Decimal(c)/100000000), str(Decimal(u)/100000000)))
else:
print_msg("%s %s" % (addr, str(Decimal(c)/100000000)))
def get_seed(self, password):
import mnemonic
seed = self.wallet.decode_seed(password)
print_msg(seed + ' "' + ' '.join(mnemonic.mn_encode(seed)) + '"')
def importprivkey(self, sec):
try:
addr = wallet.import_key(sec,password)
wallet.save()
print_msg("Keypair imported: ", addr)
except BaseException as e:
print_msg("Error: Keypair import failed: " + str(e))
def sign_message(self, address, message, password):
print_msg(self.wallet.sign_message(address, message, password))
def verify_message(self, address, signature, message):
try:
EC_KEY.verify_message(address, signature, message)
print_msg(True)
except BaseException as e:
print_error("Verification error: {0}".format(e))
print_msg(False)
def mktx(self, to_address, amount, fee, change_addr, from_addr, password = None):
for k, v in self.wallet.labels.items():
if v == to_address:
to_address = k
print_msg("alias", to_address)
break
if change_addr and v == change_addr:
change_addr = k
amount = int(10000000*amount)
if fee: fee = int(10000000*fee)
tx = self.wallet.mktx( [(to_address, amount)], password, fee , change_addr, from_addr)
out = {"hex":str(tx), "complete":tx.is_complete}
if not tx.is_complete:
import json
out['input_info'] = repr(tx.input_info).replace(' ','')
print_json(out)
def payto(self, to_address, amount, fee, change_addr, from_addr, password = None):
amount = int(10000000*amount)
if fee: fee = int(10000000*fee)
tx = self.wallet.mktx( [(to_address, amount)], password, fee, change_addr, from_addr )
r, h = wallet.sendtx( tx )
print_msg(h)
def history(self):
import datetime
balance = 0
for item in self.wallet.get_tx_history():
tx_hash, conf, is_mine, value, fee, balance, timestamp = item
try:
time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3]
except:
time_str = "----"
label, is_default_label = self.wallet.get_label(tx_hash)
if not label: label = tx_hash
else: label = label + ' '*(64 - len(label) )
print_msg("%17s"%time_str, " " + label + " " + format_satoshis(value)+ " "+ format_satoshis(balance))
print_msg("# balance: ", format_satoshis(balance))
def setlabel(self, tx, label):
self.wallet.labels[tx] = label
self.wallet.save()
def contacts(self):
c = {}
for addr in self.wallet.addressbook:
c[addr] = self.wallet.labels.get(addr)
print_json(c)

View File

@ -413,7 +413,7 @@ class ElectrumWindow(QMainWindow):
tabs.addTab(self.create_send_tab(), _('Send') )
tabs.addTab(self.create_receive_tab(), _('Receive') )
tabs.addTab(self.create_contacts_tab(), _('Contacts') )
tabs.addTab(self.create_wall_tab(), _('Console') )
tabs.addTab(self.create_console_tab(), _('Console') )
tabs.setMinimumSize(600, 400)
tabs.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.setCentralWidget(tabs)
@ -1263,12 +1263,22 @@ class ElectrumWindow(QMainWindow):
l.setCurrentItem(l.topLevelItem(0))
def create_wall_tab(self):
def create_console_tab(self):
from qt_console import Console
import util, bitcoin
import util, bitcoin, commands
self.console = console = Console()
console.updateNamespace({'wallet' : self.wallet, 'interface' : self.wallet.interface, 'gui':self})
console.updateNamespace({'util' : util, 'bitcoin':bitcoin})
c = commands.Commands(self.wallet, self.wallet.interface)
methods = {}
def mkfunc(f, method):
return lambda *args: apply( f, (method, args, self.password_dialog ))
for m in dir(c):
if m[0]=='_' or m=='wallet' or m == 'interface': continue
methods[m] = mkfunc(c._run, m)
console.updateNamespace(methods)
return console

View File

@ -652,7 +652,7 @@ class Wallet:
return default_label
def mktx(self, outputs, label, password, fee=None, change_addr=None, from_addr= None):
def mktx(self, outputs, password, fee=None, change_addr=None, from_addr= None):
for address, x in outputs:
assert self.is_valid(address)
@ -682,8 +682,8 @@ class Wallet:
if address not in self.addressbook and not self.is_mine(address):
self.addressbook.append(address)
if label:
self.labels[tx.hash()] = label
#if label:
# self.labels[tx.hash()] = label
return tx