witness: Witness::new(), }) .collect(), output: self .outputs .iter() .map(|(address, amount)| TxOut { value: amount.to_sat(), script_pubkey: address.script_pubkey(), }) .collect(), }; assert_eq!( self .amounts .iter() .filter(|(outpoint, amount)| *outpoint == &self.outgoing.outpoint && self.outgoing.offset < amount.to_sat()) .count(), 1, "invariant: outgoing sat is contained in utxos" ); assert_eq!( transaction .input .iter() .filter(|tx_in| tx_in.previous_output == self.outgoing.outpoint) .count(), 1, "invariant: inputs spend outgoing sat" ); let mut sat_offset = 0; let mut found = false; for tx_in in &transaction.input { if tx_in.previous_output == self.outgoing.outpoint { sat_offset += self.outgoing.offset; found = true; break; } else {