Provide error codes in enumerate output

This commit is contained in:
Andrew Chow 2019-05-21 17:19:56 -04:00
parent c14896c6eb
commit 129e91d9f0
5 changed files with 25 additions and 4 deletions

View File

@ -1,7 +1,7 @@
# Coldcard interaction script # Coldcard interaction script
from ..hwwclient import HardwareWalletClient from ..hwwclient import HardwareWalletClient
from ..errors import ActionCanceledError, BadArgumentError, DeviceBusyError, UnavailableActionError, DeviceFailureError from ..errors import ActionCanceledError, BadArgumentError, DeviceBusyError, DeviceFailureError, HWWError, UnavailableActionError, UNKNOWN_ERROR
from .ckcc.client import ColdcardDevice, COINKITE_VID, CKCC_PID from .ckcc.client import ColdcardDevice, COINKITE_VID, CKCC_PID
from .ckcc.protocol import CCProtocolPacker, CCBusyError, CCProtoError, CCUserRefused from .ckcc.protocol import CCProtocolPacker, CCBusyError, CCProtoError, CCUserRefused
from .ckcc.constants import MAX_BLK_LEN, AF_P2WPKH, AF_CLASSIC, AF_P2WPKH_P2SH from .ckcc.constants import MAX_BLK_LEN, AF_P2WPKH, AF_CLASSIC, AF_P2WPKH_P2SH
@ -230,8 +230,12 @@ def enumerate(password=''):
try: try:
client = ColdcardClient(path) client = ColdcardClient(path)
d_data['fingerprint'] = client._get_fingerprint_hex() d_data['fingerprint'] = client._get_fingerprint_hex()
except HWWError as e:
d_data['error'] = "Could not open client or get fingerprint information: " + e.get_msg()
d_data['code'] = e.get_code()
except Exception as e: except Exception as e:
d_data['error'] = "Could not open client or get fingerprint information: " + str(e) d_data['error'] = "Could not open client or get fingerprint information: " + str(e)
d_data['code'] = UNKNOWN_ERROR
if client: if client:
client.close() client.close()

View File

@ -15,7 +15,7 @@ import sys
import time import time
from ..hwwclient import HardwareWalletClient from ..hwwclient import HardwareWalletClient
from ..errors import ActionCanceledError, BadArgumentError, DeviceFailureError, DeviceAlreadyInitError, DeviceNotReadyError, NoPasswordError, UnavailableActionError, DeviceFailureError from ..errors import ActionCanceledError, BadArgumentError, DeviceFailureError, DeviceAlreadyInitError, DeviceNotReadyError, HWWError, NoPasswordError, UnavailableActionError, UNKNOWN_ERROR
from ..serializations import CTransaction, PSBT, hash256, hash160, ser_sig_der, ser_sig_compact, ser_compact_size from ..serializations import CTransaction, PSBT, hash256, hash160, ser_sig_der, ser_sig_compact, ser_compact_size
from ..base58 import get_xpub_fingerprint, decode, to_address, xpub_main_2_test, get_xpub_fingerprint_hex from ..base58 import get_xpub_fingerprint, decode, to_address, xpub_main_2_test, get_xpub_fingerprint_hex
@ -603,8 +603,12 @@ def enumerate(password=''):
else: else:
master_xpub = client.get_pubkey_at_path('m/0h')['xpub'] master_xpub = client.get_pubkey_at_path('m/0h')['xpub']
d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub) d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub)
except HWWError as e:
d_data['error'] = "Could not open client or get fingerprint information: " + e.get_msg()
d_data['code'] = e.get_code()
except Exception as e: except Exception as e:
d_data['error'] = "Could not open client or get fingerprint information: " + str(e) d_data['error'] = "Could not open client or get fingerprint information: " + str(e)
d_data['code'] = UNKNOWN_ERROR
if client: if client:
client.close() client.close()

View File

