Browse Source

getpubkeys command

master
ThomasV 12 years ago
parent
commit
6f2471b69b
  1. 4
      electrum
  2. 8
      lib/account.py
  3. 27
      lib/commands.py
  4. 4
      lib/wallet.py

4
electrum

@ -320,12 +320,12 @@ if __name__ == '__main__':
# check the number of arguments # check the number of arguments
if len(args) - 1 < cmd.min_args: if len(args) - 1 < cmd.min_args:
print_msg("Not enough arguments") print_msg("Not enough arguments")
print_msg("Syntax:", syntax) print_msg("Syntax:", cmd.syntax)
sys.exit(1) sys.exit(1)
if cmd.max_args >= 0 and len(args) - 1 > cmd.max_args: if cmd.max_args >= 0 and len(args) - 1 > cmd.max_args:
print_msg("too many arguments", args) print_msg("too many arguments", args)
print_msg("Syntax:", syntax) print_msg("Syntax:", cmd.syntax)
sys.exit(1) sys.exit(1)
if cmd.max_args < 0: if cmd.max_args < 0:

8
lib/account.py

@ -42,6 +42,8 @@ class Account(object):
def get_address(self, for_change, n): def get_address(self, for_change, n):
pass pass
def get_pubkeys(self, sequence):
return [ self.get_pubkey( *sequence )]
@ -182,6 +184,8 @@ class BIP32_Account_2of2(BIP32_Account):
address = hash_160_to_bc_address(hash_160(self.redeem_script((for_change, n)).decode('hex')), 5) address = hash_160_to_bc_address(hash_160(self.redeem_script((for_change, n)).decode('hex')), 5)
return address return address
def get_pubkeys(self, sequence):
return [ self.get_pubkey( *sequence ), self.get_pubkey2( *sequence )]
class BIP32_Account_2of3(BIP32_Account_2of2): class BIP32_Account_2of3(BIP32_Account_2of2):
@ -212,4 +216,8 @@ class BIP32_Account_2of3(BIP32_Account_2of2):
pubkey3 = self.get_pubkey3(chain, i) pubkey3 = self.get_pubkey3(chain, i)
return Transaction.multisig_script([pubkey1, pubkey2, pubkey3], 3) return Transaction.multisig_script([pubkey1, pubkey2, pubkey3], 3)
def get_pubkeys(self, sequence):
return [ self.get_pubkey( *sequence ), self.get_pubkey2( *sequence ), self.get_pubkey3( *sequence )]

27
lib/commands.py

@ -69,8 +69,9 @@ register_command('freeze', 1, 1, False, True, True, 'Freeze the
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('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('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('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('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('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('getseed', 0, 0, False, True, True, 'Print the generation seed of your wallet.')
register_command('help', 0, 1, False, False, False, 'Prints this help') register_command('help', 0, 1, False, False, False, 'Prints this help')
@ -118,6 +119,7 @@ class Commands:
return result return result
def getaddresshistory(self, addr): def getaddresshistory(self, addr):
assert self.wallet.is_mine(addr)
h = self.wallet.get_history(addr) h = self.wallet.get_history(addr)
if h is None: h = self.network.synchronous_get([ ('blockchain.address.get_history',[addr]) ])[0] if h is None: h = self.network.synchronous_get([ ('blockchain.address.get_history',[addr]) ])[0]
return h return h
@ -181,13 +183,16 @@ class Commands:
isvalid = is_valid(addr) isvalid = is_valid(addr)
out = { 'isvalid':isvalid } out = { 'isvalid':isvalid }
if isvalid: if isvalid:
is_mine = self.wallet.is_mine(addr)
out['address'] = addr out['address'] = addr
out['ismine'] = is_mine
if is_mine: 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) account, sequence = self.wallet.get_address_index(addr)
if account != -1: if account != -1:
out['pubkey'] = self.wallet.get_public_key(addr) a = self.wallet.accounts[account]
out['pubkeys'] = a.get_pubkeys( sequence )
return out return out
def getbalance(self, account= None): def getbalance(self, account= None):
@ -337,14 +342,14 @@ class Commands:
out.append( item ) out.append( item )
return out return out
def help(self, cmd2=None): def help(self, cmd=None):
if cmd2 not in known_commands: if cmd not in known_commands:
print_msg("\nList of commands:", ', '.join(sorted(known_commands))) print_msg("\nList of commands:", ', '.join(sorted(known_commands)))
else: else:
_, _, description, syntax, options_syntax = known_commands[cmd2] cmd = known_commands[cmd]
print_msg(description) print_msg(cmd.description)
if syntax: print_msg("Syntax: " + syntax) if cmd.syntax: print_msg("Syntax: " + cmd.syntax)
if options_syntax: print_msg("options:\n" + options_syntax) if cmd.options: print_msg("options:\n" + cmd.options)
return None return None
def getrawtransaction(self, tx_hash, height = 0): def getrawtransaction(self, tx_hash, height = 0):

4
lib/wallet.py

@ -555,10 +555,6 @@ class Wallet:
return '&'.join(dd) return '&'.join(dd)
def get_public_key(self, address):
account, sequence = self.get_address_index(address)
return self.accounts[account].get_pubkey( *sequence )
def decode_seed(self, password): def decode_seed(self, password):
seed = pw_decode(self.seed, password) seed = pw_decode(self.seed, password)

Loading…
Cancel
Save