taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

commit 2116901c50a4d7b35e1948c9720051c26f03baf1
parent 8e33065eacbe23ec3dff71e630bb765cab7a7a3a
Author: Antoine A <>
Date:   Wed, 18 Mar 2026 16:07:22 +0100

common: replace async block with async closure

Diffstat:
Mcommon/taler-api/src/api.rs | 8+++-----
Mcommon/taler-api/src/api/revenue.rs | 4++--
Mcommon/taler-api/src/api/wire.rs | 45++++++++++++++++++++++-----------------------
Mcommon/taler-api/src/db.rs | 2+-
Mcommon/taler-api/tests/api.rs | 2+-
Mcommon/taler-test-utils/src/routine.rs | 27+++++++++++++--------------
Mtaler-cyclos/src/bin/cyclos-harness.rs | 8+++-----
Mtaler-cyclos/src/main.rs | 2+-
Mtaler-cyclos/tests/api.rs | 44++++++++++++++++++++------------------------
Mtaler-magnet-bank/src/bin/magnet-bank-harness.rs | 8+++-----
Mtaler-magnet-bank/src/main.rs | 2+-
Mtaler-magnet-bank/tests/api.rs | 43++++++++++++++++++++-----------------------
12 files changed, 90 insertions(+), 105 deletions(-)

