Skip to content

Commit

Permalink
Merge pull request fedimint#6149 from Kodylow/add-tweaked-invoice-rpcs
Browse files Browse the repository at this point in the history
feat: add tweaked invoice rpcs
  • Loading branch information
Kodylow authored Oct 9, 2024
2 parents f4e1230 + 700fe68 commit 430e64f
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion modules/fedimint-ln-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ use pay::PayInvoicePayload;
use rand::rngs::OsRng;
use rand::seq::IteratorRandom as _;
use rand::{CryptoRng, Rng, RngCore};
use secp256k1::{All, PublicKey, Scalar, Secp256k1, Signing, ThirtyTwoByteHash, Verification};
use secp256k1::{
All, PublicKey, Scalar, Secp256k1, SecretKey, Signing, ThirtyTwoByteHash, Verification,
};
use serde::{Deserialize, Serialize};
use serde_json::json;
use strum::IntoEnumIterator;
Expand Down Expand Up @@ -476,6 +478,38 @@ impl ClientModule for LightningClientModule {
yield serde_json::to_value(state)?;
}
}
"create_bolt11_invoice_for_user_tweaked" => {
let req: CreateBolt11InvoiceForUserTweakedRequest = serde_json::from_value(payload)?;
let (op, invoice, _) = self
.create_bolt11_invoice_for_user_tweaked(
req.amount,
lightning_invoice::Bolt11InvoiceDescription::Direct(
&lightning_invoice::Description::new(req.description)?,
),
req.expiry_time,
req.user_key,
req.index,
req.extra_meta,
req.gateway,
)
.await?;
yield serde_json::json!({
"operation_id": op,
"invoice": invoice,
});
}
"scan_receive_for_user_tweaked" => {
let req: ScanReceiveForUserTweakedRequest = serde_json::from_value(payload)?;
let keypair = KeyPair::from_secret_key(&self.secp, &req.user_key);
let operation_ids = self.scan_receive_for_user_tweaked(keypair, req.indices, req.extra_meta).await;
yield serde_json::to_value(operation_ids)?;
}
"subscribe_ln_claim" => {
let req: SubscribeLnClaimRequest = serde_json::from_value(payload)?;
for await state in self.subscribe_ln_claim(req.operation_id).await?.into_stream() {
yield serde_json::to_value(state)?;
}
}
"get_gateway" => {
let req: GetGatewayRequest = serde_json::from_value(payload)?;
let gateway = self.get_gateway(req.gateway_id, req.force_internal).await?;
Expand Down Expand Up @@ -524,6 +558,29 @@ struct SubscribeLnReceiveRequest {
operation_id: OperationId,
}

#[derive(Deserialize)]
struct CreateBolt11InvoiceForUserTweakedRequest {
amount: Amount,
description: String,
expiry_time: Option<u64>,
user_key: PublicKey,
index: u64,
extra_meta: serde_json::Value,
gateway: Option<LightningGateway>,
}

#[derive(Deserialize)]
struct ScanReceiveForUserTweakedRequest {
user_key: SecretKey,
indices: Vec<u64>,
extra_meta: serde_json::Value,
}

#[derive(Deserialize)]
struct SubscribeLnClaimRequest {
operation_id: OperationId,
}

#[derive(Deserialize)]
struct GetGatewayRequest {
gateway_id: Option<secp256k1::PublicKey>,
Expand Down

0 comments on commit 430e64f

Please sign in to comment.