-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add MintToken interface struct, add it into the Initial struct as a f…
…ield
- Loading branch information
Showing
14 changed files
with
180 additions
and
76 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
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use super::Value; | ||
use crate::crypto::account::Identifier; | ||
use chain_crypto::bech32::Bech32; | ||
use chain_impl_mockchain::{ | ||
certificate, | ||
tokens::{minting_policy, name}, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
struct TokenName(name::TokenName); | ||
|
||
impl From<name::TokenName> for TokenName { | ||
fn from(val: name::TokenName) -> Self { | ||
Self(val) | ||
} | ||
} | ||
|
||
impl Serialize for TokenName { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
self.0.to_bech32_str().serialize(serializer) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for TokenName { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
let s = String::deserialize(deserializer)?; | ||
Ok(Self( | ||
name::TokenName::try_from_bech32_str(&s) | ||
.map_err(<D::Error as serde::de::Error>::custom)?, | ||
)) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Default)] | ||
pub struct MintingPolicy(minting_policy::MintingPolicy); | ||
|
||
impl From<minting_policy::MintingPolicy> for MintingPolicy { | ||
fn from(val: minting_policy::MintingPolicy) -> Self { | ||
Self(val) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct MintToken { | ||
name: TokenName, | ||
// TODO add a serde implementation for the MintingPolicy when it will be well specified | ||
#[serde(skip)] | ||
policy: MintingPolicy, | ||
to: Identifier, | ||
value: Value, | ||
} | ||
|
||
impl From<certificate::MintToken> for MintToken { | ||
fn from(val: certificate::MintToken) -> Self { | ||
Self { | ||
name: val.name.into(), | ||
policy: val.policy.into(), | ||
to: val.to.into(), | ||
value: val.value.into(), | ||
} | ||
} | ||
} | ||
|
||
impl From<MintToken> for certificate::MintToken { | ||
fn from(val: MintToken) -> Self { | ||
Self { | ||
name: val.name.0, | ||
policy: val.policy.0, | ||
to: val.to.to_inner(), | ||
value: val.value.into(), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use quickcheck::Arbitrary; | ||
|
||
use super::*; | ||
|
||
impl Arbitrary for MintToken { | ||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self { | ||
certificate::MintToken::arbitrary(g).into() | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.