Skip to content

Commit b44cde7

Browse files
committed
f - remove UnsupportedChain and UnsupportedCurrency checks
1 parent ec9302a commit b44cde7

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
@@ -220,11 +220,9 @@ impl OfferBuilder {
220220

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

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

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

511494
let description = match description {
@@ -682,16 +665,14 @@ mod tests {
682665
assert_eq!(tlv_stream.amount, Some(1000));
683666
assert_eq!(tlv_stream.currency, None);
684667

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

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

lightning/src/offers/parse.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,8 @@ pub enum ParseError {
7272
/// Error when interpreting a TLV stream as a specific type.
7373
#[derive(Debug, PartialEq)]
7474
pub enum SemanticError {
75-
/// The provided block hash does not correspond to a supported chain.
76-
UnsupportedChain,
7775
/// An amount was expected but was missing.
7876
MissingAmount,
79-
/// A currency was provided that is not supported.
80-
UnsupportedCurrency,
8177
/// A required description was not provided.
8278
MissingDescription,
8379
/// A node id was not provided.

0 commit comments

Comments
 (0)