-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update deps and add PortId ArgParser implementation
1 parent
ffe0552
commit edd565b
Showing
4 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use core::marker::PhantomData; | ||
use core::str::FromStr; | ||
|
||
use cgp::prelude::*; | ||
use ibc::core::host::types::identifiers::PortId; | ||
|
||
use crate::traits::parse::ArgParser; | ||
|
||
const TRANSFER_PORT_ID: &str = "transfer"; | ||
|
||
pub struct ParsePortId<Parsed>(pub PhantomData<Parsed>); | ||
|
||
impl<App, Args, Tag, Parsed> ArgParser<App, Args, Tag> for ParsePortId<Parsed> | ||
where | ||
App: CanRaiseAsyncError<Parsed::Err>, | ||
Args: HasField<Tag, Value = String>, | ||
Parsed: Async + FromStr, | ||
{ | ||
type Parsed = PortId; | ||
|
||
fn parse_arg(_app: &App, args: &Args, _tag: PhantomData<Tag>) -> Result<Parsed, App::Error> { | ||
let port_id: PortId = args | ||
.get_field(PhantomData) | ||
.parse() | ||
.map_err(App::raise_error)?; | ||
|
||
if port_id.validate().is_err() { | ||
Ok(PortId::new(TRANSFER_PORT_ID.to_string())) | ||
} else { | ||
Ok(port_id) | ||
} | ||
} | ||
} |
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,2 +1,3 @@ | ||
pub mod field; | ||
pub mod identifier; | ||
pub mod string; |