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: Use AccountComponentTemplate #680

Merged
merged 8 commits into from
Jan 27, 2025
Merged

Conversation

igamigo
Copy link
Collaborator

@igamigo igamigo commented Jan 20, 2025

No description provided.

@igamigo igamigo changed the title feat: Use AccountComponentTemplate feat: Use AccountComponentTemplate Jan 20, 2025
Base automatically changed from igamigo-block-num to next January 21, 2025 18:00
@igamigo igamigo force-pushed the igamigo-component-template branch 4 times, most recently from b4ae4b1 to 3ed6e41 Compare January 24, 2025 03:35
@igamigo igamigo marked this pull request as ready for review January 24, 2025 03:36
Copy link
Collaborator

@SantiagoPittella SantiagoPittella left a comment

Choose a reason for hiding this comment

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

Overall looks good. We can make use of the recently-merged CliError enum.

@igamigo igamigo force-pushed the igamigo-component-template branch from 568c3ca to 40baa5a Compare January 24, 2025 22:00
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you. I left some comments inline. Some are minor and others are for bigger refactorings in the future.

Also, would be good to add some documentation about how this new functionality can be used.

bin/miden-cli/src/commands/new_account.rs Outdated Show resolved Hide resolved
Comment on lines 213 to 215
#[derive(Debug, Parser, Clone)]
/// Create a new wallet account.
pub struct NewWalletCmd {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same nit as above re putting comments above attributes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually meant docs/attributes on lines 213 - 214 (not for the internal fields). Re-arranging them for the fields is fine too - but let's make sure the descriptions still show up in the CLI correctly.

bin/miden-cli/src/commands/new_account.rs Outdated Show resolved Hide resolved
Comment on lines +40 to +60
/// 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(
extra_components: &[AccountComponentTemplate],
) -> Result<Vec<AccountComponent>, CliError> {
let mut account_components = vec![];
for component_template in extra_components {
let mut init_storage_data = BTreeMap::new();
for (placeholder_key, placeholder_type) in
component_template.metadata().get_unique_storage_placeholders()
{
print!(
"Enter hex value for placeholder '{}' (type: {}): ",
placeholder_key, placeholder_type
);
std::io::stdout().flush()?;

let mut input_value = String::new();
std::io::stdin().read_line(&mut input_value)?;
let input_value = input_value.trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

This approach is fine for this PR, but it is actually different from how I originally thought about it. Specifically, I was imagining that we'd prompt the user to provide data for specific fields and so we'd show a filed name and a field description to the user (rather than showing placeholder and type).

This may require refactoring the structure in miden-base - maybe to move away from placeholder-based approach and more toward specifying something like a "type" or a "kind" for a given storage slot. Let's create an issue for this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see. I think we could show the storage slot metadata here (name and description), but not specifically for the values themselves although the placeholder itself does not carry this data (so it would have to be searched in the template metadata). Is this what you meant? Or did you mean more specific to the value?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think ideally we'd iterate over all slots that require user input, show slot name/description, and allow user to enter the required values (there may be more than one value needed per slot). What we now call placeholder may need to be treated more like a "type" of the data. For example, we may have 3 slots each expecting Falcon public keys and so all 3 would have type auth::rpo_falcon512 (or something like this) - but the user should be able to provide 3 different public keys.

There are a few details to think through here - so, probably warrants a separate issue.

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left just one nit inline. Once we address it and add some docs, we are good to merge.

Comment on lines 213 to 215
#[derive(Debug, Parser, Clone)]
/// Create a new wallet account.
pub struct NewWalletCmd {
Copy link
Contributor

Choose a reason for hiding this comment

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

I actually meant docs/attributes on lines 213 - 214 (not for the internal fields). Re-arranging them for the fields is fine too - but let's make sure the descriptions still show up in the CLI correctly.

@igamigo igamigo merged commit 4ce0495 into next Jan 27, 2025
13 checks passed
@igamigo igamigo deleted the igamigo-component-template branch January 27, 2025 13:46
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.

3 participants