@@ -54,8 +54,7 @@ function toExpectedOutputs(
5454 recipients ?: ITransactionRecipient [ ] ;
5555 allowExternalChangeAddress ?: boolean ;
5656 changeAddress ?: string ;
57- } ,
58- allOutputs : Output [ ]
57+ }
5958) : Output [ ] {
6059 // verify that each recipient from txParams has their own output
6160 const expectedOutputs = ( txParams . recipients ?? [ ] ) . flatMap ( ( output ) => {
@@ -70,17 +69,7 @@ function toExpectedOutputs(
7069 if ( txParams . allowExternalChangeAddress && txParams . changeAddress ) {
7170 // when an external change address is explicitly specified, count all outputs going towards that
7271 // address in the expected outputs (regardless of the output amount)
73- expectedOutputs . push (
74- ...allOutputs . flatMap ( ( output ) => {
75- if (
76- output . address === undefined ||
77- output . address !== coin . canonicalAddress ( txParams . changeAddress as string )
78- ) {
79- return [ ] ;
80- }
81- return [ { ...output , address : coin . canonicalAddress ( output . address ) } ] ;
82- } )
83- ) ;
72+ expectedOutputs . push ( { address : coin . canonicalAddress ( txParams . changeAddress ) , amount : 'max' } ) ;
8473 }
8574 return expectedOutputs ;
8675}
@@ -120,16 +109,7 @@ export async function parseTransaction<TNumber extends bigint | number>(
120109 throw new Error ( 'missing required txPrebuild property txHex' ) ;
121110 }
122111
123- // obtain all outputs
124- const explanation : TransactionExplanation = await coin . explainTransaction < TNumber > ( {
125- txHex : txPrebuild . txHex ,
126- txInfo : txPrebuild . txInfo ,
127- pubs : keychainArray . map ( ( k ) => k . pub ) as Triple < string > ,
128- } ) ;
129-
130- const allOutputs = [ ...explanation . outputs , ...explanation . changeOutputs ] ;
131-
132- const expectedOutputs = toExpectedOutputs ( coin , txParams , allOutputs ) ;
112+ const expectedOutputs = toExpectedOutputs ( coin , txParams ) ;
133113
134114 // get the keychains from the custom change wallet if needed
135115 let customChange : CustomChangeOptions | undefined ;
@@ -159,6 +139,15 @@ export async function parseTransaction<TNumber extends bigint | number>(
159139 }
160140 }
161141
142+ // obtain all outputs
143+ const explanation : TransactionExplanation = await coin . explainTransaction < TNumber > ( {
144+ txHex : txPrebuild . txHex ,
145+ txInfo : txPrebuild . txInfo ,
146+ pubs : keychainArray . map ( ( k ) => k . pub ) as Triple < string > ,
147+ } ) ;
148+
149+ const allOutputs = [ ...explanation . outputs , ...explanation . changeOutputs ] ;
150+
162151 /**
163152 * Loop through all the outputs and classify each of them as either internal spends
164153 * or external spends by setting the "external" property to true or false on the output object.
0 commit comments