Skip to content
Merged
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
14 changes: 6 additions & 8 deletions payjoin-cli/src/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Config {
"Multiple version flags specified. Please use only one of: {}",
Self::VERSION_FLAGS
.iter()
.map(|(flag, _)| format!("--{}", flag))
.map(|(flag, _)| format!("--{flag}"))
.collect::<Vec<_>>()
.join(", ")
)));
Expand Down Expand Up @@ -146,8 +146,7 @@ impl Config {
Ok(v1) => config.version = Some(VersionConfig::V1(v1)),
Err(e) =>
return Err(ConfigError::Message(format!(
"Valid V1 configuration is required for BIP78 mode: {}",
e
"Valid V1 configuration is required for BIP78 mode: {e}"
))),
}
}
Expand All @@ -163,8 +162,7 @@ impl Config {
Ok(v2) => config.version = Some(VersionConfig::V2(v2)),
Err(e) =>
return Err(ConfigError::Message(format!(
"Valid V2 configuration is required for BIP77 mode: {}",
e
"Valid V2 configuration is required for BIP77 mode: {e}"
))),
}
}
Expand All @@ -182,7 +180,7 @@ impl Config {
));
}

log::debug!("App config: {:?}", config);
log::debug!("App config: {config:?}");
Ok(config)
}

