URI: 
       tfollow-up prev. sanity check OP_RETURN outputs - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit c9c8b7656d3ceb5d4d26ae443cb2ad5eaab064d0
   DIR parent e1b2195cf7c4a3194812612ebae0b85ed56938aa
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Tue, 31 Jul 2018 13:03:34 +0200
       
       follow-up prev. sanity check OP_RETURN outputs
       
       based on https://github.com/fyookball/electrum/pull/765/commits/86c63a3a084951c87789346e1d9de35f4cede055
       
       Diffstat:
         M electrum/plugins/hw_wallet/plugin.… |      16 +++++++++++++++-
         M electrum/plugins/keepkey/keepkey.py |       4 ++--
         M electrum/plugins/safe_t/safe_t.py   |       4 ++--
         M electrum/plugins/trezor/trezor.py   |       4 ++--
       
       4 files changed, 21 insertions(+), 7 deletions(-)
       ---
   DIR diff --git a/electrum/plugins/hw_wallet/plugin.py b/electrum/plugins/hw_wallet/plugin.py
       t@@ -26,7 +26,9 @@
        
        from electrum.plugin import BasePlugin, hook
        from electrum.i18n import _
       -from electrum.bitcoin import is_address
       +from electrum.bitcoin import is_address, TYPE_SCRIPT
       +from electrum.util import bfh
       +from electrum.transaction import opcodes
        
        
        class HW_PluginBase(BasePlugin):
       t@@ -87,3 +89,15 @@ def is_any_tx_output_on_change_branch(tx):
                    if index[0] == 1:
                        return True
            return False
       +
       +
       +def trezor_validate_op_return_output_and_get_data(_type, address, amount):
       +    if _type != TYPE_SCRIPT:
       +        raise Exception("Unexpected output type: {}".format(_type))
       +    script = bfh(address)
       +    if not (script[0] == opcodes.OP_RETURN and
       +            script[1] == len(script) - 2 and script[1] <= 75):
       +        raise Exception(_("Only OP_RETURN scripts, with one constant push, are supported."))
       +    if amount != 0:
       +        raise Exception(_("Amount for OP_RETURN output must be zero."))
       +    return script[2:]
   DIR diff --git a/electrum/plugins/keepkey/keepkey.py b/electrum/plugins/keepkey/keepkey.py
       t@@ -15,7 +15,7 @@ from electrum.wallet import Standard_Wallet
        from electrum.base_wizard import ScriptTypeNotSupported
        
        from ..hw_wallet import HW_PluginBase
       -from ..hw_wallet.plugin import is_any_tx_output_on_change_branch
       +from ..hw_wallet.plugin import is_any_tx_output_on_change_branch, trezor_validate_op_return_output_and_get_data
        
        
        # TREZOR initialization methods
       t@@ -382,7 +382,7 @@ class KeepKeyPlugin(HW_PluginBase):
                    txoutputtype.amount = amount
                    if _type == TYPE_SCRIPT:
                        txoutputtype.script_type = self.types.PAYTOOPRETURN
       -                txoutputtype.op_return_data = bfh(address)[2:]
       +                txoutputtype.op_return_data = trezor_validate_op_return_output_and_get_data(_type, address, amount)
                    elif _type == TYPE_ADDRESS:
                        if is_segwit_address(address):
                            txoutputtype.script_type = self.types.PAYTOWITNESS
   DIR diff --git a/electrum/plugins/safe_t/safe_t.py b/electrum/plugins/safe_t/safe_t.py
       t@@ -13,7 +13,7 @@ from electrum.keystore import Hardware_KeyStore, is_xpubkey, parse_xpubkey, xtyp
        from electrum.base_wizard import ScriptTypeNotSupported
        
        from ..hw_wallet import HW_PluginBase
       -from ..hw_wallet.plugin import is_any_tx_output_on_change_branch
       +from ..hw_wallet.plugin import is_any_tx_output_on_change_branch, trezor_validate_op_return_output_and_get_data
        
        
        # Safe-T mini initialization methods
       t@@ -453,7 +453,7 @@ class SafeTPlugin(HW_PluginBase):
                    txoutputtype.amount = amount
                    if _type == TYPE_SCRIPT:
                        txoutputtype.script_type = self.types.OutputScriptType.PAYTOOPRETURN
       -                txoutputtype.op_return_data = bfh(address)[2:]
       +                txoutputtype.op_return_data = trezor_validate_op_return_output_and_get_data(_type, address, amount)
                    elif _type == TYPE_ADDRESS:
                        txoutputtype.script_type = self.types.OutputScriptType.PAYTOADDRESS
                        txoutputtype.address = address
   DIR diff --git a/electrum/plugins/trezor/trezor.py b/electrum/plugins/trezor/trezor.py
       t@@ -13,7 +13,7 @@ from electrum.keystore import Hardware_KeyStore, is_xpubkey, parse_xpubkey, xtyp
        from electrum.base_wizard import ScriptTypeNotSupported
        
        from ..hw_wallet import HW_PluginBase
       -from ..hw_wallet.plugin import is_any_tx_output_on_change_branch
       +from ..hw_wallet.plugin import is_any_tx_output_on_change_branch, trezor_validate_op_return_output_and_get_data
        
        
        # TREZOR initialization methods
       t@@ -464,7 +464,7 @@ class TrezorPlugin(HW_PluginBase):
                    txoutputtype.amount = amount
                    if _type == TYPE_SCRIPT:
                        txoutputtype.script_type = self.types.OutputScriptType.PAYTOOPRETURN
       -                txoutputtype.op_return_data = bfh(address)[2:]
       +                txoutputtype.op_return_data = trezor_validate_op_return_output_and_get_data(_type, address, amount)
                    elif _type == TYPE_ADDRESS:
                        txoutputtype.script_type = self.types.OutputScriptType.PAYTOADDRESS
                        txoutputtype.address = address