Skip to content

Commit

Permalink
Merge branch 'main' into feat/fetch-accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru authored Feb 5, 2025
2 parents ce94e28 + 99ac952 commit c34d164
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 80 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ surfpool-core = { workspace = true }
# txtx-core = { path = "../../../txtx/crates/txtx-core" }
# txtx-addon-network-svm = { package = "txtx-addon-network-svm", path = "../../../txtx/addons/svm" }
txtx-core = { version = "0.2.1" }
txtx-addon-network-svm = { version = "0.1.0" }
txtx-addon-network-svm = { version = "0.1.1" }
hiro-system-kit = "0.3.1"
atty = "0.2.13"
ansi_term = "0.12.1"
Expand Down
28 changes: 26 additions & 2 deletions crates/cli/src/cli/simnet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use crate::{runbook::execute_runbook, scaffold::detect_program_frameworks, tui};
use crate::{
runbook::execute_runbook,
scaffold::{detect_program_frameworks, scaffold_runbooks_layout},
tui,
};

use super::{Context, StartSimnet};
use dialoguer::{console::Style, theme::ColorfulTheme, MultiSelect};
use surfpool_core::{
simnet::SimnetEvent,
start_simnet,
Expand Down Expand Up @@ -58,9 +63,28 @@ pub async fn handle_start_simnet_command(cmd: &StartSimnet, ctx: &Context) -> Re
};

let deploy_progress_rx = if let Some((framework, programs)) = deployment {
let theme = ColorfulTheme {
values_style: Style::new().green(),
hint_style: Style::new().cyan(),
..ColorfulTheme::default()
};

let selection = MultiSelect::with_theme(&theme)
.with_prompt("Programs to deploy:")
.items(&programs)
.interact()
.unwrap();

let selected_programs = selection
.iter()
.map(|i| programs[*i].clone())
.collect::<Vec<_>>();

scaffold_runbooks_layout(selected_programs, &cmd.manifest_path)?;

let (progress_tx, progress_rx) = crossbeam::channel::unbounded();
let manifest_location = FileLocation::from_path_string(&cmd.manifest_path)?;
execute_runbook("v1", progress_tx, &manifest_location).await?;
execute_runbook("deployment", progress_tx, &manifest_location).await?;
Some(progress_rx)
} else {
None
Expand Down
6 changes: 4 additions & 2 deletions crates/cli/src/runbook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ pub async fn execute_runbook(

let manifest = WorkspaceManifest::from_location(&txtx_manifest_location)?;
let runbook_selector = vec![runbook_id.to_string()];
let mut runbooks = read_runbooks_from_manifest(&manifest, &None, Some(&runbook_selector))?;
let top_level_inputs_map = manifest.get_runbook_inputs(&None, &vec![], None)?;
let mut runbooks =
read_runbooks_from_manifest(&manifest, &Some("localnet".into()), Some(&runbook_selector))?;
let top_level_inputs_map =
manifest.get_runbook_inputs(&Some("localnet".into()), &vec![], None)?;

let Some((mut runbook, runbook_sources, state, smt)) = runbooks.swap_remove(runbook_id) else {
return Err(format!("Deployment {} not found", runbook_id));
Expand Down
27 changes: 3 additions & 24 deletions crates/cli/src/scaffold/anchor.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
use anyhow::{anyhow, Error, Result};
use serde::{Deserialize, Serialize};
use std::{collections::BTreeMap, str::FromStr};
use txtx_addon_network_svm::{
templates::{
get_interpolated_addon_template, get_interpolated_anchor_program_deployment_template,
get_interpolated_header_template, get_interpolated_signer_template,
},
SvmNetworkAddon,
};
use txtx_addon_network_svm::SvmNetworkAddon;
use txtx_core::kit::helpers::fs::FileLocation;
use txtx_core::kit::types::AuthorizationContext;
use url::Url;
Expand All @@ -16,7 +10,7 @@ use crate::types::Framework;

pub fn try_get_programs_from_project(
base_location: FileLocation,
) -> Result<Option<(Framework, Vec<String>, String)>, String> {
) -> Result<Option<(Framework, Vec<String>)>, String> {
let mut manifest_location = base_location.clone();
manifest_location.append_path("Anchor.toml")?;
if manifest_location.exists() {
Expand All @@ -32,29 +26,14 @@ pub fn try_get_programs_from_project(
let addon = SvmNetworkAddon::new();
let _function_spec = &addon.get_deploy_action_spec();
let _context = AuthorizationContext::empty();
let mut runbook_src = String::new();
runbook_src.push_str(&get_interpolated_header_template(&format!("Runbook")));
runbook_src.push_str(&get_interpolated_addon_template("http://localhost:8899"));
runbook_src.push_str(&get_interpolated_signer_template(
"~/.config/solana/id.json",
));

if let Some((_, deployments)) = manifest.programs.iter().next() {
for (program_name, _deployment) in deployments.iter() {
programs.push(program_name.clone());
runbook_src.push_str(&get_interpolated_anchor_program_deployment_template(
program_name,
));
// Configure initialize instruction
// let args = vec![
// Value::string("hellosol".into()),
// Value::string(target_location.to_string())
// ];
// let command = GetProgramFromAnchorProject::run(function_spec, &context, &args);
}
}

Ok(Some((Framework::Anchor, programs, runbook_src)))
Ok(Some((Framework::Anchor, programs)))
} else {
Ok(None)
}
Expand Down
Loading

0 comments on commit c34d164

Please sign in to comment.