@ -1,5 +1,6 @@
# KeepKey interaction script # KeepKey interaction script
from ..errors import HWWError, UNKNOWN_ERROR
from .trezorlib.transport import enumerate_devices from .trezorlib.transport import enumerate_devices
from .trezor import TrezorClient from .trezor import TrezorClient
from ..base58 import get_xpub_fingerprint_hex from ..base58 import get_xpub_fingerprint_hex
@ -30,8 +31,12 @@ def enumerate(password=''):
d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub) d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub)
else: else:
d_data['error'] = 'Not initialized' d_data['error'] = 'Not initialized'
except HWWError as e:
d_data['error'] = "Could not open client or get fingerprint information: " + e.get_msg()
d_data['code'] = e.get_code()
except Exception as e: except Exception as e:
d_data['error'] = "Could not open client or get fingerprint information: " + str(e) d_data['error'] = "Could not open client or get fingerprint information: " + str(e)
d_data['code'] = UNKNOWN_ERROR
if client: if client:
client.close() client.close()

View File

@ -1,7 +1,7 @@
# Ledger interaction script # Ledger interaction script
from ..hwwclient import HardwareWalletClient from ..hwwclient import HardwareWalletClient
from ..errors import ActionCanceledError, BadArgumentError, DeviceConnectionError, DeviceFailureError, UnavailableActionError from ..errors import ActionCanceledError, BadArgumentError, DeviceConnectionError, DeviceFailureError, HWWError, UnavailableActionError, UNKNOWN_ERROR
from .btchip.btchip import * from .btchip.btchip import *
from .btchip.btchipUtils import * from .btchip.btchipUtils import *
import base64 import base64
@ -350,8 +350,12 @@ def enumerate(password=''):
client = LedgerClient(path, password) client = LedgerClient(path, password)
master_xpub = client.get_pubkey_at_path('m/0h')['xpub'] master_xpub = client.get_pubkey_at_path('m/0h')['xpub']
d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub) d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub)
except HWWError as e:
d_data['error'] = "Could not open client or get fingerprint information: " + e.get_msg()
d_data['code'] = e.get_code()
except Exception as e: except Exception as e:
d_data['error'] = "Could not open client or get fingerprint information: " + str(e) d_data['error'] = "Could not open client or get fingerprint information: " + str(e)
d_data['code'] = UNKNOWN_ERROR
if client: if client:
client.close() client.close()

View File

@ -1,7 +1,7 @@
# Trezor interaction script # Trezor interaction script
from ..hwwclient import HardwareWalletClient from ..hwwclient import HardwareWalletClient
from ..errors import ActionCanceledError, BadArgumentError, DeviceAlreadyInitError, DeviceAlreadyUnlockedError, DeviceConnectionError, UnavailableActionError, DeviceNotReadyError from ..errors import ActionCanceledError, BadArgumentError, DeviceAlreadyInitError, DeviceAlreadyUnlockedError, DeviceConnectionError, DeviceNotReadyError, HWWError, UnavailableActionError, UNKNOWN_ERROR
from .trezorlib.client import TrezorClient as Trezor from .trezorlib.client import TrezorClient as Trezor
from .trezorlib.debuglink import TrezorClientDebugLink, DebugUI from .trezorlib.debuglink import TrezorClientDebugLink, DebugUI
from .trezorlib.exceptions import Cancelled from .trezorlib.exceptions import Cancelled
@ -426,8 +426,12 @@ def enumerate(password=''):
d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub) d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub)
else: else:
d_data['error'] = 'Not initialized' d_data['error'] = 'Not initialized'
except HWWError as e:
d_data['error'] = "Could not open client or get fingerprint information: " + e.get_msg()
d_data['code'] = e.get_code()
except Exception as e: except Exception as e:
d_data['error'] = "Could not open client or get fingerprint information: " + str(e) d_data['error'] = "Could not open client or get fingerprint information: " + str(e)
d_data['code'] = UNKNOWN_ERROR
if client: if client:
client.close() client.close()