Skip to content

Commit a5c5848

Browse files
committed
f DRY payment secret checks
1 parent a234c7e commit a5c5848

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

lightning-invoice/src/lib.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,13 @@ impl Invoice {
10231023
return Err(SemanticError::MultipleDescriptions);
10241024
}
10251025

1026+
self.check_payment_secret()?;
1027+
1028+
Ok(())
1029+
}
1030+
1031+
/// Checks that there is exactly one payment secret field
1032+
fn check_payment_secret(&self) -> Result<(), SemanticError> {
10261033
// "A writer MUST include exactly one `s` field."
10271034
let payment_secret_count = self.tagged_fields().filter(|&tf| match *tf {
10281035
TaggedField::PaymentSecret(_) => true,
@@ -1049,16 +1056,7 @@ impl Invoice {
10491056

10501057
/// Check that feature bits are set as required
10511058
fn check_feature_bits(&self) -> Result<(), SemanticError> {
1052-
// "A writer MUST include exactly one `s` field."
1053-
let payment_secret_count = self.tagged_fields().filter(|&tf| match *tf {
1054-
TaggedField::PaymentSecret(_) => true,
1055-
_ => false,
1056-
}).count();
1057-
if payment_secret_count < 1 {
1058-
return Err(SemanticError::NoPaymentSecret);
1059-
} else if payment_secret_count > 1 {
1060-
return Err(SemanticError::MultiplePaymentSecrets);
1061-
}
1059+
self.check_payment_secret()?;
10621060

10631061
// "A writer MUST set an s field if and only if the payment_secret feature is set."
10641062
// (this requirement has been since removed, and we now require the payment secret

0 commit comments

Comments
 (0)