示例#1
0
 def sign_tx(self,
             psbt='',
             device_type=None,
             path=None,
             fingerprint=None,
             passphrase='',
             chain=''):
     if psbt == '':
         raise Exception("PSBT must not be empty")
     client = self._get_client(device_type=device_type,
                               fingerprint=fingerprint,
                               path=path,
                               passphrase=passphrase,
                               chain=chain)
     try:
         status = hwi_commands.signtx(client, psbt)
         client.close()
         if 'error' in status:
             raise Exception(status['error'])
         elif 'psbt' in status:
             return status['psbt']
         else:
             raise Exception(
                 "Failed to sign transaction with device: Unknown Error")
     except Exception as e:
         if client:
             client.close()
         raise e
示例#2
0
 def sign_tx(
     self,
     psbt="",
     device_type=None,
     path=None,
     fingerprint=None,
     passphrase="",
     chain="",
 ):
     if psbt == "":
         raise Exception("PSBT must not be empty")
     with self._get_client(
             device_type=device_type,
             fingerprint=fingerprint,
             path=path,
             passphrase=passphrase,
             chain=chain,
     ) as client:
         status = hwi_commands.signtx(client, psbt)
         if "error" in status:
             raise Exception(status["error"])
         elif "psbt" in status:
             return status["psbt"]
         else:
             raise Exception(
                 "Failed to sign transaction with device: Unknown Error")
示例#3
0
def hwi_sign_tx():
    type = request.form.get("type")
    path = request.form.get("path")
    passphrase = request.form.get("passphrase")
    psbt = request.form.get("psbt")

    try:
        client = get_hwi_client(type, path, passphrase=passphrase)
        status = hwilib_commands.signtx(client, psbt)
        print(status)

        # Do proper cleanup otherwise have to reconnect device to access again
        client.close()

        return jsonify(status)
    except Exception as e:
        print(e)
        if client:
            try:
                client.close()
            except Exception:
                # We tried...
                pass

        return jsonify(success=False, error=str(e))