-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat: bolt12 #370
Closed
Closed
feat: bolt12 #370
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
0848ad4
feat: pay bolt12 (backends not impl)
thesimplekid b1b6d4c
feat: phd pay offer
thesimplekid 1c2c7a3
feat: cdk-cli melt bolt12
thesimplekid 880fcc5
chore: update phd-rs
thesimplekid cd591ab
fix: check phd has valid payment id
thesimplekid f1494c5
fix: add unknown state to sql
thesimplekid 113a449
feat: cln fetch invoice
thesimplekid fc046b7
feat: cln pay bolt12
thesimplekid de6e75e
feat: logging amoints
thesimplekid 0933111
fix: phd fee
thesimplekid 0b1464a
feat: bolt12 mint endpoints
thesimplekid d249f65
chore: clippy
thesimplekid bed9543
feat: cln mint via bolt12
thesimplekid 25d8fde
feat: cdk-cli mint bolt12
thesimplekid 98d7489
feat: mint cli
thesimplekid aa0ccab
feat: bolt12 info
thesimplekid f364fad
feat: wait any invoice, use offer id
thesimplekid 2ac7c08
feat: add bolt12 router
thesimplekid bc2d114
feat: add cancel to wait invoice
thesimplekid 590ad0d
feat: nut18/19 settings
thesimplekid 122130e
feat: nut18/19 mint melt settings
thesimplekid 10d8435
refactor: ln backend set up helpers
thesimplekid b34aa44
refactor: ln routers
thesimplekid 24b637e
fix: rename cdk-mintd bin
thesimplekid baee4ea
fix: itest kill script
thesimplekid 6bbfd56
feat: mint builder
thesimplekid 54b783a
feat: use mintbuilder
thesimplekid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,10 @@ use std::io::Write; | |
use std::str::FromStr; | ||
|
||
use anyhow::{bail, Result}; | ||
use cdk::nuts::CurrencyUnit; | ||
use cdk::amount::Amount; | ||
use cdk::nuts::{CurrencyUnit, PaymentMethod}; | ||
use cdk::wallet::multi_mint_wallet::{MultiMintWallet, WalletKey}; | ||
use cdk::Bolt11Invoice; | ||
// use cdk::Bolt11Invoice; | ||
use clap::Args; | ||
|
||
use crate::sub_commands::balance::mint_balances; | ||
|
@@ -15,13 +16,19 @@ pub struct MeltSubCommand { | |
/// Currency unit e.g. sat | ||
#[arg(default_value = "sat")] | ||
unit: String, | ||
/// Payment method | ||
#[arg(short, long, default_value = "bolt11")] | ||
method: String, | ||
/// Amount | ||
#[arg(short, long)] | ||
amount: Option<u64>, | ||
} | ||
|
||
pub async fn pay( | ||
multi_mint_wallet: &MultiMintWallet, | ||
sub_command_args: &MeltSubCommand, | ||
) -> Result<()> { | ||
let unit = CurrencyUnit::from_str(&sub_command_args.unit)?; | ||
let unit = CurrencyUnit::from_str(&sub_command_args.unit).unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove unwrap |
||
let mints_amounts = mint_balances(multi_mint_wallet, &unit).await?; | ||
|
||
println!("Enter mint number to melt from"); | ||
|
@@ -44,22 +51,36 @@ pub async fn pay( | |
.await | ||
.expect("Known wallet"); | ||
|
||
println!("Enter bolt11 invoice request"); | ||
let method = PaymentMethod::from_str(&sub_command_args.method)?; | ||
match method { | ||
PaymentMethod::Bolt11 => { | ||
println!("Enter bolt11 invoice request"); | ||
} | ||
PaymentMethod::Bolt12 => { | ||
println!("Enter bolt12 invoice request"); | ||
} | ||
_ => panic!("Unknown payment method"), | ||
} | ||
|
||
let mut user_input = String::new(); | ||
let stdin = io::stdin(); | ||
io::stdout().flush().unwrap(); | ||
stdin.read_line(&mut user_input)?; | ||
let bolt11 = Bolt11Invoice::from_str(user_input.trim())?; | ||
|
||
if bolt11 | ||
.amount_milli_satoshis() | ||
.unwrap() | ||
.gt(&(<cdk::Amount as Into<u64>>::into(mints_amounts[mint_number].1) * 1000_u64)) | ||
{ | ||
bail!("Not enough funds"); | ||
} | ||
let quote = wallet.melt_quote(bolt11.to_string(), None).await?; | ||
|
||
let quote = match method { | ||
PaymentMethod::Bolt11 => { | ||
wallet | ||
.melt_quote(user_input.trim().to_string(), None) | ||
.await? | ||
} | ||
PaymentMethod::Bolt12 => { | ||
let amount = sub_command_args.amount.map(Amount::from); | ||
wallet | ||
.melt_bolt12_quote(user_input.trim().to_string(), amount) | ||
.await? | ||
} | ||
_ => panic!("Unsupported payment methof"), | ||
}; | ||
|
||
println!("{:?}", quote); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set this back to arg