Skip to content

Commit

Permalink
feat: Generalize new account
Browse files Browse the repository at this point in the history
  • Loading branch information
igamigo committed Feb 12, 2025
1 parent 6b66ff7 commit dcbe31c
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 110 deletions.
132 changes: 67 additions & 65 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion bin/miden-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ tracing = { workspace = true }
tracing-subscriber = { version = "0.3" }

[build-dependencies]
miden-client = { version = "0.8", path = "../../crates/rust-client", default-features = false }
miden-client = { version = "0.8", path = "../../crates/rust-client", features = ["std"] }
miden-objects = { workspace = true }
miden-lib = { workspace = true }
31 changes: 25 additions & 6 deletions bin/miden-cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
use std::{env, fs, path::PathBuf};
use std::{
env, fs,
path::{Path, PathBuf},
};

use miden_client::account::component::{AccountComponentMetadata, AccountComponentTemplate};
use miden_lib::{account::components::basic_fungible_faucet_library, utils::Serializable};
use miden_objects::assembly::Library;

fn main() {
let toml_path = PathBuf::from("templates/faucet.toml");
let toml_string =
fs::read_to_string(&toml_path).expect(&format!("failed to read {}", toml_path.display()));
build_component_template(
&PathBuf::from("templates/faucet.toml"),
basic_fungible_faucet_library(),
);
}

/// Builds a component template and stores it under `{OUT_DIR}/templates`.
pub fn build_component_template(metadata_path: &Path, library: Library) {
let toml_string = fs::read_to_string(metadata_path)
.expect(&format!("failed to read {}", metadata_path.display()));

let template_metadata =
AccountComponentMetadata::from_toml(&toml_string).expect("faucet toml is well-formed");
let library = basic_fungible_faucet_library();

let faucet_component_template =
AccountComponentTemplate::new(template_metadata, library).to_bytes();
Expand All @@ -20,7 +30,16 @@ fn main() {
let templates_out_dir = PathBuf::from(out_dir).join("templates");
fs::create_dir_all(&templates_out_dir)
.expect("Failed to create templates directory in OUT_DIR");
let output_file = templates_out_dir.join("faucet_component_template.mct");

let output_filename = metadata_path
.file_stem()
.expect("metadata path should have a file stem")
.to_os_string();
let mut output_filename = output_filename;
// TODO: Do we want to add this?
output_filename.push(".mct");

let output_file = templates_out_dir.join(output_filename);
fs::write(&output_file, &faucet_component_template)
.expect("Failed to write faucet component template file");
}
2 changes: 1 addition & 1 deletion bin/miden-cli/src/commands/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::{
// ACCOUNT COMMAND
// ================================================================================================

#[derive(Default, Debug, Clone, Parser)]
/// View and manage accounts. Defaults to `list` command.
#[derive(Default, Debug, Clone, Parser)]
#[allow(clippy::option_option)]
pub struct AccountCmd {
/// List all accounts monitored by this client (default action).
Expand Down
Loading

0 comments on commit dcbe31c

Please sign in to comment.