diff --git a/common/taler-api/src/api.rs b/common/taler-api/src/api.rs @@ -97,11 +97,9 @@ impl TalerRouter for Router { } fn finalize(self) -> Router { - self.method_not_allowed_fallback(|| async { - failure_code(ErrorCode::GENERIC_METHOD_INVALID) - }) - .fallback(|| async { failure_code(ErrorCode::GENERIC_ENDPOINT_UNKNOWN) }) - .layer(middleware::from_fn(logger_middleware)) + self.method_not_allowed_fallback(async || failure_code(ErrorCode::GENERIC_METHOD_INVALID)) + .fallback(async || failure_code(ErrorCode::GENERIC_ENDPOINT_UNKNOWN)) + .layer(middleware::from_fn(logger_middleware)) } async fn serve(mut self, serve: Serve, lifetime: Option<u32>) -> std::io::Result<()> { diff --git a/common/taler-api/src/api/revenue.rs b/common/taler-api/src/api/revenue.rs @@ -49,7 +49,7 @@ pub fn router<I: Revenue>(state: Arc<I>, auth: AuthMethod) -> Router { .route( "/history", get( - |State(state): State<Arc<I>>, Query(params): Query<HistoryParams>| async move { + async |State(state): State<Arc<I>>, Query(params): Query<HistoryParams>| { let params = params.check(MAX_PAGE_SIZE, MAX_TIMEOUT_MS)?; let history = state.history(params).await?; ApiResult::Ok(if history.incoming_transactions.is_empty() { @@ -63,7 +63,7 @@ pub fn router<I: Revenue>(state: Arc<I>, auth: AuthMethod) -> Router { .auth(auth, "taler-revenue") .route( "/config", - get(|State(state): State<Arc<I>>| async move { + get(async |State(state): State<Arc<I>>| { Json(RevenueConfig { name: "taler-revenue", version: REVENUE_API_VERSION, diff --git a/common/taler-api/src/api/wire.rs b/common/taler-api/src/api/wire.rs @@ -95,7 +95,7 @@ pub fn router<I: WireGateway>(state: Arc<I>, auth: AuthMethod) -> Router { .route( "/transfer", post( - |State(state): State<Arc<I>>, Req(req): Req<TransferRequest>| async move { + async |State(state): State<Arc<I>>, Req(req): Req<TransferRequest>| { state.check_currency(&req.amount)?; ApiResult::Ok(Json(state.transfer(req).await?)) }, @@ -104,7 +104,7 @@ pub fn router<I: WireGateway>(state: Arc<I>, auth: AuthMethod) -> Router { .route( "/transfers", get( - |State(state): State<Arc<I>>, Query(params): Query<TransferParams>| async move { + async |State(state): State<Arc<I>>, Query(params): Query<TransferParams>| { let page = params.pagination.check(MAX_PAGE_SIZE)?; let list = state.transfer_page(page, params.status).await?; ApiResult::Ok(if list.transfers.is_empty() { @@ -117,22 +117,20 @@ pub fn router<I: WireGateway>(state: Arc<I>, auth: AuthMethod) -> Router { ) .route( "/transfers/{id}", - get( - |State(state): State<Arc<I>>, Path(id): Path<u64>| async move { - match state.transfer_by_id(id).await? { - Some(it) => Ok(Json(it)), - None => Err(failure( - ErrorCode::BANK_TRANSACTION_NOT_FOUND, - format!("Transfer '{id}' not found"), - )), - } - }, - ), + get(async |State(state): State<Arc<I>>, Path(id): Path<u64>| { + match state.transfer_by_id(id).await? { + Some(it) => Ok(Json(it)), + None => Err(failure( + ErrorCode::BANK_TRANSACTION_NOT_FOUND, + format!("Transfer '{id}' not found"), + )), + } + }), ) .route( "/history/incoming", get( - |State(state): State<Arc<I>>, Query(params): Query<HistoryParams>| async move { + async |State(state): State<Arc<I>>, Query(params): Query<HistoryParams>| { let params = params.check(MAX_PAGE_SIZE, MAX_TIMEOUT_MS)?; let history = state.incoming_history(params).await?; ApiResult::Ok(if history.incoming_transactions.is_empty() { @@ -146,7 +144,7 @@ pub fn router<I: WireGateway>(state: Arc<I>, auth: AuthMethod) -> Router { .route( "/history/outgoing", get( - |State(state): State<Arc<I>>, Query(params): Query<HistoryParams>| async move { + async |State(state): State<Arc<I>>, Query(params): Query<HistoryParams>| { let params = params.check(MAX_PAGE_SIZE, MAX_TIMEOUT_MS)?; let history = state.outgoing_history(params).await?; ApiResult::Ok(if history.outgoing_transactions.is_empty() { @@ -160,7 +158,7 @@ pub fn router<I: WireGateway>(state: Arc<I>, auth: AuthMethod) -> Router { .route( "/admin/add-incoming", post( - |State(state): State<Arc<I>>, Req(req): Req<AddIncomingRequest>| async move { + async |State(state): State<Arc<I>>, Req(req): Req<AddIncomingRequest>| { state.check_currency(&req.amount)?; ApiResult::Ok(Json(state.add_incoming_reserve(req).await?)) }, @@ -169,7 +167,7 @@ pub fn router<I: WireGateway>(state: Arc<I>, auth: AuthMethod) -> Router { .route( "/admin/add-kycauth", post( - |State(state): State<Arc<I>>, Req(req): Req<AddKycauthRequest>| async move { + async |State(state): State<Arc<I>>, Req(req): Req<AddKycauthRequest>| { state.check_currency(&req.amount)?; ApiResult::Ok(Json(state.add_incoming_kyc(req).await?)) }, @@ -178,18 +176,19 @@ pub fn router<I: WireGateway>(state: Arc<I>, auth: AuthMethod) -> Router { .route( "/account/check", get( - |State(state): State<Arc<I>>, Query(params): Query<AccountParams>| async move { - match state.account_check(params).await? { - Some(it) => Ok(Json(it)), - None => Err(failure_code(ErrorCode::BANK_UNKNOWN_ACCOUNT)), - } + async |State(state): State<Arc<I>>, Query(params): Query<AccountParams>| match state + .account_check(params) + .await? + { + Some(it) => Ok(Json(it)), + None => Err(failure_code(ErrorCode::BANK_UNKNOWN_ACCOUNT)), }, ), ) .auth(auth, "taler-wire-gateway") .route( "/config", - get(|State(state): State<Arc<I>>| async move { + get(async |State(state): State<Arc<I>>| { Json(WireConfig { name: "taler-wire-gateway", version: WIRE_GATEWAY_API_VERSION, diff --git a/common/taler-api/src/db.rs b/common/taler-api/src/db.rs @@ -90,7 +90,7 @@ pub async fn history<'a, 'b, R: Send + Unpin>( prepare: impl Fn() -> QueryBuilder<'a, Postgres> + Copy, map: impl Fn(PgRow) -> Result<R, Error> + Send + Copy, ) -> Result<Vec<R>, Error> { - let load = || async { page(pool, id_col, &params.page, prepare, map).await }; + let load = async || page(pool, id_col, &params.page, prepare, map).await; // When going backward there is always at least one transaction or none if params.page.limit >= 0 && params.timeout_ms.is_some_and(|it| it > 0) { diff --git a/common/taler-api/tests/api.rs b/common/taler-api/tests/api.rs @@ -75,7 +75,7 @@ async fn outgoing_history() { .map(|it| *it.row_id as i64) .collect() }, - |server, i| async move { + async |server, i| { server .post("/taler-wire-gateway/transfer") .json(&json!({ diff --git a/common/taler-test-utils/src/routine.rs b/common/taler-test-utils/src/routine.rs @@ -15,7 +15,6 @@ */ use std::{ - borrow::Cow, fmt::Debug, future::Future, time::{Duration, Instant}, @@ -54,12 +53,12 @@ pub async fn routine_pagination<'a, T: DeserializeOwned, F: Future<Output = ()>> } // Check history is following specs - let assert_history = |args: Cow<'static, str>, size: usize| async move { + let assert_history = async |args: &str, size: usize| { let resp = server.get(&format!("{url}?{args}")).await; assert_history_ids(&resp, ids, size) }; // Get latest registered id - let latest_id = || async move { assert_history("limit=-1".into(), 1).await[0] }; + let latest_id = async || assert_history("limit=-1", 1).await[0]; for i in 0..20 { register(server, i).await; @@ -68,15 +67,15 @@ pub async fn routine_pagination<'a, T: DeserializeOwned, F: Future<Output = ()>> let id = latest_id().await; // default - assert_history("".into(), 20).await; + assert_history("", 20).await; // forward range - assert_history("limit=10".into(), 10).await; - assert_history("limit=10&offset=4".into(), 10).await; + assert_history("limit=10", 10).await; + assert_history("limit=10&offset=4", 10).await; // backward range - assert_history("limit=-10".into(), 10).await; - assert_history(format!("limit=-10&{}", id - 4).into(), 10).await; + assert_history("limit=-10", 10).await; + assert_history(&format!("limit=-10&{}", id - 4), 10).await; } pub async fn assert_time<R: Debug>(range: std::ops::Range<u128>, task: impl Future<Output = R>) { @@ -112,7 +111,7 @@ pub async fn routine_history< }; } // Get latest registered id - let latest_id = || async { assert_history!("limit=-1", 1).await[0] }; + let latest_id = async || assert_history!("limit=-1", 1).await[0]; // Check error when no transactions assert_history!("limit=7".to_owned(), 0).await; @@ -415,7 +414,7 @@ pub async fn transfer_routine( .map(|it| *it.row_id as i64) .collect() }, - |server, i| async move { + async |server, i| { server .post("/taler-wire-gateway/transfer") .json(&json!({ @@ -521,7 +520,7 @@ pub async fn revenue_routine(server: &Router, debit_acount: &PaytoURI, kyc: bool .collect() }, 2, - |server, i| async move { + async |server, i| { if i % 2 == 0 || !kyc { server .post("/taler-wire-gateway/admin/add-incoming") @@ -545,7 +544,7 @@ pub async fn revenue_routine(server: &Router, debit_acount: &PaytoURI, kyc: bool } }, 0, - |_, _| async move {}, + async |_, _| {}, ) .await; } @@ -570,7 +569,7 @@ pub async fn admin_add_incoming_routine(server: &Router, debit_acount: &PaytoURI .collect() }, 2, - |server, i| async move { + async |server, i| { if i % 2 == 0 || !kyc { server .post("/taler-wire-gateway/admin/add-incoming") @@ -594,7 +593,7 @@ pub async fn admin_add_incoming_routine(server: &Router, debit_acount: &PaytoURI } }, 0, - |_, _| async move {}, + async |_, _| {}, ) .await; // Add incoming reserve diff --git a/taler-cyclos/src/bin/cyclos-harness.rs b/taler-cyclos/src/bin/cyclos-harness.rs @@ -623,10 +623,8 @@ async fn online_harness(config: &Config, reset: bool) -> anyhow::Result<()> { fn main() { let args = Args::parse(); - taler_main(CONFIG_SOURCE, args.common, |cfg| async move { - match args.cmd { - Command::Logic { reset } => logic_harness(&cfg, reset).await, - Command::Online { reset } => online_harness(&cfg, reset).await, - } + taler_main(CONFIG_SOURCE, args.common, async |cfg| match args.cmd { + Command::Logic { reset } => logic_harness(&cfg, reset).await, + Command::Online { reset } => online_harness(&cfg, reset).await, }); } diff --git a/taler-cyclos/src/main.rs b/taler-cyclos/src/main.rs @@ -144,7 +144,7 @@ async fn run(cmd: Command, cfg: &Config) -> anyhow::Result<()> { fn main() { let args = Args::parse(); - taler_main(CONFIG_SOURCE, args.common, |cfg| async move { + taler_main(CONFIG_SOURCE, args.common, async |cfg| { run(args.cmd, &cfg).await }); } diff --git a/taler-cyclos/tests/api.rs b/taler-cyclos/tests/api.rs @@ -95,31 +95,27 @@ async fn outgoing_history() { .map(|it| *it.row_id as i64) .collect() }, - |_, i| { - let acquire = pool.acquire(); - async move { - let mut conn = acquire.await.unwrap(); - db::register_tx_out( - &mut conn, - &db::TxOut { - transfer_id: i as i64, - tx_id: if i % 2 == 0 { - Some((i % 2) as i64) - } else { - None - }, - amount: decimal("10"), - subject: "subject".to_owned(), - creditor_id: 31000163100000000, - creditor_name: "Name".to_string(), - valued_at: Timestamp::now(), + async |_, i| { + db::register_tx_out( + &mut pool.acquire().await.unwrap(), + &db::TxOut { + transfer_id: i as i64, + tx_id: if i % 2 == 0 { + Some((i % 2) as i64) + } else { + None }, - &TxOutKind::Talerable(OutgoingSubject::rand()), - &Timestamp::now(), - ) - .await - .unwrap(); - } + amount: decimal("10"), + subject: "subject".to_owned(), + creditor_id: 31000163100000000, + creditor_name: "Name".to_string(), + valued_at: Timestamp::now(), + }, + &TxOutKind::Talerable(OutgoingSubject::rand()), + &Timestamp::now(), + ) + .await + .unwrap(); }, ) .await; diff --git a/taler-magnet-bank/src/bin/magnet-bank-harness.rs b/taler-magnet-bank/src/bin/magnet-bank-harness.rs @@ -575,10 +575,8 @@ async fn online_harness(config: &Config, reset: bool) -> anyhow::Result<()> { fn main() { let args = Args::parse(); - taler_main(CONFIG_SOURCE, args.common, |cfg| async move { - match args.cmd { - Command::Logic { reset } => logic_harness(&cfg, reset).await, - Command::Online { reset } => online_harness(&cfg, reset).await, - } + taler_main(CONFIG_SOURCE, args.common, async |cfg| match args.cmd { + Command::Logic { reset } => logic_harness(&cfg, reset).await, + Command::Online { reset } => online_harness(&cfg, reset).await, }); } diff --git a/taler-magnet-bank/src/main.rs b/taler-magnet-bank/src/main.rs @@ -144,7 +144,7 @@ async fn run(cmd: Command, cfg: &Config) -> anyhow::Result<()> { fn main() { let args = Args::parse(); - taler_main(CONFIG_SOURCE, args.common, |cfg| async move { + taler_main(CONFIG_SOURCE, args.common, async |cfg| { run(args.cmd, &cfg).await }); } diff --git a/taler-magnet-bank/tests/api.rs b/taler-magnet-bank/tests/api.rs @@ -91,29 +91,26 @@ async fn outgoing_history() { .map(|it| *it.row_id as i64) .collect() }, - |_, i| { - let acquire = pool.acquire(); - async move { - let mut conn = acquire.await.unwrap(); - let now = Zoned::now().date(); - db::register_tx_out( - &mut conn, - &db::TxOut { - code: i as u64, - amount: amount("EUR:10"), - subject: "subject".to_owned(), - creditor: magnet_payto( - "payto://iban/HU30162000031000163100000000?receiver-name=name", - ), - value_date: now, - status: TxStatus::Completed, - }, - &TxOutKind::Talerable(OutgoingSubject::rand()), - &Timestamp::now(), - ) - .await - .unwrap(); - } + async |_, i| { + let mut conn = pool.acquire().await.unwrap(); + let now = Zoned::now().date(); + db::register_tx_out( + &mut conn, + &db::TxOut { + code: i as u64, + amount: amount("EUR:10"), + subject: "subject".to_owned(), + creditor: magnet_payto( + "payto://iban/HU30162000031000163100000000?receiver-name=name", + ), + value_date: now, + status: TxStatus::Completed, + }, + &TxOutKind::Talerable(OutgoingSubject::rand()), + &Timestamp::now(), + ) + .await + .unwrap(); }, ) .await;