feat(NUT02): add input_fee_ppk

chore: instrument log on mint fns
This commit is contained in:
thesimplekid
2024-05-30 00:19:19 +01:00
parent 8477dc7a1d
commit 17263b07f5
33 changed files with 1009 additions and 514 deletions

View File

@@ -14,6 +14,7 @@ use cdk_sqlite::WalletSqliteDatabase;
use clap::{Parser, Subcommand};
use rand::Rng;
use tracing::Level;
use tracing_subscriber::EnvFilter;
mod sub_commands;
@@ -69,11 +70,15 @@ enum Commands {
#[tokio::main]
async fn main() -> Result<()> {
// Parse input
let args: Cli = Cli::parse();
tracing_subscriber::fmt()
.with_max_level(args.log_level)
.init();
let default_filter = args.log_level;
let sqlx_filter = "sqlx=warn";
let env_filter = EnvFilter::new(format!("{},{}", default_filter, sqlx_filter));
// Parse input
tracing_subscriber::fmt().with_env_filter(env_filter).init();
let work_dir = match &args.work_dir {
Some(work_dir) => work_dir.clone(),
@@ -131,6 +136,7 @@ async fn main() -> Result<()> {
cdk::nuts::CurrencyUnit::Sat,
localstore.clone(),
&mnemonic.to_seed_normalized(""),
None,
);
wallets.insert(mint, wallet);

View File

@@ -32,7 +32,13 @@ pub async fn mint(
let mint_url = sub_command_args.mint_url.clone();
let wallet = match wallets.get(&mint_url) {
Some(wallet) => wallet.clone(),
None => Wallet::new(&mint_url.to_string(), CurrencyUnit::Sat, localstore, seed),
None => Wallet::new(
&mint_url.to_string(),
CurrencyUnit::Sat,
localstore,
seed,
None,
),
};
let quote = wallet

View File

@@ -136,11 +136,12 @@ async fn receive_token(
CurrencyUnit::Sat,
Arc::clone(localstore),
seed,
None,
),
};
let amount = wallet
.receive(token_str, &SplitTarget::default(), signing_keys, preimage)
.receive(token_str, SplitTarget::default(), signing_keys, preimage)
.await?;
Ok(amount)
}

View File

@@ -6,6 +6,7 @@ use std::str::FromStr;
use anyhow::{bail, Result};
use cdk::amount::SplitTarget;
use cdk::nuts::{Conditions, PublicKey, SpendingConditions, Token};
use cdk::wallet::types::SendKind;
use cdk::wallet::Wallet;
use cdk::{Amount, UncheckedUrl};
use clap::Args;
@@ -35,6 +36,15 @@ pub struct SendSubCommand {
/// Token as V3 token
#[arg(short, long)]
v3: bool,
/// Should the send be offline only
#[arg(short, long)]
offline: bool,
/// Include fee to redeam in token
#[arg(short, long)]
include_fee: bool,
/// Amount willing to overpay to avoid a swap
#[arg(short, long)]
tolerance: Option<u64>,
}
pub async fn send(
@@ -146,12 +156,21 @@ pub async fn send(
let wallet = mints_amounts[mint_number].0.clone();
let send_kind = match (sub_command_args.offline, sub_command_args.tolerance) {
(true, Some(amount)) => SendKind::OfflineTolerance(Amount::from(amount)),
(true, None) => SendKind::OfflineExact,
(false, Some(amount)) => SendKind::OnlineTolerance(Amount::from(amount)),
(false, None) => SendKind::OnlineExact,
};
let token = wallet
.send(
token_amount,
sub_command_args.memo.clone(),
conditions,
&SplitTarget::default(),
&send_kind,
sub_command_args.include_fee,
)
.await?;