MCPcopy Create free account
hub / github.com/ElementsProject/lightning / parse_payment_instructions

Function parse_payment_instructions

plugins/bip353-plugin/src/main.rs:173–264  ·  view source on GitHub ↗
(
    payment_instructions: &PaymentInstructions,
)

Source from the content-addressed store, hash-verified

171}
172
173fn parse_payment_instructions(
174 payment_instructions: &PaymentInstructions,
175) -> Result<ProcessedBIP353, anyhow::Error> {
176 let proof = payment_instructions
177 .bip_353_dnssec_proof()
178 .as_ref()
179 .ok_or_else(|| anyhow!("bip353 dnssec proof not found"))?
180 .to_lower_hex_string();
181
182 let mut processed_bip353 = ProcessedBIP353::new(proof);
183
184 match payment_instructions {
185 PaymentInstructions::ConfigurableAmount(configurable_instructions) => {
186 for method in configurable_instructions.methods() {
187 let resolved_method = if let PossiblyResolvedPaymentMethod::Resolved(m) = method {
188 m
189 } else {
190 continue;
191 };
192 let mut processed_instruction = ProcessedPaymentInstruction::new();
193 if let Some(desc) = configurable_instructions.recipient_description() {
194 processed_instruction.description = Some(desc.to_owned());
195 }
196 match resolved_method {
197 PaymentMethod::LightningBolt12(offer) => {
198 processed_instruction.offer = Some(offer.to_string());
199 processed_bip353.instructions.push(processed_instruction);
200 log::debug!("Found offer for configurable amount: {}", offer);
201 }
202 PaymentMethod::OnChain(address) => {
203 processed_instruction.onchain = Some(address.to_string());
204 processed_bip353.instructions.push(processed_instruction);
205 log::debug!("Found onchain address for configurable amount: {}", address);
206 }
207 _ => continue,
208 }
209 }
210 }
211 PaymentInstructions::FixedAmount(fixed_instructions) => {
212 for method in fixed_instructions.methods() {
213 let mut processed_instruction = ProcessedPaymentInstruction::new();
214 if let Some(desc) = fixed_instructions.recipient_description() {
215 processed_instruction.description = Some(desc.to_owned());
216 }
217 match method {
218 PaymentMethod::LightningBolt12(offer) => {
219 processed_instruction.offer = Some(offer.to_string());
220 let offchain_amount_msat = fixed_instructions
221 .ln_payment_amount()
222 .ok_or_else(|| {
223 anyhow!("Not supported: amount is for non-Bitcoin currency")
224 })?
225 .milli_sats();
226 processed_instruction.offchain_amount_msat = Some(offchain_amount_msat);
227 processed_bip353.instructions.push(processed_instruction);
228
229 log::debug!(
230 "Found offer:{} for fixed amount: {}msat",

Callers 1

fetch_bip353Function · 0.85

Calls 2

methodsMethod · 0.80
to_stringMethod · 0.45

Tested by

no test coverage detected