Skip to content

Commit

Permalink
cosmrs: Coin constructor (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrit committed Sep 12, 2022
1 parent 9d13faf commit cd6a758
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cosmrs/src/base.rs
Expand Up @@ -136,6 +136,16 @@ pub struct Coin {
pub amount: u128,
}

impl Coin {
/// Constructor
pub fn new(amount: u128, denom: &str) -> Result<Self> {
Ok(Coin {
amount,
denom: denom.parse()?,
})
}
}

impl TryFrom<proto::cosmos::base::v1beta1::Coin> for Coin {
type Error = ErrorReport;

Expand Down Expand Up @@ -224,7 +234,7 @@ impl Serialize for Denom {

#[cfg(test)]
mod tests {
use super::{AccountId, Denom};
use super::{AccountId, Coin, Denom};

#[test]
fn account_id() {
Expand All @@ -248,4 +258,9 @@ mod tests {
.is_ok()
);
}

#[test]
fn coin() {
Coin::new(1000, "uatom").unwrap();
}
}

0 comments on commit cd6a758

Please sign in to comment.