Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include send to pubkey condition in payment request #526

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/cdk-cli/src/sub_commands/create_request.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use anyhow::Result;
use cdk::nuts::nut18::TransportType;
use cdk::nuts::{CurrencyUnit, PaymentRequest, PaymentRequestPayload, Token, Transport};
use cdk::nuts::{
CurrencyUnit, PaymentRequest, PaymentRequestPayload, PublicKey as CdkPublicKey, Token,
Transport,
};
use cdk::wallet::MultiMintWallet;
use clap::Args;
use nostr_sdk::nips::nip19::Nip19Profile;
Expand All @@ -14,6 +17,9 @@ pub struct CreateRequestSubCommand {
/// Currency unit e.g. sat
#[arg(default_value = "sat")]
unit: String,
/// Public key
#[arg(short, long)]
pubkey: Option<CdkPublicKey>,
/// Quote description
description: Option<String>,
}
Expand Down Expand Up @@ -48,6 +54,7 @@ pub async fn create_request(
mints: Some(mints),
description: sub_command_args.description.clone(),
transports: vec![nostr_transport],
public_key: sub_command_args.pubkey,
};

println!("{}", req);
Expand Down
8 changes: 6 additions & 2 deletions crates/cdk-cli/src/sub_commands/pay_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io::{self, Write};
use anyhow::{anyhow, Result};
use cdk::amount::SplitTarget;
use cdk::nuts::nut18::TransportType;
use cdk::nuts::{PaymentRequest, PaymentRequestPayload};
use cdk::nuts::{PaymentRequest, PaymentRequestPayload, SpendingConditions};
use cdk::wallet::{MultiMintWallet, SendKind};
use clap::Args;
use nostr_sdk::nips::nip19::Nip19Profile;
Expand Down Expand Up @@ -81,11 +81,15 @@ pub async fn pay_request(
})
.ok_or(anyhow!("No supported transport method found"))?;

let conditions = payment_request
.public_key
.map(|pk| SpendingConditions::new_p2pk(pk, None));

let proofs = matching_wallet
.send(
amount,
None,
None,
conditions,
&SplitTarget::default(),
&SendKind::default(),
true,
Expand Down
6 changes: 5 additions & 1 deletion crates/cdk/src/nuts/nut18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bitcoin::base64::{alphabet, Engine};
use serde::{Deserialize, Serialize};
use thiserror::Error;

use super::{CurrencyUnit, Proofs};
use super::{CurrencyUnit, Proofs, PublicKey};
use crate::mint_url::MintUrl;
use crate::Amount;

Expand Down Expand Up @@ -95,6 +95,9 @@ pub struct PaymentRequest {
/// Transport
#[serde(rename = "t")]
pub transports: Vec<Transport>,
/// Public key
#[serde(rename = "p")]
pub public_key: Option<PublicKey>,
}

impl fmt::Display for PaymentRequest {
Expand Down Expand Up @@ -180,6 +183,7 @@ mod tests {
mints: Some(vec!["https://nofees.testnut.cashu.space".parse()?]),
description: None,
transports: vec![transport.clone()],
public_key: None,
};

let request_str = request.to_string();
Expand Down
Loading