Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/cli/src/cli/simnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ async fn write_and_execute_iac(
accounts,
accounts_dir,
clones,
generate_subgraphs,
}) = deployment
{
if let Some(clones) = clones.as_ref() {
Expand Down Expand Up @@ -483,6 +484,7 @@ async fn write_and_execute_iac(
&programs,
&base_location,
cmd.skip_runbook_generation_prompts,
generate_subgraphs,
)?;
}

Expand All @@ -500,6 +502,7 @@ async fn write_and_execute_iac(
&genesis_accounts,
&accounts,
&accounts_dir,
generate_subgraphs,
)?);
} else {
let runbooks_ids_to_execute = cmd.runbooks.clone();
Expand Down
22 changes: 22 additions & 0 deletions crates/cli/src/scaffold/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ use crate::{
types::Framework,
};

/// Determines if subgraphs should be generated based on the anchor version.
/// Subgraphs are only supported for Anchor >= 0.26.0
fn should_generate_subgraphs(anchor_version: &Option<String>) -> bool {
if let Some(version) = anchor_version {
let version_parts: Vec<&str> = version.split('.').collect();
if version_parts.len() >= 2 {
if let (Ok(major), Ok(minor)) = (
version_parts[0].parse::<u32>(),
version_parts[1].parse::<u32>(),
) {
// Disable subgraph generation for versions < 0.26.0
if major == 0 && minor < 26 {
return false;
}
}
}
}
// If no version specified or parsing fails, assume subgraphs should be generated
true
}

pub fn try_get_programs_from_project(
base_location: FileLocation,
test_suite_paths: &[String],
Expand Down Expand Up @@ -131,6 +152,7 @@ pub fn try_get_programs_from_project(
} else {
Some(clones)
},
should_generate_subgraphs(&manifest.toolchain.anchor_version),
)))
} else {
Ok(None)
Expand Down
36 changes: 23 additions & 13 deletions crates/cli/src/scaffold/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct ProgramFrameworkData {
pub accounts: Option<Vec<AccountEntry>>,
pub accounts_dir: Option<Vec<AccountDirEntry>>,
pub clones: Option<Vec<String>>,
pub generate_subgraphs: bool,
}

impl ProgramFrameworkData {
Expand All @@ -45,6 +46,7 @@ impl ProgramFrameworkData {
accounts: Option<Vec<AccountEntry>>,
accounts_dir: Option<Vec<AccountDirEntry>>,
clones: Option<Vec<String>>,
generate_subgraphs: bool,
) -> Self {
Self {
framework,
Expand All @@ -53,6 +55,7 @@ impl ProgramFrameworkData {
accounts,
accounts_dir,
clones,
generate_subgraphs,
}
}

Expand All @@ -64,6 +67,7 @@ impl ProgramFrameworkData {
accounts: None,
accounts_dir: None,
clones: None,
generate_subgraphs: true,
}
}
}
Expand Down Expand Up @@ -134,6 +138,7 @@ pub fn scaffold_in_memory_iac(
genesis_accounts: &Option<Vec<GenesisEntry>>,
accounts: &Option<Vec<AccountEntry>>,
accounts_dir: &Option<Vec<AccountDirEntry>>,
generate_subgraphs: bool,
) -> Result<(String, RunbookSources, WorkspaceManifest), String> {
let mut deployment_runbook_src: String = String::new();

Expand All @@ -151,15 +156,17 @@ pub fn scaffold_in_memory_iac(
.get_in_memory_interpolated_program_deployment_template(&program_metadata.name),
);

if let Some(subgraph_iac) = &framework
.get_interpolated_subgraph_template(
&program_metadata.name,
program_metadata.idl.as_ref(),
)
.ok()
.flatten()
{
deployment_runbook_src.push_str(subgraph_iac);
if generate_subgraphs {
if let Some(subgraph_iac) = &framework
.get_interpolated_subgraph_template(
&program_metadata.name,
program_metadata.idl.as_ref(),
)
.ok()
.flatten()
{
deployment_runbook_src.push_str(subgraph_iac);
}
}
}

Expand Down Expand Up @@ -199,6 +206,7 @@ pub fn scaffold_iac_layout(
programs: &[ProgramMetadata],
base_location: &FileLocation,
auto_generate_runbooks: bool,
generate_subgraphs: bool,
) -> Result<(), String> {
let mut target_location = base_location.clone();
target_location.append_path("target")?;
Expand Down Expand Up @@ -296,10 +304,12 @@ pub fn scaffold_iac_layout(
&framework.get_interpolated_program_deployment_template(&program_metadata.name),
);

subgraph_runbook_src = framework.get_interpolated_subgraph_template(
&program_metadata.name,
program_metadata.idl.as_ref(),
)?;
if generate_subgraphs {
subgraph_runbook_src = framework.get_interpolated_subgraph_template(
&program_metadata.name,
program_metadata.idl.as_ref(),
)?;
}

// Configure initialize instruction
// let args = vec![
Expand Down