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