@@ -127,99 +127,52 @@ def getStatus(self):
127127
128128
129129
130-
131130 @process_ledger_exceptions
132- def prepare_transfer_tx (self , caller , bip32_path , utxos_to_spend , dest_address , tx_fee , useSwiftX = False ):
133- with self .lock :
134- # For each UTXO create a Ledger 'trusted input'
135- self .trusted_inputs = []
136- # https://klmoney.wordpress.com/bitcoin-dissecting-transactions-part-2-building-a-transaction-by-hand)
137- self .arg_inputs = []
138- self .amount = 0
131+ def append_inputs_to_TX (self , utxo , bip32_path ):
132+ self .amount += int (utxo ['value' ])
133+ raw_tx = bytearray .fromhex (utxo ['raw_tx' ])
139134
140- num_of_sigs = len (utxos_to_spend )
141- curr_utxo_checked = 0
142- for idx , utxo in enumerate (utxos_to_spend ):
143-
144- self .amount += int (utxo ['value' ])
145- raw_tx = bytearray .fromhex (utxo ['raw_tx' ])
146-
147- # parse the raw transaction, so that we can extract the UTXO locking script we refer to
148- prev_transaction = bitcoinTransaction (raw_tx )
149-
150- utxo_tx_index = utxo ['tx_ouput_n' ]
151- if utxo_tx_index < 0 or utxo_tx_index > len (prev_transaction .outputs ):
152- raise Exception ('Incorrect value of outputIndex for UTXO %s' % str (idx ))
153-
154-
155- trusted_input = self .chip .getTrustedInput (prev_transaction , utxo_tx_index )
156-
157- self .trusted_inputs .append (trusted_input )
158-
159- # Hash check
160- curr_pubkey = compress_public_key (self .chip .getWalletPublicKey (bip32_path )['publicKey' ])
161- pubkey_hash = bin_hash160 (curr_pubkey )
162- pubkey_hash_from_script = extract_pkh_from_locking_script (prev_transaction .outputs [utxo_tx_index ].script )
163- if pubkey_hash != pubkey_hash_from_script :
164- text = "Error: The hashes for the public key for the BIP32 path, and the UTXO locking script do not match."
165- text += "Your signed transaction will not be validated by the network.\n "
166- text += "pubkey_hash: %s\n " % pubkey_hash .hex ()
167- text += "pubkey_hash_from_script: %s\n " % pubkey_hash_from_script .hex ()
168- printDbg (text )
169-
170- self .arg_inputs .append ({
171- 'locking_script' : prev_transaction .outputs [utxo ['tx_ouput_n' ]].script ,
172- 'pubkey' : curr_pubkey ,
173- 'bip32_path' : bip32_path ,
174- 'outputIndex' : utxo ['tx_ouput_n' ],
175- 'txid' : utxo ['tx_hash' ]
176- })
177-
178- # completion percent emitted
179- curr_utxo_checked += 1
180- completion = int (95 * curr_utxo_checked / num_of_sigs )
181- self .tx_progress .emit (completion )
182-
183- self .amount -= int (tx_fee )
184- self .amount = int (self .amount )
185- arg_outputs = [{'address' : dest_address , 'valueSat' : self .amount }] # there will be multiple outputs soon
186- self .new_transaction = bitcoinTransaction () # new transaction object to be used for serialization at the last stage
187- self .new_transaction .version = bytearray ([0x01 , 0x00 , 0x00 , 0x00 ])
188-
189- # completion percent emitted
190- self .tx_progress .emit (99 )
135+ # parse the raw transaction, so that we can extract the UTXO locking script we refer to
136+ prev_transaction = bitcoinTransaction (raw_tx )
191137
192- for o in arg_outputs :
193- output = bitcoinOutput ()
194- output .script = compose_tx_locking_script (o ['address' ])
195- output .amount = int .to_bytes (o ['valueSat' ], 8 , byteorder = 'little' )
196- self .new_transaction .outputs .append (output )
197-
198- # completion percent emitted
199- self .tx_progress .emit (100 )
200-
201- # join all outputs - will be used by Ledger for signing transaction
202- self .all_outputs_raw = self .new_transaction .serializeOutputs ()
203-
204- self .mBox2 = QMessageBox (caller )
205- self .messageText = "<p>Confirm transaction on your device, with the following details:</p>"
206- #messageText += "From bip32_path: <b>%s</b><br><br>" % str(bip32_path)
207- self .messageText += "<p>Payment to:<br><b>%s</b></p>" % dest_address
208- self .messageText += "<p>Net amount:<br><b>%s</b> PIV</p>" % str (round (self .amount / 1e8 , 8 ))
209- if useSwiftX :
210- self .messageText += "<p>Fees (SwiftX flat rate):<br><b>%s</b> PIV<p>" % str (round (int (tx_fee ) / 1e8 , 8 ))
211- else :
212- self .messageText += "<p>Fees:<br><b>%s</b> PIV<p>" % str (round (int (tx_fee ) / 1e8 , 8 ))
213- messageText = self .messageText + "Signature Progress: 0 %"
214- self .mBox2 .setText (messageText )
215- self .mBox2 .setText (messageText )
216- self .mBox2 .setIconPixmap (caller .tabMain .ledgerImg .scaledToHeight (200 , Qt .SmoothTransformation ))
217- self .mBox2 .setWindowTitle ("CHECK YOUR LEDGER" )
218- self .mBox2 .setStandardButtons (QMessageBox .NoButton )
219- self .mBox2 .setMaximumWidth (500 )
220- self .mBox2 .show ()
138+ utxo_tx_index = utxo ['tx_ouput_n' ]
139+ if utxo_tx_index < 0 or utxo_tx_index > len (prev_transaction .outputs ):
140+ raise Exception ('Incorrect value of outputIndex for UTXO %s-%d' %
141+ (utxo ['raw_tx' ], utxo ['tx_ouput_n' ]))
221142
222- ThreadFuns .runInThread (self .signTxSign , (), self .signTxFinish )
143+ trusted_input = self .chip .getTrustedInput (prev_transaction , utxo_tx_index )
144+ self .trusted_inputs .append (trusted_input )
145+
146+ # Hash check
147+ curr_pubkey = compress_public_key (self .chip .getWalletPublicKey (bip32_path )['publicKey' ])
148+ pubkey_hash = bin_hash160 (curr_pubkey )
149+ pubkey_hash_from_script = extract_pkh_from_locking_script (prev_transaction .outputs [utxo_tx_index ].script )
150+ if pubkey_hash != pubkey_hash_from_script :
151+ text = "Error: The hashes for the public key for the BIP32 path, and the UTXO locking script do not match."
152+ text += "Your signed transaction will not be validated by the network.\n "
153+ text += "pubkey_hash: %s\n " % pubkey_hash .hex ()
154+ text += "pubkey_hash_from_script: %s\n " % pubkey_hash_from_script .hex ()
155+ printDbg (text )
156+
157+ self .arg_inputs .append ({
158+ 'locking_script' : prev_transaction .outputs [utxo ['tx_ouput_n' ]].script ,
159+ 'pubkey' : curr_pubkey ,
160+ 'bip32_path' : bip32_path ,
161+ 'outputIndex' : utxo ['tx_ouput_n' ],
162+ 'txid' : utxo ['tx_hash' ]
163+ })
164+
165+
166+
167+
168+ @process_ledger_exceptions
169+ def prepare_transfer_tx (self , caller , bip32_path , utxos_to_spend , dest_address , tx_fee , useSwiftX = False ):
170+ rewardsArray = []
171+ mnode = {}
172+ mnode ['path' ] = bip32_path
173+ mnode ['utxos' ] = utxos_to_spend
174+ rewardsArray .append (mnode )
175+ self .prepare_transfer_tx_bulk (caller , rewardsArray , dest_address , tx_fee , useSwiftX )
223176
224177
225178
@@ -234,41 +187,9 @@ def prepare_transfer_tx_bulk(self, caller, rewardsArray, dest_address, tx_fee, u
234187 num_of_sigs = sum ([len (mnode ['utxos' ]) for mnode in rewardsArray ])
235188 curr_utxo_checked = 0
236189
237- for i , mnode in enumerate (rewardsArray ):
238- for idx , utxo in enumerate (mnode ['utxos' ]):
239-
240- self .amount += int (utxo ['value' ])
241- raw_tx = bytearray .fromhex (utxo ['raw_tx' ])
242-
243- # parse the raw transaction, so that we can extract the UTXO locking script we refer to
244- prev_transaction = bitcoinTransaction (raw_tx )
245-
246- utxo_tx_index = utxo ['tx_ouput_n' ]
247- if utxo_tx_index < 0 or utxo_tx_index > len (prev_transaction .outputs ):
248- raise Exception ('Incorrect value of outputIndex for UTXO %s' % str (idx ))
249-
250- trusted_input = self .chip .getTrustedInput (prev_transaction , utxo_tx_index )
251- self .trusted_inputs .append (trusted_input )
252-
253- # Hash check
254- curr_pubkey = compress_public_key (self .chip .getWalletPublicKey (mnode ['path' ])['publicKey' ])
255- pubkey_hash = bin_hash160 (curr_pubkey )
256- pubkey_hash_from_script = extract_pkh_from_locking_script (prev_transaction .outputs [utxo_tx_index ].script )
257- if pubkey_hash != pubkey_hash_from_script :
258- text = "Error: The hashes for the public key for the BIP32 path, and the UTXO locking script do not match."
259- text += "Your signed transaction will not be validated by the network.\n "
260- text += "pubkey_hash: %s\n " % pubkey_hash .hex ()
261- text += "pubkey_hash_from_script: %s\n " % pubkey_hash_from_script .hex ()
262- printDbg (text )
263-
264- self .arg_inputs .append ({
265- 'locking_script' : prev_transaction .outputs [utxo ['tx_ouput_n' ]].script ,
266- 'pubkey' : curr_pubkey ,
267- 'bip32_path' : mnode ['path' ],
268- 'outputIndex' : utxo ['tx_ouput_n' ],
269- 'txid' : utxo ['tx_hash' ]
270- })
271-
190+ for mnode in rewardsArray :
191+ for utxo in mnode ['utxos' ]:
192+ self .append_inputs_to_TX (utxo , mnode ['path' ])
272193 # completion percent emitted
273194 curr_utxo_checked += 1
274195 completion = int (95 * curr_utxo_checked / num_of_sigs )
0 commit comments