Expand Down Expand Up @@ -315,10 +313,10 @@ where
match path_str {
None => Ok(None),
Some(path) => std::fs::read(path)
.map_err(|e| serde::de::Error::custom(format!("Failed to read ohttp_keys file: {}", e)))
.map_err(|e| serde::de::Error::custom(format!("Failed to read ohttp_keys file: {e}")))
.and_then(|bytes| {
payjoin::OhttpKeys::decode(&bytes).map_err(|e| {
serde::de::Error::custom(format!("Failed to decode ohttp keys: {}", e))
serde::de::Error::custom(format!("Failed to decode ohttp keys: {e}"))
})
})
.map(Some),
Expand Down
6 changes: 3 additions & 3 deletions payjoin-cli/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ pub trait App: Send + Sync {
}

fn process_pj_response(&self, psbt: Psbt) -> Result<bitcoin::Txid> {
log::debug!("Proposed psbt: {:#?}", psbt);
log::debug!("Proposed psbt: {psbt:#?}");

let signed = self.wallet().process_psbt(&psbt)?;
let tx = self.wallet().finalize_psbt(&signed)?;

let txid = self.wallet().broadcast_tx(&tx)?;

println!("Payjoin sent. TXID: {}", txid);
println!("Payjoin sent. TXID: {txid}");
Ok(txid)
}
}
Expand Down Expand Up @@ -83,7 +83,7 @@ fn read_local_cert() -> Result<Vec<u8>> {

async fn handle_interrupt(tx: watch::Sender<()>) {
if let Err(e) = signal::ctrl_c().await {
eprintln!("Error setting up Ctrl-C handler: {}", e);
eprintln!("Error setting up Ctrl-C handler: {e}");
}
let _ = tx.send(());
}
16 changes: 8 additions & 8 deletions payjoin-cli/src/app/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ impl AppTrait for App {
);
let psbt = ctx.process_response(&mut response.bytes().await?.to_vec().as_slice()).map_err(
|e| {
log::debug!("Error processing response: {:?}", e);
anyhow!("Failed to process response {}", e)
log::debug!("Error processing response: {e:?}");
anyhow!("Failed to process response {e}")
},
)?;

Expand Down Expand Up @@ -165,7 +165,7 @@ impl App {
let stream = match tls_acceptor.accept(stream).await {
Ok(tls_stream) => tls_stream,
Err(e) => {
log::error!("TLS accept error: {}", e);
log::error!("TLS accept error: {e}");
return;
}
};
Expand Down Expand Up @@ -211,19 +211,19 @@ impl App {
self,
req: Request<Incoming>,
) -> Result<Response<BoxBody<Bytes, hyper::Error>>> {
log::debug!("Received request: {:?}", req);
log::debug!("Received request: {req:?}");
let mut response = match (req.method(), req.uri().path()) {
(&Method::GET, "/bip21") => {
let query_string = req.uri().query().unwrap_or("");
log::debug!("{:?}, {:?}", req.method(), query_string);
log::debug!("{:?}, {query_string:?}", req.method());
let query_params: HashMap<_, _> =
url::form_urlencoded::parse(query_string.as_bytes()).into_owned().collect();
let amount = query_params.get("amount").map(|amt| {
Amount::from_btc(amt.parse().expect("Failed to parse amount")).unwrap()
});
self.handle_get_bip21(amount)
.map_err(|e| {
log::error!("Error handling request: {}", e);
log::error!("Error handling request: {e}");
Response::builder().status(500).body(full(e.to_string())).unwrap()
})
.unwrap_or_else(|err_resp| err_resp)
Expand All @@ -233,11 +233,11 @@ impl App {
.await
.map_err(|e| match e {
V1(e) => {
log::error!("Error handling request: {}", e);
log::error!("Error handling request: {e}");
Response::builder().status(400).body(full(e.to_string())).unwrap()
}
e => {
log::error!("Error handling request: {}", e);
log::error!("Error handling request: {e}");
Response::builder().status(500).body(full(e.to_string())).unwrap()
}
})
Expand Down
12 changes: 6 additions & 6 deletions payjoin-cli/src/app/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl App {
let mut pj_uri = session.pj_uri();
pj_uri.amount = amount;
println!("Request Payjoin by sharing this Payjoin Uri:");
println!("{}", pj_uri);
println!("{pj_uri}");

let mut interrupt = self.interrupt.clone();
let receiver = tokio::select! {
Expand Down Expand Up @@ -208,8 +208,8 @@ impl App {
println!("No response yet.");
}
Err(re) => {
println!("{}", re);
log::debug!("{:?}", re);
println!("{re}");
log::debug!("{re:?}");
return Err(anyhow!("Response error").context(re));
}
}
Expand All @@ -223,8 +223,8 @@ impl App {
match v1_ctx.process_response(&mut response.bytes().await?.to_vec().as_slice()) {
Ok(psbt) => Ok(psbt),
Err(re) => {
println!("{}", re);
log::debug!("{:?}", re);
println!("{re}");
log::debug!("{re:?}");
Err(anyhow!("Response error").context(re))
}
}
Expand Down Expand Up @@ -286,7 +286,7 @@ impl App {
self.config.max_fee_rate,
)?;
let payjoin_proposal_psbt = payjoin_proposal.psbt();
log::debug!("Receiver's Payjoin proposal PSBT Rsponse: {:#?}", payjoin_proposal_psbt);
log::debug!("Receiver's Payjoin proposal PSBT Rsponse: {payjoin_proposal_psbt:#?}");
Ok(payjoin_proposal)
}
}
Expand Down
8 changes: 4 additions & 4 deletions payjoin-cli/src/db/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ pub(crate) enum Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Sled(e) => write!(f, "Database operation failed: {}", e),
Error::Sled(e) => write!(f, "Database operation failed: {e}"),
#[cfg(feature = "v2")]
Error::Serialize(e) => write!(f, "Serialization failed: {}", e),
Error::Serialize(e) => write!(f, "Serialization failed: {e}"),
#[cfg(feature = "v2")]
Error::Deserialize(e) => write!(f, "Deserialization failed: {}", e),
Error::Deserialize(e) => write!(f, "Deserialization failed: {e}"),
#[cfg(feature = "v2")]
Error::NotFound(key) => write!(f, "Key not found: {}", key),
Error::NotFound(key) => write!(f, "Key not found: {key}"),
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions payjoin-cli/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod e2e {
let receiver_rpchost = format!("http://{}/wallet/receiver", bitcoind.params.rpc_socket);
let sender_rpchost = format!("http://{}/wallet/sender", bitcoind.params.rpc_socket);
let cookie_file = &bitcoind.params.cookie_file;
let pj_endpoint = format!("https://localhost:{}", port);
let pj_endpoint = format!("https://localhost:{port}");
let payjoin_cli = env!("CARGO_BIN_EXE_payjoin-cli");

let mut cli_receiver = Command::new(payjoin_cli)
Expand Down Expand Up @@ -82,7 +82,7 @@ mod e2e {
{
// Write to stdout regardless
stdout
.write_all(format!("{}\n", line).as_bytes())
.write_all(format!("{line}\n").as_bytes())
.await
.expect("Failed to write to stdout");

Expand Down Expand Up @@ -121,7 +121,7 @@ mod e2e {
lines.next_line().await.expect("Failed to read line from stdout")
{
stdout
.write_all(format!("{}\n", line).as_bytes())
.write_all(format!("{line}\n").as_bytes())
.await
.expect("Failed to write to stdout");
if line.contains("Payjoin sent") {
Expand Down Expand Up @@ -173,8 +173,8 @@ mod e2e {
CleanupGuard { paths: vec![receiver_db_path.clone(), sender_db_path.clone()] };

let result = tokio::select! {
res = services.take_ohttp_relay_handle() => Err(format!("Ohttp relay is long running: {:?}", res).into()),
res = services.take_directory_handle() => Err(format!("Directory server is long running: {:?}", res).into()),
res = services.take_ohttp_relay_handle() => Err(format!("Ohttp relay is long running: {res:?}").into()),
res = services.take_directory_handle() => Err(format!("Directory server is long running: {res:?}").into()),
res = send_receive_cli_async(&services, receiver_db_path.clone(), sender_db_path.clone()) => res,
};

Expand Down Expand Up @@ -357,7 +357,7 @@ mod e2e {
{
// Write all output to tests stdout
stdout
.write_all(format!("{}\n", line).as_bytes())
.write_all(format!("{line}\n").as_bytes())
.await
.expect("Failed to write to stdout");

Expand All @@ -375,7 +375,7 @@ mod e2e {

fn cleanup_temp_file(path: &std::path::Path) {
if let Err(e) = std::fs::remove_dir_all(path) {
eprintln!("Failed to remove {:?}: {}", path, e);
eprintln!("Failed to remove {path:?}: {e}");
}
}
}
6 changes: 3 additions & 3 deletions payjoin-directory/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ impl std::fmt::Display for Error {
use Error::*;

match &self {
Redis(error) => write!(f, "Redis error: {}", error),
Timeout(timeout) => write!(f, "Timeout: {}", timeout),
Redis(error) => write!(f, "Redis error: {error}"),
Timeout(timeout) => write!(f, "Timeout: {timeout}"),
}
}
}
Expand All @@ -49,7 +49,7 @@ pub(crate) type Result<T> = core::result::Result<T, Error>;

impl DbPool {
pub async fn new(timeout: Duration, db_host: String) -> Result<Self> {
let client = Client::open(format!("redis://{}", db_host))?;
let client = Client::open(format!("redis://{db_host}"))?;
Ok(Self { client, timeout })
}

Expand Down
2 changes: 1 addition & 1 deletion payjoin-directory/src/key_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn read_server_config(dir: &Path) -> Result<ServerKeyConfig> {
/// Get the path to the key configuration file
/// For now, default to [KEY_ID].ikm.
/// In the future this might be able to save multiple keys named by KeyId.
fn key_path(dir: &Path) -> PathBuf { dir.join(format!("{}.ikm", KEY_ID)) }
fn key_path(dir: &Path) -> PathBuf { dir.join(format!("{KEY_ID}.ikm")) }

#[cfg(test)]
mod tests {
Expand Down
4 changes: 2 additions & 2 deletions payjoin-directory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub async fn listen_tcp_with_tls(
cert_key: (Vec<u8>, Vec<u8>),
ohttp: ohttp::Server,
) -> Result<tokio::task::JoinHandle<Result<(), BoxError>>, BoxError> {
let addr = format!("0.0.0.0:{}", port);
let addr = format!("0.0.0.0:{port}");
let listener = tokio::net::TcpListener::bind(&addr).await?;
listen_tcp_with_tls_on_listener(listener, db_host, timeout, cert_key, ohttp).await
}
Expand Down Expand Up @@ -352,7 +352,7 @@ async fn post_fallback_v1(
Err(_) => return Ok(bad_request_body_res),
};

let v2_compat_body = format!("{}\n{}", body_str, query);
let v2_compat_body = format!("{body_str}\n{query}");
let id = ShortId::from_str(id)?;
pool.push_default(&id, v2_compat_body.into())
.await
Expand Down
4 changes: 2 additions & 2 deletions payjoin-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub async fn init_directory(
(u16, tokio::task::JoinHandle<std::result::Result<(), BoxSendSyncError>>),
BoxSendSyncError,
> {
println!("Database running on {}", db_host);
println!("Database running on {db_host}");
let timeout = Duration::from_secs(2);
let ohttp_server = payjoin_directory::gen_ohttp_server_config()?;
payjoin_directory::listen_tcp_with_tls_on_free_port(
Expand Down Expand Up @@ -221,7 +221,7 @@ pub fn init_bitcoind_multi_sender_single_reciever(
) -> Result<(bitcoind::BitcoinD, Vec<bitcoincore_rpc::Client>, bitcoincore_rpc::Client), BoxError> {
let bitcoind = init_bitcoind()?;
let wallets_to_create =
(0..number_of_senders + 1).map(|i| (format!("sender_{}", i), None)).collect::<Vec<_>>();
(0..number_of_senders + 1).map(|i| (format!("sender_{i}"), None)).collect::<Vec<_>>();
let mut wallets = create_and_fund_wallets(&bitcoind, wallets_to_create)?;
let receiver = wallets.pop().expect("receiver to exist");
let senders = wallets;
Expand Down
3 changes: 1 addition & 2 deletions payjoin/src/hpke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ impl fmt::Display for HpkeError {
PayloadTooLarge { actual, max } => {
write!(
f,
"Plaintext too large, max size is {} bytes, actual size is {} bytes",
max, actual
"Plaintext too large, max size is {max} bytes, actual size is {actual} bytes"
)
}
PayloadTooShort => write!(f, "Payload too small"),
Expand Down
2 changes: 1 addition & 1 deletion payjoin/src/into_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl std::fmt::Display for Error {

match self {
BadScheme => write!(f, "URL scheme is not allowed"),
ParseError(e) => write!(f, "{}", e),
ParseError(e) => write!(f, "{e}"),
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions payjoin/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ impl std::fmt::Display for Error {
ParseUrl(e) => e.fmt(f),
Io(e) => e.fmt(f),
InvalidOhttpKeys(e) => {
write!(f, "Invalid ohttp keys returned from payjoin directory: {}", e)
write!(f, "Invalid ohttp keys returned from payjoin directory: {e}")
}
UnexpectedStatusCode(code) => {
write!(f, "Unexpected status code from payjoin directory: {}", code)
write!(f, "Unexpected status code from payjoin directory: {code}")
}
#[cfg(feature = "_danger-local-https")]
Rustls(e) => e.fmt(f),
Expand Down Expand Up @@ -172,8 +172,7 @@ mod tests {
match parse_ohttp_keys_response(response).await {
Err(Error(InternalError::UnexpectedStatusCode(code))) => assert_eq!(code, status),
result => panic!(
"Expected UnexpectedStatusCode error for status code: {}, got: {:?}",
status, result
"Expected UnexpectedStatusCode error for status code: {status}, got: {result:?}"
),
}
}
Expand Down
7 changes: 3 additions & 4 deletions payjoin/src/ohttp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn ohttp_encapsulate(
let authority_bytes = url.host().map_or_else(Vec::new, |host| {
let mut authority = host.to_string();
if let Some(port) = url.port() {
write!(authority, ":{}", port).unwrap();
write!(authority, ":{port}").unwrap();
}
authority.into_bytes()
});
Expand Down Expand Up @@ -249,9 +249,8 @@ impl std::fmt::Display for ParseOhttpKeysError {
match self {
ParseOhttpKeysError::InvalidFormat => write!(f, "Invalid format"),
ParseOhttpKeysError::InvalidPublicKey => write!(f, "Invalid public key"),
ParseOhttpKeysError::DecodeBech32(e) => write!(f, "Failed to decode base64: {}", e),
ParseOhttpKeysError::DecodeKeyConfig(e) =>
write!(f, "Failed to decode KeyConfig: {}", e),
ParseOhttpKeysError::DecodeBech32(e) => write!(f, "Failed to decode base64: {e}"),
ParseOhttpKeysError::DecodeKeyConfig(e) => write!(f, "Failed to decode KeyConfig: {e}"),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions payjoin/src/psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub(crate) enum InconsistentPsbt {
impl fmt::Display for InconsistentPsbt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
InconsistentPsbt::UnequalInputCounts { tx_ins, psbt_ins, } => write!(f, "The number of PSBT inputs ({}) doesn't equal to the number of unsigned transaction inputs ({})", psbt_ins, tx_ins),
InconsistentPsbt::UnequalOutputCounts { tx_outs, psbt_outs, } => write!(f, "The number of PSBT outputs ({}) doesn't equal to the number of unsigned transaction outputs ({})", psbt_outs, tx_outs),
InconsistentPsbt::UnequalInputCounts { tx_ins, psbt_ins, } => write!(f, "The number of PSBT inputs ({psbt_ins}) doesn't equal to the number of unsigned transaction inputs ({tx_ins})"),
InconsistentPsbt::UnequalOutputCounts { tx_outs, psbt_outs, } => write!(f, "The number of PSBT outputs ({psbt_outs}) doesn't equal to the number of unsigned transaction outputs ({tx_outs})"),
}
}
}
Expand Down Expand Up @@ -228,7 +228,7 @@ impl fmt::Display for PrevTxOutError {
match self {
PrevTxOutError::MissingUtxoInformation => write!(f, "missing UTXO information"),
PrevTxOutError::IndexOutOfBounds { output_count, index } => {
write!(f, "index {} out of bounds (number of outputs: {})", index, output_count)
write!(f, "index {index} out of bounds (number of outputs: {output_count})")
}
}
}
Expand Down
Loading
Loading