Skip to content

Commit 3b24546

Browse files
committed
node/launcher: extract deploy_subgraph_from_flag helper from run
1 parent f11317a commit 3b24546

File tree

1 file changed

+57
-47
lines changed

1 file changed

+57
-47
lines changed

node/src/launcher.rs

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,61 @@ async fn spawn_block_ingestor(
204204
graph::spawn_blocking(job_runner.start());
205205
}
206206

207+
fn deploy_subgraph_from_flag(
208+
subgraph: String,
209+
opt: &Opt,
210+
subgraph_registrar: Arc<impl SubgraphRegistrar>,
211+
node_id: NodeId,
212+
) {
213+
let (name, hash) = if subgraph.contains(':') {
214+
let mut split = subgraph.split(':');
215+
(split.next().unwrap(), split.next().unwrap().to_owned())
216+
} else {
217+
("cli", subgraph)
218+
};
219+
220+
let name = SubgraphName::new(name)
221+
.expect("Subgraph name must contain only a-z, A-Z, 0-9, '-' and '_'");
222+
let subgraph_id = DeploymentHash::new(hash).expect("Subgraph hash must be a valid IPFS hash");
223+
let debug_fork = opt
224+
.debug_fork
225+
.clone()
226+
.map(DeploymentHash::new)
227+
.map(|h| h.expect("Debug fork hash must be a valid IPFS hash"));
228+
let start_block = opt
229+
.start_block
230+
.clone()
231+
.map(|block| {
232+
let mut split = block.split(':');
233+
(
234+
// BlockHash
235+
split.next().unwrap().to_owned(),
236+
// BlockNumber
237+
split.next().unwrap().parse::<i64>().unwrap(),
238+
)
239+
})
240+
.map(|(hash, number)| BlockPtr::try_from((hash.as_str(), number)))
241+
.map(Result::unwrap);
242+
243+
graph::spawn(
244+
async move {
245+
subgraph_registrar.create_subgraph(name.clone()).await?;
246+
subgraph_registrar
247+
.create_subgraph_version(
248+
name,
249+
subgraph_id,
250+
node_id,
251+
debug_fork,
252+
start_block,
253+
None,
254+
None,
255+
)
256+
.await
257+
}
258+
.map_err(|e| panic!("Failed to deploy subgraph from `--subgraph` flag: {}", e)),
259+
);
260+
}
261+
207262
pub async fn run(opt: Opt, env_vars: Arc<EnvVars>) {
208263
env_logger::init();
209264
// Set up logger
@@ -308,7 +363,7 @@ pub async fn run(opt: Opt, env_vars: Arc<EnvVars>) {
308363

309364
// TODO: make option loadable from configuration TOML and environment:
310365
let expensive_queries =
311-
read_expensive_queries(&logger, opt.expensive_queries_filename).unwrap();
366+
read_expensive_queries(&logger, opt.expensive_queries_filename.clone()).unwrap();
312367

313368
let (primary_pool, subscription_manager, chain_head_update_listener, network_store) =
314369
setup_store(
@@ -446,52 +501,7 @@ pub async fn run(opt: Opt, env_vars: Arc<EnvVars>) {
446501

447502
// Add the CLI subgraph with a REST request to the admin server.
448503
if let Some(subgraph) = subgraph {
449-
let (name, hash) = if subgraph.contains(':') {
450-
let mut split = subgraph.split(':');
451-
(split.next().unwrap(), split.next().unwrap().to_owned())
452-
} else {
453-
("cli", subgraph)
454-
};
455-
456-
let name = SubgraphName::new(name)
457-
.expect("Subgraph name must contain only a-z, A-Z, 0-9, '-' and '_'");
458-
let subgraph_id =
459-
DeploymentHash::new(hash).expect("Subgraph hash must be a valid IPFS hash");
460-
let debug_fork = opt
461-
.debug_fork
462-
.map(DeploymentHash::new)
463-
.map(|h| h.expect("Debug fork hash must be a valid IPFS hash"));
464-
let start_block = opt
465-
.start_block
466-
.map(|block| {
467-
let mut split = block.split(':');
468-
(
469-
// BlockHash
470-
split.next().unwrap().to_owned(),
471-
// BlockNumber
472-
split.next().unwrap().parse::<i64>().unwrap(),
473-
)
474-
})
475-
.map(|(hash, number)| BlockPtr::try_from((hash.as_str(), number)))
476-
.map(Result::unwrap);
477-
478-
graph::spawn(
479-
async move {
480-
subgraph_registrar.create_subgraph(name.clone()).await?;
481-
subgraph_registrar
482-
.create_subgraph_version(
483-
name,
484-
subgraph_id,
485-
node_id,
486-
debug_fork,
487-
start_block,
488-
None,
489-
None,
490-
)
491-
.await
492-
}
493-
.map_err(|e| panic!("Failed to deploy subgraph from `--subgraph` flag: {}", e)),
494-
);
504+
deploy_subgraph_from_flag(subgraph, &opt, subgraph_registrar.clone(), node_id);
495505
}
496506

497507
// Serve GraphQL queries over HTTP

0 commit comments

Comments
 (0)