pub fn new(
outgoing: SatPoint,
inscriptions: BTreeMap<SatPoint, InscriptionId>,
amounts: BTreeMap<OutPoint, Amount>,
locked_utxos: BTreeSet<OutPoint>,
recipient: Address,
change: [Address; 2],
fee_rate: FeeRate,
target: Target,
) -> Self {
Self {
utxos: amounts.keys().cloned().collect(),
locked_utxos,
amounts,
change_addresses: change.iter().cloned().collect(),
fee_rate,
inputs: Vec::new(),
inscriptions,
outgoing,
outputs: Vec::new(),
recipient,
unused_change_addresses: change.to_vec(),
target,
}
}
pub fn build_transaction(self) -> Result<Transaction> {
if self.change_addresses.len() < 2 {
return Err(Error::DuplicateAddress(
self.change_addresses.first().unwrap().clone(),
));
}
if self.change_addresses.contains(&self.recipient) {
return Err(Error::DuplicateAddress(self.recipient));
}
match self.target {
Target::Value(output_value) | Target::ExactPostage(output_value) => {