Skip to content

Commit

Permalink
Merge pull request #89 from benthecarman/match-optt
Browse files Browse the repository at this point in the history
Match on Option instead of using is_none
  • Loading branch information
johncantrell97 authored Jun 15, 2022
2 parents 235d829 + 56bac34 commit 9644a3d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
9 changes: 4 additions & 5 deletions senseicore/src/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl ChannelOpener {
.map(|(request, result)| {
if result.is_ok() {
let mut channel_counterparty_node_id = None;
let event = events.iter().find(|event| {
let event_opt = events.iter().find(|event| {
if let SenseiEvent::FundingGenerationReady {
user_channel_id,
counterparty_node_id,
Expand All @@ -148,10 +148,9 @@ impl ChannelOpener {
false
});

if event.is_none() {
(request, Err(Error::FundingGenerationNeverHappened), None)
} else {
(request, result, channel_counterparty_node_id)
match event_opt {
None => (request, Err(Error::FundingGenerationNeverHappened), None),
Some(_) => (request, result, channel_counterparty_node_id),
}
} else {
(request, result, None)
Expand Down
18 changes: 8 additions & 10 deletions src/grpc/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,15 @@ impl AdminService {
}

fn raw_token_from_metadata(&self, metadata: MetadataMap) -> Result<String, Status> {
let token = metadata.get("token");

if token.is_none() {
return Err(Status::unauthenticated("token is required"));
let token_opt = metadata.get("token");

match token_opt {
Some(token) => token
.to_str()
.map(String::from)
.map_err(|_e| Status::unauthenticated("invalid token: must be ascii")),
None => Err(Status::unauthenticated("token is required")),
}

token
.unwrap()
.to_str()
.map(String::from)
.map_err(|_e| Status::unauthenticated("invalid token: must be ascii"))
}
}

Expand Down
16 changes: 7 additions & 9 deletions src/grpc/utils.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use tonic::{metadata::MetadataMap, Status};

pub fn raw_macaroon_from_metadata(metadata: MetadataMap) -> Result<String, Status> {
let macaroon = metadata.get("macaroon");
let macaroon_opt = metadata.get("macaroon");

if macaroon.is_none() {
return Err(Status::unauthenticated("macaroon is required"));
match macaroon_opt {
Some(macaroon) => macaroon
.to_str()
.map(String::from)
.map_err(|_e| Status::unauthenticated("invalid macaroon: must be ascii")),
None => Err(Status::unauthenticated("macaroon is required")),
}

macaroon
.unwrap()
.to_str()
.map(String::from)
.map_err(|_e| Status::unauthenticated("invalid macaroon: must be ascii"))
}

0 comments on commit 9644a3d

Please sign in to comment.