Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CLI): Generalize new account command #728

Open
wants to merge 10 commits into
base: next
Choose a base branch
from

Conversation

igamigo
Copy link
Collaborator

@igamigo igamigo commented Feb 12, 2025

Closes #695

This can be tested with something like this:

miden init

miden new-account --account-type fungible-faucet -c basic-fungible-faucet -i init_data.toml

Succesfully created new account. 
To view account details execute `miden account -s 0x8318a196a267aea0000006b51e173a`

Where init_data.toml is:

token_metadata.decimals=10
token_metadata.max_supply=10000000
token_metadata.ticker="TST"

If no TOML is provided, it looks like this:

miden new-account --account-type fungible-faucet -c fungible_faucet

Enter value for 'token_metadata.decimals' - Number of decimal places (type: u8): 3
Enter value for 'token_metadata.max_supply' - Maximum supply of the token in base units (type: felt): 3
Enter value for 'token_metadata.ticker' - Token symbol of the faucet's asset, limited to 4 characters. (type: tokensymbol): 3
Error: cli::account_error

  × account error: error instantiating component from template
  ├─▶ failed to create account component
  ├─▶ error converting value into expected type:
  ╰─▶ failed to parse input `3` as `tokensymbol`

TODO:

  • Refactor and deduplicate file name constants (and decide on a naming scheme).
  • Address TODOs in these changes (removing unwraps)
  • Fix integration tests using the InitStorageData::from_toml function
  • (probably on another PR) Decide how to further generalize this. For example, this still assumes the basic auth component always goes into the first slot. This in turn interacts with things such as import/export functionality, where we assume the public key is in a specific place. With the work related to detecting account features in miden-base, we could do all of this better.

@igamigo igamigo changed the title feat: Generalize new account feat(CLI): Generalize new account command Feb 12, 2025
@igamigo igamigo force-pushed the igamigo-general-new-acct branch from dcbe31c to ee9baf4 Compare February 12, 2025 15:42
@igamigo igamigo marked this pull request as ready for review February 12, 2025 18:37
Copy link
Collaborator

@tomyrd tomyrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some tests with the CLI and it seems to work correctly 👍 We should update the integration CLI tests with the new new-account command

Comment on lines 38 to 39
// TODO: Do we want to add this?
output_filename.push(".mct");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's value in having different extensions. Just so we can differentiate templates from account files and exported notes

std::io::stdin().read_line(&mut input_value)?;
let input_value = input_value.trim();
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum CliAccountType {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a small description mentioning that this is a redefinition of the AccountType struct.

AccountType::RegularAccountImmutableCode
};

// Use the provided account type.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment is a little out of place here, we could add it in line 247

@@ -0,0 +1,15 @@
name = "fungible_faucet"
description = "This is a test component"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this template will be used in the CLI I would change this description.

@igamigo igamigo changed the base branch from next to igamigo-next-base February 13, 2025 20:00
Comment on lines 19 to 20
const FAUCET_TEMPLATE_BYTES: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/templates/faucet.mct"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a bit more descriptive (both the constant name and the file name) - e.g., basic_fungible_faucet.mct.

/// Helper function to process extra component templates.
/// It reads user input for each placeholder in a component template.
// TODO: this could take a TOML file with key-values
fn process_component_templates(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would probably move this function to the end of the file into the "HELPER FUNCTIONS" section.

Comment on lines 153 to 156
print!(
"Enter value for placeholder '{placeholder_key}' - {description} (type: {}): ",
placeholder_type.r#type.to_string()
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this print out? Maybe it should look more like:

Enter value for 'token_metadata.max_supply' - maximum supply of the token in base units (type: felt):

Base automatically changed from igamigo-next-base to next February 17, 2025 17:14
@igamigo igamigo force-pushed the igamigo-general-new-acct branch 2 times, most recently from 140d424 to 380cace Compare February 20, 2025 21:43
@igamigo igamigo force-pushed the igamigo-general-new-acct branch from 380cace to 4a60d04 Compare February 20, 2025 21:46
Copy link
Collaborator

@tomyrd tomyrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good and I did some local tests which worked! The integration tests seem to be failing because of the CLI tests which should be updated.

Comment on lines 147 to 150
CliError::Config(
"failed to create account component templates directory".to_string().into(),
err.to_string(),
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be like:

Suggested change
CliError::Config(
"failed to create account component templates directory".to_string().into(),
err.to_string(),
)
CliError::Config(
err.into()
"failed to create account component templates directory".to_string()
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants