from bitcoin import *
from decimal import Decimal
import bitcoin
-
+from transaction import Transaction
class Command:
def __init__(self, name, min_args, max_args, requires_network, requires_wallet, requires_password, description, syntax = '', options_syntax = ''):
-payto_options = ' --fee, -f: set transaction fee\n --fromaddr, -s: send from address -\n --changeaddr, -c: send change to address'
-listaddr_options = " -a: show all addresses, including change addresses\n -b: include balance in results\n -l: include labels in results"
+payto_options = ' --fee, -f: set transaction fee\n --fromaddr, -F: send from address -\n --changeaddr, -c: send change to address'
+listaddr_options = " -a: show all addresses, including change addresses\n -l: include labels in results"
restore_options = " accepts a seed or master public key."
config_options = " accounts, addr_history, auto_cycle, column_widths, console-history, contacts,\n fee_per_kb, frozen_addresses, gap_limit, imported_keys, labels,\n master_public_key, num_zeros, prioritized_addresses, proxy, seed,\n seed_version, server, transactions, use_change, use_encryption, winpos-qt"
mksendmany_syntax = 'mksendmanytx <recipient> <amount> [<recipient> <amount> ...]'
register_command('getbalance', 0, 1, True, True, False, 'Return the balance of your wallet, or of one account in your wallet', 'getbalance [<account>]')
register_command('getservers', 0, 0, True, False, False, 'Return the list of available servers')
register_command('getaddressbalance', 1, 1, True, True, False, 'Return the balance of an address', 'getbalance <address>')
-register_command('getaddresshistory', 1, 1, True, False, False, 'Return the transaction history of an address', 'getaddresshistory <address>')
+register_command('getaddresshistory', 1, 1, True, True, False, 'Return the transaction history of a wallet address', 'getaddresshistory <address>')
register_command('getconfig', 1, 1, False, False, False, 'Return a configuration variable', 'getconfig <name>', config_options)
+register_command('getpubkeys', 1, 1, False, True, False, 'Return the public keys for a wallet address', 'getpubkeys <bitcoin address>')
register_command('getrawtransaction', 1, 2, True, False, False, 'Retrieve a transaction', 'getrawtransaction <txhash> <height>')
register_command('getseed', 0, 0, False, True, True, 'Print the generation seed of your wallet.')
+register_command('getmpk', 0, 0, False, True, False, 'Return your wallet\'s master public key', 'getmpk')
register_command('help', 0, 1, False, False, False, 'Prints this help')
register_command('history', 0, 0, True, True, False, 'Returns the transaction history of your wallet')
register_command('importprivkey', 1, 1, False, True, True, 'Import a private key', 'importprivkey <privatekey>')
-register_command('listaddresses', 3, 3, False, True, False, 'Returns your list of addresses.', '', listaddr_options)
+register_command('listaddresses', 2, 2, False, True, False, 'Returns your list of addresses.', '', listaddr_options)
register_command('listunspent', 0, 0, True, True, False, 'Returns the list of unspent inputs in your wallet.')
register_command('mktx', 5, 5, False, True, True, 'Create a signed transaction', 'mktx <recipient> <amount> [label]', payto_options)
register_command('mksendmanytx', 4, 4, False, True, True, 'Create a signed transaction', mksendmany_syntax, payto_options)
return result
def getaddresshistory(self, addr):
+ assert self.wallet.is_mine(addr)
h = self.wallet.get_history(addr)
if h is None: h = self.network.synchronous_get([ ('blockchain.address.get_history',[addr]) ])[0]
return h
addresses = self.wallet.addresses(True)
return [self.wallet.get_private_key(address, self.password) for address in addresses]
- def validateaddress(self,addr):
+ def validateaddress(self, addr):
isvalid = is_valid(addr)
out = { 'isvalid':isvalid }
if isvalid:
- is_mine = self.wallet.is_mine(addr)
out['address'] = addr
- out['ismine'] = is_mine
- if is_mine:
- account, sequence = self.wallet.get_address_index(addr)
- if account != -1:
- out['pubkey'] = self.wallet.get_public_key(addr)
+
+ def getpubkeys(self, addr):
+ assert is_valid(addr) and self.wallet.is_mine(addr)
+ out = { 'address':addr }
+ account, sequence = self.wallet.get_address_index(addr)
+ if account != -1:
+ a = self.wallet.accounts[account]
+ out['pubkeys'] = a.get_pubkeys( sequence )
+
return out
def getbalance(self, account= None):
def getservers(self):
return self.network.get_servers()
+ def getmpk(self):
+ return self.wallet.get_master_public_key()
+
def getseed(self):
- import mnemonic
- seed = self.wallet.decode_seed(self.password)
- return { "hex":seed, "mnemonic": ' '.join(mnemonic.mn_encode(seed)) }
+ mnemonic = self.wallet.get_mnemonic(self.password)
+ seed = self.wallet.get_seed(self.password)
+ return { 'mnemonic':mnemonic, 'seed':seed, 'version':self.wallet.seed_version }
def importprivkey(self, sec):
try:
def verifymessage(self, address, signature, message):
- return self.wallet.verify_message(address, signature, message)
+ return bitcoin.verify_message(address, signature, message)
def _mktx(self, outputs, fee = None, change_addr = None, domain = None):
return c
- def listaddresses(self, show_all = False, show_balance = False, show_label = False):
+ def listaddresses(self, show_all = False, show_label = False):
out = []
for addr in self.wallet.addresses(True):
if show_all or not self.wallet.is_change(addr):
- if show_balance or show_label:
+ if show_label:
item = { 'address': addr }
- if show_balance:
- item['balance'] = str(Decimal(self.wallet.get_addr_balance(addr)[0])/100000000)
if show_label:
label = self.wallet.labels.get(addr,'')
if label:
out.append( item )
return out
- def help(self, cmd2=None):
- if cmd2 not in known_commands:
+ def help(self, cmd=None):
+ if cmd not in known_commands:
print_msg("\nList of commands:", ', '.join(sorted(known_commands)))
else:
- _, _, description, syntax, options_syntax = known_commands[cmd2]
- print_msg(description)
- if syntax: print_msg("Syntax: " + syntax)
- if options_syntax: print_msg("options:\n" + options_syntax)
+ cmd = known_commands[cmd]
+ print_msg(cmd.description)
+ if cmd.syntax: print_msg("Syntax: " + cmd.syntax)
+ if cmd.options: print_msg("options:\n" + cmd.options)
return None
def getrawtransaction(self, tx_hash, height = 0):