pub fn mint_coins(&mut self, space_delim_strings: &[&str], is_blocking: bool) -> Result<()> {
        ensure!(
            space_delim_strings.len() >= 4 && space_delim_strings.len() <= 5,
            "Invalid number of arguments for mint"
        );
        let (receiver, receiver_auth_key_opt) =
            self.get_account_address_from_parameter(space_delim_strings[1])?;
        let receiver_auth_key = receiver_auth_key_opt.ok_or_else(|| {
            format_err!("Need authentication key to create new account via minting from facuet")
        })?;
        let mint_currency = space_delim_strings[3];
        let use_base_units = space_delim_strings
            .get(4)
            .map(|s| s == &"use_base_units")
            .unwrap_or(false);
        let num_coins = if !use_base_units {
            self.convert_to_on_chain_representation(space_delim_strings[2], mint_currency)?
        } else {
            Self::convert_to_scaled_representation(space_delim_strings[2], 1, 1)?
        };
        let currency_code = from_currency_code_string(mint_currency)
            .map_err(|_| format_err!("Invalid currency code {} provided to mint", mint_currency))?;

        ensure!(
            num_coins > 0,
            "Invalid number of coins to transfer from faucet."
        );

        if self.tc_account.is_some() {
            let script = transaction_builder::encode_create_parent_vasp_account_script(
                type_tag_for_currency_code(currency_code.clone()),
                0,
                receiver,
                receiver_auth_key.prefix().to_vec(),
                b"testnet".to_vec(),
                false, /* add all currencies */
            );
            // If the receiver is local, create it now.
            if let Some(pos) = self
                .accounts
                .iter()
                .position(|account_data| account_data.address == receiver)
            {
                let status = &self.accounts.get(pos).unwrap().status;
                if &AccountStatus::Local == status {
                    println!(">> Creating recipient account before minting from faucet");
                    // This needs to be blocking since the mint can't happen until it completes
                    self.association_transaction_with_local_tc_account(
                        TransactionPayload::Script(script),
                        true,
                    )?;
                    self.accounts.get_mut(pos).unwrap().status = AccountStatus::Persisted;
                }
            } else {
                // We can't determine the account state. So try and create the account, but
                // if it already exists don't error.
                let _result = self.association_transaction_with_local_tc_account(
                    TransactionPayload::Script(script),
                    true,
                );
            } // else, the account has already been created -- do nothing
        }

        println!(">> Sending coins from faucet");
        match self.testnet_designated_dealer_account {
            Some(_) => {
                let script = transaction_builder::encode_peer_to_peer_with_metadata_script(
                    type_tag_for_currency_code(currency_code),
                    receiver,
                    num_coins,
                    vec![],
                    vec![],
                );
                self.association_transaction_with_local_testnet_dd_account(
                    TransactionPayload::Script(script),
                    is_blocking,
                )
            }
            None => self.mint_coins_with_faucet_service(
                receiver_auth_key,
                num_coins,
                mint_currency.to_owned(),
                is_blocking,
            ),
        }
    }
/// Mints coins for the receiver specified.
Mints coins for the receiver specified.
Mints coins for the receiver specified .
pub fn mint_coins(&mut self, space_delim_strings: &[&str], is_blocking: bool) -> Result<()> {
        ensure!(
            space_delim_strings.len() >= 4 && space_delim_strings.len() <= 5,
            "Invalid number of arguments for mint"
        );
        let (receiver, receiver_auth_key_opt) =
            self.get_account_address_from_parameter(space_delim_strings[1])?;
        let receiver_auth_key = receiver_auth_key_opt.ok_or_else(|| {
            format_err!("Need authentication key to create new account via minting from facuet")
        })?;
        let mint_currency = space_delim_strings[3];
        let use_base_units = space_delim_strings
            .get(4)
            .map(|s| s == &"use_base_units")
            .unwrap_or(false);
        let num_coins = if !use_base_units {
            self.convert_to_on_chain_representation(space_delim_strings[2], mint_currency)?
        } else {
            Self::convert_to_scaled_representation(space_delim_strings[2], 1, 1)?
        };
        let currency_code = from_currency_code_string(mint_currency)
            .map_err(|_| format_err!("Invalid currency code {} provided to mint", mint_currency))?;
        ensure!(
            num_coins > 0,
            "Invalid number of coins to transfer from faucet."
        );
        if self.tc_account.is_some() {
            let script = transaction_builder::encode_create_parent_vasp_account_script(
                type_tag_for_currency_code(currency_code.clone()),
                0,
                receiver,
                receiver_auth_key.prefix().to_vec(),
                b"testnet".to_vec(),
                false, /* add all currencies */
            );
            // If the receiver is local, create it now.
            if let Some(pos) = self
                .accounts
                .iter()
                .position(|account_data| account_data.address == receiver)
            {
                let status = &self.accounts.get(pos).unwrap().status;
                if &AccountStatus::Local == status {
                    println!(">> Creating recipient account before minting from faucet");
                    // This needs to be blocking since the mint can't happen until it completes
                    self.association_transaction_with_local_tc_account(
                        TransactionPayload::Script(script),
                        true,
                    )?;
                    self.accounts.get_mut(pos).unwrap().status = AccountStatus::Persisted;
                }
            } else {
                // We can't determine the account state. So try and create the account, but
                // if it already exists don't error.
                let _result = self.association_transaction_with_local_tc_account(
                    TransactionPayload::Script(script),
                    true,
                );
            } // else, the account has already been created -- do nothing
        }
        println!(">> Sending coins from faucet");
        match self.testnet_designated_dealer_account {
            Some(_) => {
                let script = transaction_builder::encode_peer_to_peer_with_metadata_script(
                    type_tag_for_currency_code(currency_code),
                    receiver,
                    num_coins,
                    vec![],
                    vec![],
                );
                self.association_transaction_with_local_testnet_dd_account(
                    TransactionPayload::Script(script),
                    is_blocking,
                )
            }
            None => self.mint_coins_with_faucet_service(
                receiver_auth_key,
                num_coins,
                mint_currency.to_owned(),
                is_blocking,
            ),
        }
    }
