Skip to content

Commit

Permalink
add token minting for ExternalWalletTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Jan 26, 2022
1 parent d03d110 commit 951e6d4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jormungandr-lib/src/interfaces/mint_token.rs
Expand Up @@ -52,7 +52,7 @@ impl<'de> Deserialize<'de> for TokenName {
}
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Hash, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct TokenIdentifier(identifier::TokenIdentifier);

impl From<identifier::TokenIdentifier> for TokenIdentifier {
Expand Down
1 change: 1 addition & 0 deletions jormungandr-lib/src/interfaces/mod.rs
Expand Up @@ -57,6 +57,7 @@ pub use self::fragments_processing_summary::{
};
pub use self::leadership_log::{LeadershipLog, LeadershipLogId, LeadershipLogStatus};
pub use self::linear_fee::{LinearFeeDef, PerCertificateFeeDef, PerVoteCertificateFeeDef};
pub use self::mint_token::TokenIdentifier;
pub use self::old_address::OldAddress;
pub use self::peer_stats::{PeerRecord, PeerStats, Subscription};
pub use self::ratio::{ParseRatioError, Ratio};
Expand Down
22 changes: 21 additions & 1 deletion testing/hersir/src/builder/settings.rs
Expand Up @@ -9,11 +9,14 @@ use assert_fs::fixture::PathChild;
use chain_crypto::Ed25519;
use chain_impl_mockchain::block::BlockDate;
use chain_impl_mockchain::testing::create_initial_vote_plan;
use chain_impl_mockchain::tokens::minting_policy::MintingPolicy;
use chain_impl_mockchain::{
certificate::VotePlan, chaintypes::ConsensusVersion, fee::LinearFee, vote::PayloadType,
};
use jormungandr_automation::jormungandr::NodeAlias;
use jormungandr_lib::crypto::account::Identifier;
use jormungandr_lib::interfaces::Destination;
use jormungandr_lib::interfaces::InitialToken;
use jormungandr_lib::interfaces::{try_initial_fragment_from_message, VotePlan as VotePLanLib};
use jormungandr_lib::{
crypto::key::SigningKey,
Expand Down Expand Up @@ -100,11 +103,28 @@ impl Settings {
external_wallets: Vec<ExternalWalletTemplate>,
) {
for template in external_wallets {
let address: jormungandr_lib::interfaces::Address = template.address().parse().unwrap();

let external_fragment = Initial::Fund(vec![InitialUTxO {
address: template.address().parse().unwrap(),
address: address.clone(),
value: (*template.value()).into(),
}]);

self.block0.initial.push(external_fragment);

for (token_identifier, value) in template.tokens() {
let tokens_fragment = Initial::Token(InitialToken {
token_id: token_identifier.clone(),
// TODO: there are no policies now, but this will need to be changed later
policy: MintingPolicy::new().into(),
to: vec![Destination {
address: address.clone(),
value: (*value).into(),
}],
});

self.block0.initial.push(tokens_fragment);
}
}
}

Expand Down
17 changes: 15 additions & 2 deletions testing/hersir/src/builder/wallet/template/external.rs
@@ -1,5 +1,7 @@
use std::collections::HashMap;

use chain_impl_mockchain::value::Value;
use jormungandr_lib::interfaces::ValueDef;
use jormungandr_lib::interfaces::{TokenIdentifier, ValueDef};
use serde::Deserialize;
use thor::WalletAlias;

Expand All @@ -11,15 +13,22 @@ pub struct ExternalWalletTemplate {
address: String,
#[serde(with = "ValueDef")]
value: Value,
tokens: HashMap<TokenIdentifier, u64>,
}

impl ExternalWalletTemplate {
#[inline]
pub fn new<S: Into<WalletAlias>>(alias: S, value: Value, address: String) -> Self {
pub fn new<S: Into<WalletAlias>>(
alias: S,
value: Value,
address: String,
tokens: HashMap<TokenIdentifier, u64>,
) -> Self {
Self {
alias: alias.into(),
value,
address,
tokens,
}
}

Expand All @@ -31,6 +40,10 @@ impl ExternalWalletTemplate {
&self.address
}

pub fn tokens(&self) -> &HashMap<TokenIdentifier, u64> {
&self.tokens
}

pub fn alias(&self) -> WalletAlias {
self.alias.clone()
}
Expand Down

0 comments on commit 951e6d4

Please sign in to comment.