Skip to content

Commit

Permalink
Ensure assetid is always included if set
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross committed Jan 21, 2025
1 parent 2d1b319 commit 5a20b38
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions libs/sdk-common/src/liquid/bip21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,19 @@ impl LiquidAddressData {

let mut optional_keys = HashMap::new();

if let Some(amount) = self.amount {
let Some(asset_id) = self.asset_id.clone() else {
return Err(URISerializationError::AssetIdMissing);
};

optional_keys.insert("amount", format!("{amount:.8}"));
// Ensure that assetid is always set when an amount is set
if let Some(asset_id) = self.asset_id.clone() {
optional_keys.insert("assetid", asset_id);
} else if self.amount.is_some() || self.amount_sat.is_some() {
return Err(URISerializationError::AssetIdMissing);
}

if let Some(amount_sat) = self.amount_sat {
let Some(asset_id) = self.asset_id.clone() else {
return Err(URISerializationError::AssetIdMissing);
};

// Take amount over amount_sat if both are set
if let Some(amount) = self.amount {
optional_keys.insert("amount", format!("{amount:.8}"));
} else if let Some(amount_sat) = self.amount_sat {
let amount_btc = amount_sat as f64 / 100_000_000.0;
optional_keys.insert("amount", format!("{amount_btc:.8}"));
optional_keys.insert("assetid", asset_id);
}

if let Some(message) = &self.message {
Expand Down

0 comments on commit 5a20b38

Please sign in to comment.