pub fn mint_coins ( & mut self , space_delim_strings : & [ & str ] , is_blocking : bool ) -> Result < ( ) > { ensure ! ( space_delim_strings len ( ) 4 space_delim_strings len ( ) 5 " " ) ; let ( receiver , receiver_auth_key_opt ) = self . get_account_address_from_parameter ( space_delim_strings [ 1 ] ) ? ; let receiver_auth_key = receiver_auth_key_opt . ok_or_else ( | | { format_err ! ( " " ) } ) ? ; let mint_currency = space_delim_strings [ 3 ] ; let use_base_units = space_delim_strings . get ( 4 ) . map ( | s | s == & " " ) . unwrap_or ( false ) ; let num_coins = if ! use_base_units { self . convert_to_on_chain_representation ( space_delim_strings [ 2 ] , mint_currency ) ? } else { Self :: convert_to_scaled_representation ( space_delim_strings [ 2 ] , 1 , 1 ) ? } ; let currency_code = from_currency_code_string ( mint_currency ) . map_err ( | _ | format_err ! ( " " mint_currency ) ) ? ; ensure ! ( num_coins 0 " " ) ; if self . tc_account . is_some ( ) { let script = transaction_builder :: encode_create_parent_vasp_account_script ( type_tag_for_currency_code ( currency_code . clone ( ) ) , 0 , receiver , receiver_auth_key . prefix ( ) . to_vec ( ) , b" " . to_vec ( ) , false , /* add all currencies */ ) ; // If the receiver is local, create it now. if let Some ( pos ) = self . accounts . iter ( ) . position ( | account_data | account_data . address == receiver ) { let status = & self . accounts . get ( pos ) . unwrap ( ) . status ; if & AccountStatus :: Local == status { println ! ( " " ) ; // This needs to be blocking since the mint can't happen until it completes self . association_transaction_with_local_tc_account ( TransactionPayload :: Script ( script ) , true , ) ? ; self . accounts . get_mut ( pos ) . unwrap ( ) . status = AccountStatus :: Persisted ; } } else { // We can't determine the account state. So try and create the account, but // if it already exists don't error. let _result = self . association_transaction_with_local_tc_account ( TransactionPayload :: Script ( script ) , true , ) ; } // else, the account has already been created -- do nothing } println ! ( " " ) ; match self . testnet_designated_dealer_account { Some ( _ ) => { let script = transaction_builder :: encode_peer_to_peer_with_metadata_script ( type_tag_for_currency_code ( currency_code ) , receiver , num_coins , vec ! [ ] , vec ! [ ] , ) ; self . association_transaction_with_local_testnet_dd_account ( TransactionPayload :: Script ( script ) , is_blocking , ) } None => self . mint_coins_with_faucet_service ( receiver_auth_key , num_coins , mint_currency . to_owned ( ) , is_blocking , ) , } }
Mints coins for the receiver specified.
Mints coins for the receiver specified .
&mut self
space_delim_strings
&[&str]
is_blocking
bool
&mut self
space_delim_strings
&[&str]
is_blocking
bool