Merge pull request #3335 from SomberNight/cmd_getprivkeys

more robust getprivatekeys() and is_segwit_address()
This commit is contained in:
ThomasV 2017-11-23 10:03:18 +01:00 committed by GitHub
commit 9edffd1754
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -569,7 +569,10 @@ def address_from_private_key(sec):
return pubkey_to_address(txin_type, public_key) return pubkey_to_address(txin_type, public_key)
def is_segwit_address(addr): def is_segwit_address(addr):
witver, witprog = segwit_addr.decode(NetworkConstants.SEGWIT_HRP, addr) try:
witver, witprog = segwit_addr.decode(NetworkConstants.SEGWIT_HRP, addr)
except Exception as e:
return False
return witprog is not None return witprog is not None
def is_b58_address(addr): def is_b58_address(addr):

View File

@ -273,6 +273,8 @@ class Commands:
@command('wp') @command('wp')
def getprivatekeys(self, address, password=None): def getprivatekeys(self, address, password=None):
"""Get private keys of addresses. You may pass a single wallet address, or a list of wallet addresses.""" """Get private keys of addresses. You may pass a single wallet address, or a list of wallet addresses."""
if isinstance(address, str):
address = address.strip()
if is_address(address): if is_address(address):
return self.wallet.export_private_key(address, password)[0] return self.wallet.export_private_key(address, password)[0]
domain = address domain = address