Skip to content

Commit

Permalink
add MintToken interface struct, add it into the Initial struct as a f…
Browse files Browse the repository at this point in the history
…ield
  • Loading branch information
Mr-Leshiy committed Dec 2, 2021
1 parent 9b94284 commit 9e47f0a
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 76 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions jcli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ bech32 = "0.8"
hex = "0.4.2"
rayon = "1.5"
base64 = "0.13.0"
chain-core = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-vote = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-core = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-vote = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
jormungandr-lib = { path = "../jormungandr-lib" }
gtmpl = "0.6.0"
ed25519-bip32 = "0.4"
Expand Down
3 changes: 3 additions & 0 deletions jcli/src/jcli_lib/transaction/staging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ impl Staging {
Certificate::VoteCast(vote_cast) => {
self.make_fragment(&vote_cast, &(), Fragment::VoteCast)
}
Certificate::MintToken(mint_token) => {
self.make_fragment(&mint_token, &(), Fragment::MintToken)
}
_ => unreachable!(),
},
}
Expand Down
22 changes: 11 additions & 11 deletions jormungandr-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ description = "Data structures and formats used by Jormungandr node API and conf
bincode = "1.3"
serde = { version = "1.0", features = ["derive"] }
serde_with = { version = "1.9", features = ["macros"] }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-core = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master"}
chain-vote = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
cardano-legacy-address = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
typed-bytes = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-core = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl"}
chain-vote = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
cardano-legacy-address = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
typed-bytes = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
rand = "0.8"
rand_core = "0.6"
rand_chacha = "0.3"
Expand All @@ -36,9 +36,9 @@ quickcheck = "0.9"
quickcheck_macros = "0.9"
# FIXME required to work with quickcheck 0.9. Remove after migrating another crate or newer quickcheck
rand07 = { package = "rand", version = "0.7" }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = [ "property-test-api" ] }
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = [ "property-test-api" ] }
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = [ "property-test-api" ] }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl", features = [ "property-test-api" ] }
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl", features = [ "property-test-api" ] }
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl", features = [ "property-test-api" ] }
ed25519-bip32 = "0.4"
serde_yaml = "0.8"
serde_json = "1.0"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::interfaces::{Address, OldAddress, SignedCertificate, Value};
use crate::interfaces::{mint_token::MintToken, Address, OldAddress, SignedCertificate, Value};
use chain_impl_mockchain::{
block::BlockDate,
certificate,
Expand All @@ -16,6 +16,7 @@ pub enum Initial {
Fund(Vec<InitialUTxO>),
Cert(SignedCertificate),
LegacyFund(Vec<LegacyUTxO>),
Tokens(MintToken),
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -129,6 +130,7 @@ impl<'a> From<&'a Initial> for Fragment {
Initial::Fund(utxo) => pack_utxo_in_message(utxo),
Initial::Cert(cert) => pack_certificate_in_empty_tx_fragment(cert),
Initial::LegacyFund(utxo) => pack_legacy_utxo_in_message(utxo),
Initial::Tokens(mint_token) => pack_mint_token_in_fragment(mint_token),
}
}
}
Expand Down Expand Up @@ -203,6 +205,11 @@ fn pack_certificate_in_empty_tx_fragment(cert: &SignedCertificate) -> Fragment {
}
}

fn pack_mint_token_in_fragment(mint_token: &MintToken) -> Fragment {
let mint_token: &certificate::MintToken = &mint_token.clone().into();
Fragment::MintToken(Transaction::block0_payload(mint_token, &()))
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
93 changes: 93 additions & 0 deletions jormungandr-lib/src/interfaces/mint_token.rs
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()
}
}
}
1 change: 1 addition & 0 deletions jormungandr-lib/src/interfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod fragments_batch;
mod fragments_processing_summary;
mod leadership_log;
mod linear_fee;
mod mint_token;
mod old_address;
mod peer_stats;
mod ratio;
Expand Down
26 changes: 13 additions & 13 deletions jormungandr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ Midgard Serpent
edition = "2018"

[dependencies]
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-core = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-network = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-storage = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-vote = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
cardano-legacy-address = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
imhamt = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-core = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-network = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-storage = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-vote = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
cardano-legacy-address = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
imhamt = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }

arc-swap = "^1.1.0"
async-trait = "0.1.51"
Expand Down Expand Up @@ -72,9 +72,9 @@ features = ["rustls-tls"]
tokio = { version = "^1.4", features = ["full"] }
quickcheck = "0.9"
quickcheck_macros = "0.9"
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = [ "property-test-api" ] }
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = [ "property-test-api" ] }
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = [ "property-test-api" ] }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl", features = [ "property-test-api" ] }
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl", features = [ "property-test-api" ] }
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl", features = [ "property-test-api" ] }

[build-dependencies]
versionisator = "1.0.2"
Expand Down
4 changes: 2 additions & 2 deletions modules/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Nicolas Di Prima <nicolas.diprima@iohk.io>"]
edition = "2018"

[dependencies]
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master"}
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl"}
thiserror = "1.0.30"
lru = "0.6.6"
8 changes: 4 additions & 4 deletions testing/hersir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ edition = "2018"
assert_fs = "1.0"
custom_debug = "0.5"
ctrlc = "3.2.1"
chain-core = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = [ "property-test-api" ] }
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = [ "property-test-api" ] }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-core = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl", features = [ "property-test-api" ] }
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl", features = [ "property-test-api" ] }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "token-name-bech32-impl" }
indicatif = "0.15"
jormungandr-testing-utils = { path = "../jormungandr-testing-utils" }
jormungandr-lib = { path = "../../jormungandr-lib" }
Expand Down
Loading

0 comments on commit 9e47f0a

Please sign in to comment.