Skip to main content

agent_pay/
lightning.rs

1//! Lightning node abstraction.
2
3use async_trait::async_trait;
4
5use crate::error::Error;
6
7#[derive(Debug, Clone)]
8pub struct InvoiceCreateRequest {
9    pub amount_msat: u64,
10    pub memo: Option<String>,
11    pub expiry_seconds: Option<u64>,
12}
13
14#[derive(Debug, Clone)]
15pub struct Invoice {
16    pub bolt11: String,
17    pub payment_hash: String,
18}
19
20#[derive(Debug, Clone)]
21pub struct InvoiceLookup {
22    pub settled: bool,
23    pub amount_msat: u64,
24    pub preimage: Option<Vec<u8>>,
25}
26
27#[derive(Debug, Clone)]
28pub struct PaymentResult {
29    pub preimage: Vec<u8>,
30    pub fee_msat: u64,
31}
32
33#[async_trait]
34pub trait LightningNode: Send + Sync {
35    async fn create_invoice(&self, req: InvoiceCreateRequest) -> Result<Invoice, Error>;
36    async fn lookup_invoice(&self, payment_hash: &str) -> Result<InvoiceLookup, Error>;
37    async fn pay_invoice(&self, bolt11: &str) -> Result<PaymentResult, Error>;
38}