Skip to content

Commit dabee95

Browse files
committed
f - remove UnsupportedChain and UnsupportedCurrency checks
1 parent d472cab commit dabee95

File tree

2 files changed

+9
-32
lines changed

2 files changed

+9
-32
lines changed

lightning/src/offers/offer.rs

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,9 @@ impl OfferBuilder {
219219

220220
/// Builds an [`Offer`] from the builder's settings.
221221
pub fn build(self) -> Result<Offer, ()> {
222+
// TODO: Also check for Amount::Currency
222223
if let Some(Amount::Currency { .. }) = self.offer.amount {
223-
return Err(());
224-
}
225-
226-
if self.offer.amount_msats() > MAX_VALUE_MSAT {
224+
} else if self.offer.amount_msats() > MAX_VALUE_MSAT {
227225
return Err(());
228226
}
229227

@@ -488,26 +486,11 @@ impl TryFrom<OfferTlvStream> for OfferContents {
488486
issuer, quantity_min, quantity_max, node_id,
489487
} = tlv_stream;
490488

491-
let supported_chains = [
492-
ChainHash::using_genesis_block(Network::Bitcoin),
493-
ChainHash::using_genesis_block(Network::Testnet),
494-
ChainHash::using_genesis_block(Network::Signet),
495-
ChainHash::using_genesis_block(Network::Regtest),
496-
];
497-
let chains = match chains {
498-
None => None,
499-
Some(chains) => match chains.first() {
500-
None => Some(chains),
501-
Some(chain) if supported_chains.contains(chain) => Some(chains),
502-
_ => return Err(SemanticError::UnsupportedChain),
503-
},
504-
};
505-
506489
let amount = match (currency, amount) {
507490
(None, None) => None,
508491
(None, Some(amount_msats)) => Some(Amount::Bitcoin { amount_msats }),
509492
(Some(_), None) => return Err(SemanticError::MissingAmount),
510-
(Some(_), Some(_)) => return Err(SemanticError::UnsupportedCurrency),
493+
(Some(iso4217_code), Some(amount)) => Some(Amount::Currency { iso4217_code, amount }),
511494
};
512495

513496
let description = match description {
@@ -683,16 +666,14 @@ mod tests {
683666
assert_eq!(tlv_stream.amount, Some(1000));
684667
assert_eq!(tlv_stream.currency, None);
685668

686-
let builder = OfferBuilder::new("foo".into(), pubkey(42))
687-
.amount(currency_amount.clone());
688-
let tlv_stream = builder.offer.as_tlv_stream();
689-
assert_eq!(builder.offer.amount.as_ref(), Some(&currency_amount));
669+
let offer = OfferBuilder::new("foo".into(), pubkey(42))
670+
.amount(currency_amount.clone())
671+
.build()
672+
.unwrap();
673+
let tlv_stream = offer.as_tlv_stream();
674+
assert_eq!(offer.amount(), Some(&currency_amount));
690675
assert_eq!(tlv_stream.amount, Some(10));
691676
assert_eq!(tlv_stream.currency, Some(b"USD"));
692-
match builder.build() {
693-
Ok(_) => panic!("expected error"),
694-
Err(e) => assert_eq!(e, ()),
695-
}
696677

697678
let offer = OfferBuilder::new("foo".into(), pubkey(42))
698679
.amount(currency_amount.clone())

lightning/src/offers/parse.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,8 @@ pub enum ParseError {
7575
/// Error when interpreting a TLV stream as a specific type.
7676
#[derive(Debug, PartialEq)]
7777
pub enum SemanticError {
78-
/// The provided block hash does not correspond to a supported chain.
79-
UnsupportedChain,
8078
/// An amount was expected but was missing.
8179
MissingAmount,
82-
/// A currency was provided that is not supported.
83-
UnsupportedCurrency,
8480
/// A required description was not provided.
8581
MissingDescription,
8682
/// A node id was not provided.

0 commit comments

Comments
 (0)