From f5fb1eeb6c2b1543b4d2614f30b696d988a23134 Mon Sep 17 00:00:00 2001 From: Samuel Rufinatscha Date: Fri, 4 Mar 2022 14:14:24 +0100 Subject: [PATCH] Convert `None` case to `0` in API response (#1207) * Covert `None` case to `0` in API Response * Extract balance and dust_allowed * Update CHANGELOG.md --- bee-api/bee-rest-api/CHANGELOG.md | 8 ++++++- .../routes/api/v1/balance_ed25519.rs | 21 +++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/bee-api/bee-rest-api/CHANGELOG.md b/bee-api/bee-rest-api/CHANGELOG.md index 08c6b11b9a..499aaf768c 100644 --- a/bee-api/bee-rest-api/CHANGELOG.md +++ b/bee-api/bee-rest-api/CHANGELOG.md @@ -19,10 +19,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security --> -## 0.2.1 - 2022-02-28 +## 0.2.1 - 2022-03-04 + +### Changed - Update `bee-gossip` dependency to 0.5.0; +### Fixed + +- Convert `None` to `0` for balance response; + ## 0.2.0 - 2022-01-28 ### Added diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/balance_ed25519.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/balance_ed25519.rs index 7e10e75632..ef6f84a764 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/balance_ed25519.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/balance_ed25519.rs @@ -59,18 +59,21 @@ pub(crate) async fn balance_ed25519( "unable to fetch the balance of the address".to_string(), )) })? { - (Ok(response), ledger_index) => match response { - Some(balance) => Ok(warp::reply::json(&SuccessBody::new(BalanceAddressResponse { + (Ok(response), ledger_index) => { + let (balance, dust_allowed) = if let Some(balance) = response { + (balance.amount(), balance.dust_allowed()) + } else { + (0, false) + }; + + Ok(warp::reply::json(&SuccessBody::new(BalanceAddressResponse { address_type: Ed25519Address::KIND, address: addr.to_string(), - balance: balance.amount(), - dust_allowed: balance.dust_allowed(), + balance, + dust_allowed, ledger_index: *ledger_index, - }))), - None => Err(reject::custom(CustomRejection::NotFound( - "balance not found".to_string(), - ))), - }, + }))) + } (Err(e), _) => { error!("unable to fetch the balance of the address: {}", e); Err(reject::custom(CustomRejection::ServiceUnavailable(