From cfdd517bf4772db64c7f6aafcc6aa5af4b9661f9 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Wed, 16 Nov 2016 01:45:18 +0100 Subject: [PATCH] apps.common.signtx: fix outputs for multibyte address prefixes --- src/apps/common/signtx.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/apps/common/signtx.py b/src/apps/common/signtx.py index aea204f36..1584c7da5 100644 --- a/src/apps/common/signtx.py +++ b/src/apps/common/signtx.py @@ -312,14 +312,25 @@ def get_tx_hash(w, double: bool, reverse: bool=False) -> bytes: # TX Outputs # === +def len_address_type(address_type): + if address_type <= 0xFF: + return 1 + if address_type <= 0xFFFF: + return 2 + if address_type <= 0xFFFFFF: + return 3 + # else + return 4 def output_derive_script(o: TxOutputType, coin: CoinType, root) -> bytes: if o.script_type == OutputScriptType.PAYTOADDRESS: ra = output_paytoaddress_extract_raw_address(o, coin, root) - return script_paytoaddress_new(ra[1:]) + at = len_address_type(coin.address_type) + return script_paytoaddress_new(ra[at:]) elif o.script_type == OutputScriptType.PAYTOSCRIPTHASH: ra = output_paytoaddress_extract_raw_address(o, coin, root, p2sh=True) - return script_paytoscripthash_new(ra[1:]) + at = len_address_type(coin.address_type_p2sh) + return script_paytoscripthash_new(ra[at:]) elif o.script_type == OutputScriptType.PAYTOOPRETURN: if o.amount == 0: return script_paytoopreturn_new(o.op_return_data)