Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from input-output-hk/rustfmt
apply rustfmt
- Loading branch information
Showing
12 changed files
with
302 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,57 @@ | ||
use super::super::config::{Network, Networks}; | ||
use cardano::block::EpochId; | ||
use router::{Router}; | ||
use iron::{Request}; | ||
use super::super::config::{Networks, Network}; | ||
use iron::Request; | ||
use router::Router; | ||
|
||
pub fn validate_network_name(v: &&str) -> bool { | ||
v.chars().all(|c| c.is_ascii_alphanumeric()) | ||
} | ||
|
||
pub fn validate_epochid(v: &&str) -> Option<EpochId> { | ||
if ! v.chars().all(|c| c.is_digit(10)) { | ||
if !v.chars().all(|c| c.is_digit(10)) { | ||
None | ||
} else { | ||
Some(v.parse::<EpochId>().unwrap()) | ||
} | ||
} | ||
|
||
pub fn get_network<'a>(req: &Request, networks : &'a Networks) -> Option<(String, &'a Network)> { | ||
let ref network_name = req.extensions.get::<Router>().unwrap().find("network").unwrap(); | ||
pub fn get_network<'a>(req: &Request, networks: &'a Networks) -> Option<(String, &'a Network)> { | ||
let ref network_name = req | ||
.extensions | ||
.get::<Router>() | ||
.unwrap() | ||
.find("network") | ||
.unwrap(); | ||
|
||
if ! validate_network_name (network_name) { | ||
if !validate_network_name(network_name) { | ||
return None; | ||
} | ||
|
||
match networks.get(network_name.to_owned()) { | ||
None => None, | ||
Some(net) => Some((network_name.to_string(), net)) | ||
Some(net) => Some((network_name.to_string(), net)), | ||
} | ||
} | ||
|
||
pub fn get_network_and_epoch<'a>(req: &Request, networks: &'a Networks) -> Option<(&'a Network, EpochId)> { | ||
pub fn get_network_and_epoch<'a>( | ||
req: &Request, | ||
networks: &'a Networks, | ||
) -> Option<(&'a Network, EpochId)> { | ||
let (_, net) = get_network(req, networks)?; | ||
let ref epochid_str = req.extensions.get::<Router>().unwrap().find("epochid").unwrap(); | ||
let ref epochid_str = req | ||
.extensions | ||
.get::<Router>() | ||
.unwrap() | ||
.find("epochid") | ||
.unwrap(); | ||
|
||
let epochid = match validate_epochid (epochid_str) { | ||
let epochid = match validate_epochid(epochid_str) { | ||
None => { | ||
error!("invalid epochid: {}", epochid_str); | ||
return None; | ||
}, | ||
} | ||
Some(e) => e, | ||
}; | ||
|
||
Some((net, epochid)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
pub mod common; | ||
pub mod block; | ||
pub mod pack; | ||
pub mod common; | ||
pub mod epoch; | ||
pub mod pack; | ||
pub mod tip; | ||
pub mod tx; | ||
pub mod utxos; | ||
pub mod utxos_delta; | ||
pub mod utxos_delta; |
Oops, something went wrong.