|
@@ -74,21 +74,35 @@ impl Mint {
|
|
|
) -> Result<Self, Error> {
|
|
|
let mut active_units: HashSet<CurrencyUnit> = HashSet::default();
|
|
|
|
|
|
- // Check that there is only one active keyset per unit
|
|
|
- for keyset_info in keysets_info {
|
|
|
- if keyset_info.active && !active_units.insert(keyset_info.unit.clone()) {
|
|
|
- // TODO: Handle Error
|
|
|
- todo!()
|
|
|
- }
|
|
|
-
|
|
|
+ if keysets_info.is_empty() {
|
|
|
let keyset = nut02::mint::KeySet::generate(
|
|
|
&mnemonic.to_seed_normalized(""),
|
|
|
- keyset_info.unit.clone(),
|
|
|
- &keyset_info.derivation_path.clone(),
|
|
|
- keyset_info.max_order,
|
|
|
+ CurrencyUnit::Sat,
|
|
|
+ "",
|
|
|
+ 64,
|
|
|
);
|
|
|
|
|
|
+ localstore
|
|
|
+ .add_active_keyset(CurrencyUnit::Sat, keyset.id.clone())
|
|
|
+ .await?;
|
|
|
localstore.add_keyset(keyset).await?;
|
|
|
+ } else {
|
|
|
+ // Check that there is only one active keyset per unit
|
|
|
+ for keyset_info in keysets_info {
|
|
|
+ if keyset_info.active && !active_units.insert(keyset_info.unit.clone()) {
|
|
|
+ // TODO: Handle Error
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ let keyset = nut02::mint::KeySet::generate(
|
|
|
+ &mnemonic.to_seed_normalized(""),
|
|
|
+ keyset_info.unit.clone(),
|
|
|
+ &keyset_info.derivation_path.clone(),
|
|
|
+ keyset_info.max_order,
|
|
|
+ );
|
|
|
+
|
|
|
+ localstore.add_keyset(keyset).await?;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Ok(Self {
|
|
@@ -339,7 +353,7 @@ impl Mint {
|
|
|
let input_keyset_ids: HashSet<Id> =
|
|
|
swap_request.inputs.iter().map(|p| p.keyset_id).collect();
|
|
|
|
|
|
- let mut keyset_units = Vec::with_capacity(input_keyset_ids.capacity());
|
|
|
+ let mut keyset_units = HashSet::with_capacity(input_keyset_ids.capacity());
|
|
|
|
|
|
for id in input_keyset_ids {
|
|
|
let keyset = self
|
|
@@ -347,7 +361,7 @@ impl Mint {
|
|
|
.get_keyset(&id)
|
|
|
.await?
|
|
|
.ok_or(Error::UnknownKeySet)?;
|
|
|
- keyset_units.push(keyset.unit);
|
|
|
+ keyset_units.insert(keyset.unit);
|
|
|
}
|
|
|
|
|
|
let output_keyset_ids: HashSet<Id> =
|
|
@@ -360,12 +374,13 @@ impl Mint {
|
|
|
.await?
|
|
|
.ok_or(Error::UnknownKeySet)?;
|
|
|
|
|
|
- keyset_units.push(keyset.unit);
|
|
|
+ keyset_units.insert(keyset.unit);
|
|
|
}
|
|
|
|
|
|
- // Check that all input and output proofs are the same unit
|
|
|
- let seen_units: HashSet<CurrencyUnit> = HashSet::new();
|
|
|
- if keyset_units.iter().any(|unit| !seen_units.contains(unit)) && seen_units.len() != 1 {
|
|
|
+ // Check that all proofs are the same unit
|
|
|
+ // in the future it maybe possible to support multiple units but unsupported for
|
|
|
+ // now
|
|
|
+ if keyset_units.len().gt(&1) {
|
|
|
return Err(Error::MultipleUnits);
|
|
|
}
|
|
|
|