Skip to content

Commit ebc5639

Browse files
committed
f: DRY code
1 parent 08b1ede commit ebc5639

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

lightning/src/ln/channelmanager.rs

+15-25
Original file line numberDiff line numberDiff line change
@@ -9124,22 +9124,19 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
91249124
let context = MessageContext::Offers (
91259125
OffersContext::InvoiceRequest { nonce }
91269126
);
9127+
9128+
let offer_builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
9129+
.chain_hash($self.chain_hash);
9130+
91279131
let builder = match blinded_path {
91289132
Some(blinded_path) => {
91299133
let paths = $self
91309134
.create_blinded_paths(context, blinded_path)
91319135
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
91329136

9133-
let offer_builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
9134-
.chain_hash($self.chain_hash);
9135-
9136-
paths.into_iter().fold(offer_builder, |builder, path| {
9137-
builder.path(path)
9138-
})
9137+
paths.into_iter().fold(offer_builder, OfferBuilder::path)
91399138
}
9140-
9141-
None => OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
9142-
.chain_hash($self.chain_hash),
9139+
None => offer_builder
91439140
};
91449141

91459142
Ok(builder.into())
@@ -9206,30 +9203,23 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
92069203
OffersContext::OutboundPayment { payment_id, nonce, hmac: None }
92079204
);
92089205

9206+
let refund_builder = RefundBuilder::deriving_signing_pubkey(
9207+
node_id, expanded_key, nonce, secp_ctx,
9208+
amount_msats, payment_id,
9209+
)?
9210+
.chain_hash($self.chain_hash)
9211+
.absolute_expiry(absolute_expiry);
9212+
92099213
let builder = match blinded_path {
92109214
Some(blinded_path) => {
92119215
let paths = $self
92129216
.create_blinded_paths(context, blinded_path)
92139217
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
92149218

9215-
let refund_builder = RefundBuilder::deriving_signing_pubkey(
9216-
node_id, expanded_key, nonce, secp_ctx,
9217-
amount_msats, payment_id,
9218-
)?
9219-
.chain_hash($self.chain_hash)
9220-
.absolute_expiry(absolute_expiry);
9221-
9222-
paths.into_iter().fold(refund_builder, |builder, path| {
9223-
builder.path(path)
9224-
})
9219+
paths.into_iter().fold(refund_builder, |builder, path| builder.path(path))
92259220
}
92269221

9227-
None => RefundBuilder::deriving_signing_pubkey(
9228-
node_id, expanded_key, nonce, secp_ctx,
9229-
amount_msats, payment_id,
9230-
)?
9231-
.chain_hash($self.chain_hash)
9232-
.absolute_expiry(absolute_expiry)
9222+
None => refund_builder
92339223
};
92349224

92359225
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);

0 commit comments

Comments
 (0)