示例#1
0
 def on_qr(self, data):
     from electrum.bitcoin import base_decode, is_address
     data = data.strip()
     if is_address(data):
         self.set_URI(data)
         return
     if data.startswith('bitcoin:'):
         self.set_URI(data)
         return
     # try to decode transaction
     from electrum.transaction import Transaction
     from electrum.util import bh2u
     try:
         text = bh2u(base_decode(data, None, base=43))
         tx = Transaction(text)
         tx.deserialize()
     except:
         tx = None
     if tx:
         self.tx_dialog(tx)
         return
     # show error
     self.show_error("Unable to decode QR data")
示例#2
0
 def do_paste(self):
     data = self.app._clipboard.paste().strip()
     if not data:
         self.app.show_info(_("Clipboard is empty"))
         return
     # try to decode as transaction
     try:
         raw_tx = tx_from_str(data)
         tx = Transaction(raw_tx)
         tx.deserialize()
     except:
         tx = None
     if tx:
         self.app.tx_dialog(tx)
         return
     lower = data.lower()
     if lower.startswith('lightning:ln'):
         lower = lower[10:]
     # try to decode as URI/address
     if lower.startswith('ln'):
         self.set_ln_invoice(lower)
     else:
         self.set_URI(data)
示例#3
0
 def on_otp(self, tx: PartialTransaction, otp):
     if not otp:
         self.logger.info("sign_transaction: no auth code")
         return
     otp = int(otp)
     long_user_id, short_id = self.get_user_id()
     raw_tx = tx.serialize_as_bytes().hex()
     assert raw_tx[:10] == "70736274ff", f"bad magic. {raw_tx[:10]}"
     try:
         r = server.sign(short_id, raw_tx, otp)
     except TrustedCoinException as e:
         if e.status_code == 400:  # invalid OTP
             raise UserFacingException(_('Invalid one-time password.')) from e
         else:
             raise
     if r:
         received_raw_tx = r.get('transaction')
         received_tx = Transaction(received_raw_tx)
         tx.combine_with_other_psbt(received_tx)
     self.logger.info(f"twofactor: is complete {tx.is_complete()}")
     # reset billing_info
     self.billing_info = None
     self.plugin.start_request_thread(self)
示例#4
0
 def test_extract_commitment_number_from_tx(self):
     raw_tx = "02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8007e80300000000000022002052bfef0479d7b293c27e0f1eb294bea154c63a3294ef092c19af51409bce0e2ad007000000000000220020403d394747cae42e98ff01734ad5c08f82ba123d3d9a620abda88989651e2ab5d007000000000000220020748eba944fedc8827f6b06bc44678f93c0f9e6078b35c6331ed31e75f8ce0c2db80b000000000000220020c20b5d1f8584fd90443e7b7b720136174fa4b9333c261d04dbbd012635c0f419a00f0000000000002200208c48d15160397c9731df9bc3b236656efb6665fbfe92b4a6878e88a499f741c4c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110e0a06a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e04004730440220275b0c325a5e9355650dc30c0eccfbc7efb23987c24b556b9dfdd40effca18d202206caceb2c067836c51f296740c7ae807ffcbfbf1dd3a0d56b6de9a5b247985f060147304402204fd4928835db1ccdfc40f5c78ce9bd65249b16348df81f0c44328dcdefc97d630220194d3869c38bc732dd87d13d2958015e2fc16829e74cd4377f84d215c0b7060601475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220"
     tx = Transaction(raw_tx)
     self.assertEqual(commitment_number, extract_ctn_from_tx(tx, 0, local_payment_basepoint, remote_payment_basepoint))
示例#5
0
 def test_verify_ok_t_tx(self):
     """Actually mined 64 byte tx should not raise."""
     t_tx = Transaction(VALID_64_BYTE_TX)
     t_tx_hash = t_tx.txid()
     self.assertEqual(MERKLE_ROOT, hash_merkle_root(MERKLE_BRANCH, t_tx_hash, 3))
示例#6
0
    def main(self):
        add_menu()
        welcome = 'Use the menu to scan a transaction.'
        droid.fullShow(qr_layout(welcome))
        while True:
            event = droid.eventWait().result
            if not event:
                continue
            elif event["name"] == "key":
                if event["data"]["key"] == '4':
                    if self.qr_data:
                        self.show_qr(None)
                        self.show_title(welcome)
                    else:
                        break

            elif event["name"] == "seed":
                password = self.get_password()
                if password is False:
                    modal_dialog('Error', 'incorrect password')
                    continue
                seed = wallet.get_mnemonic(password)
                modal_dialog('Your seed is', seed)

            elif event["name"] == "password":
                self.change_password_dialog()

            elif event["name"] == "xpub":
                mpk = wallet.get_master_public_key()
                self.show_qr(mpk)
                self.show_title('master public key')

            elif event["name"] == "scan":
                r = droid.scanBarcode()
                r = r.result
                if not r:
                    continue
                data = r['extras']['SCAN_RESULT']
                data = base_decode(data.encode('utf8'), None, base=43)
                data = ''.join(chr(ord(b)) for b in data).encode('hex')
                tx = Transaction(data)
                #except:
                #    modal_dialog('Error', 'Cannot parse transaction')
                #    continue
                if not wallet.can_sign(tx):
                    modal_dialog('Error', 'Cannot sign this transaction')
                    continue
                lines = map(
                    lambda x: x[0] + u'\t\t' + format_satoshis(x[1])
                    if x[1] else x[0], tx.get_outputs())
                if not modal_question('Sign?', '\n'.join(lines)):
                    continue
                password = self.get_password()
                if password is False:
                    modal_dialog('Error', 'incorrect password')
                    continue
                droid.dialogCreateSpinnerProgress("Signing")
                droid.dialogShow()
                wallet.sign_transaction(tx, password)
                droid.dialogDismiss()
                data = base_encode(str(tx).decode('hex'), base=43)
                self.show_qr(data)
                self.show_title('Signed Transaction')

        droid.makeToast("Bye!")
示例#7
0
def combine_transactions(transaction_bin):
    transactions = list(
        map(lambda tx_bin: Transaction(tx_from_str(tx_bin)), transaction_bin))
    tx0 = transactions[0]
    tx0.deserialize(True)
    return tx0
示例#8
0
async def get_tx_async(tx):
    result = await network.interface.session.send_request(
        "blockchain.transaction.get", [tx, True])
    result_formatted = Transaction(result).deserialize()
    result_formatted.update({"confirmations": result["confirmations"]})
    return result_formatted