pub fn reorder_outputs(
	outputs: impl IntoIterator<Item = TxOut>,
	order: impl IntoIterator<Item = (Script, u64)>,
) -> Vec<TxOut> {
	let indices: HashMap<(Script, u64), usize> = order
		.into_iter()
		.enumerate()
		.map(|(idx, val)| (val, idx))
		.collect();

	let outputs_ordered: BTreeMap<usize, TxOut> = outputs
		.into_iter()
		.map(|txout| {
			(
				*indices
					.get(&(txout.script_pubkey.clone(), txout.value))
					.unwrap_or(&usize::MAX), // Change amount
				txout,
			)
		})
		.collect();

	outputs_ordered.into_values().collect()
}
Reorders outputs according to the provided order
sbtc-core/src/operations/op_return/utils.rs