From 2dec30828bf51b6bdf875579c32ea2f15e2d5da3 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Thu, 8 Mar 2018 14:39:57 +0100 Subject: [PATCH] wallet/signing: segwit has priority over force_bip143 This commit only rearranges the `if` main branch, so the segwit branch has priority over bip143. Since Bitcoin Gold is allowing both segwit and forcing bip143, the bitcoin gold segwit transactions were failing. updates #147 --- src/apps/wallet/sign_tx/signing.py | 48 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/apps/wallet/sign_tx/signing.py b/src/apps/wallet/sign_tx/signing.py index e00bf6a61..a162d1475 100644 --- a/src/apps/wallet/sign_tx/signing.py +++ b/src/apps/wallet/sign_tx/signing.py @@ -175,7 +175,30 @@ async def sign_tx(tx: SignTx, root: bip32.HDNode): key_sign = None key_sign_pub = None - if coin.force_bip143: + if segwit[i_sign]: + # STAGE_REQUEST_SEGWIT_INPUT + txi_sign = await request_tx_input(tx_req, i_sign) + + is_segwit = (txi_sign.script_type == InputScriptType.SPENDWITNESS or + txi_sign.script_type == InputScriptType.SPENDP2SHWITNESS) + if not is_segwit: + raise SigningError(FailureType.ProcessError, + 'Transaction has changed during signing') + input_check_wallet_path(txi_sign, wallet_path) + + key_sign = node_derive(root, txi_sign.address_n) + key_sign_pub = key_sign.public_key() + txi_sign.script_sig = input_derive_script(coin, txi_sign, key_sign_pub) + + w_txi = bytearray_with_cap( + 7 + len(txi_sign.prev_hash) + 4 + len(txi_sign.script_sig) + 4) + if i_sign == 0: # serializing first input => prepend headers + write_bytes(w_txi, get_tx_header(tx, True)) + write_tx_input(w_txi, txi_sign) + tx_ser.serialized_tx = w_txi + tx_req.serialized = tx_ser + + elif coin.force_bip143: # STAGE_REQUEST_SEGWIT_INPUT txi_sign = await request_tx_input(tx_req, i_sign) input_check_wallet_path(txi_sign, wallet_path) @@ -212,29 +235,6 @@ async def sign_tx(tx: SignTx, root: bip32.HDNode): tx_req.serialized = tx_ser - elif segwit[i_sign]: - # STAGE_REQUEST_SEGWIT_INPUT - txi_sign = await request_tx_input(tx_req, i_sign) - - is_segwit = (txi_sign.script_type == InputScriptType.SPENDWITNESS or - txi_sign.script_type == InputScriptType.SPENDP2SHWITNESS) - if not is_segwit: - raise SigningError(FailureType.ProcessError, - 'Transaction has changed during signing') - input_check_wallet_path(txi_sign, wallet_path) - - key_sign = node_derive(root, txi_sign.address_n) - key_sign_pub = key_sign.public_key() - txi_sign.script_sig = input_derive_script(coin, txi_sign, key_sign_pub) - - w_txi = bytearray_with_cap( - 7 + len(txi_sign.prev_hash) + 4 + len(txi_sign.script_sig) + 4) - if i_sign == 0: # serializing first input => prepend headers - write_bytes(w_txi, get_tx_header(tx, True)) - write_tx_input(w_txi, txi_sign) - tx_ser.serialized_tx = w_txi - tx_req.serialized = tx_ser - else: # hash of what we are signing with this input h_sign = HashWriter(sha256)