Skip to content

Commit

Permalink
Convert None case to 0 in API response (#1207)
Browse files Browse the repository at this point in the history
* Covert `None` case to `0` in API Response

* Extract balance and dust_allowed

* Update CHANGELOG.md
  • Loading branch information
samuel-rufi committed Mar 4, 2022
1 parent d2a1e92 commit f5fb1ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
8 changes: 7 additions & 1 deletion bee-api/bee-rest-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f5fb1ee

Please sign in to comment.