@@ -112,7 +112,7 @@ pub struct InitOpt {
112112}
113113
114114/// Run the init command.
115- pub fn run_init ( opt : InitOpt ) -> Result < ( ) > {
115+ pub async fn run_init ( opt : InitOpt ) -> Result < ( ) > {
116116 // Check if we need interactive mode
117117 let needs_interactive = should_run_interactive ( & opt) ;
118118
@@ -127,7 +127,7 @@ pub fn run_init(opt: InitOpt) -> Result<()> {
127127 ) ) ;
128128 }
129129
130- return run_interactive ( opt) ;
130+ return run_interactive ( opt) . await ;
131131 }
132132
133133 // Non-interactive mode - determine the scaffold source
@@ -143,7 +143,7 @@ pub fn run_init(opt: InitOpt) -> Result<()> {
143143 } ;
144144
145145 match source {
146- ScaffoldSource :: Contract => init_from_contract ( & opt) ,
146+ ScaffoldSource :: Contract => init_from_contract ( & opt) . await ,
147147 ScaffoldSource :: Example => init_from_example ( & opt) ,
148148 ScaffoldSource :: Subgraph => init_from_subgraph ( & opt) ,
149149 }
@@ -176,12 +176,11 @@ fn should_run_interactive(opt: &InitOpt) -> bool {
176176}
177177
178178/// Run in interactive mode.
179- fn run_interactive ( opt : InitOpt ) -> Result < ( ) > {
179+ async fn run_interactive ( opt : InitOpt ) -> Result < ( ) > {
180180 println ! ( "Creating a new subgraph...\n " ) ;
181181
182182 // Load the networks registry
183- let runtime = tokio:: runtime:: Runtime :: new ( ) . context ( "Failed to create async runtime" ) ?;
184- let registry = runtime. block_on ( async { NetworksRegistry :: load ( ) . await } ) ?;
183+ let registry = NetworksRegistry :: load ( ) . await ?;
185184
186185 // Parse start block if provided
187186 let start_block = opt. start_block . as_ref ( ) . and_then ( |s| s. parse :: < u64 > ( ) . ok ( ) ) ;
@@ -229,7 +228,7 @@ fn run_interactive(opt: InitOpt) -> Result<()> {
229228 skip_git : opt. skip_git ,
230229 ..Default :: default ( )
231230 } ;
232- init_from_contract ( & contract_opt)
231+ init_from_contract ( & contract_opt) . await
233232 }
234233 }
235234}
@@ -241,7 +240,7 @@ enum ScaffoldSource {
241240}
242241
243242/// Initialize a subgraph from a contract address.
244- fn init_from_contract ( opt : & InitOpt ) -> Result < ( ) > {
243+ async fn init_from_contract ( opt : & InitOpt ) -> Result < ( ) > {
245244 let address = opt
246245 . from_contract
247246 . as_ref ( )
@@ -262,48 +261,44 @@ fn init_from_contract(opt: &InitOpt) -> Result<()> {
262261 & format ! ( "Fetching contract info from {} on {}" , address, network) ,
263262 ) ;
264263
265- // Create async runtime to fetch contract info
266- let runtime = tokio:: runtime:: Runtime :: new ( ) . context ( "Failed to create async runtime" ) ?;
267-
268- let contract_info = runtime. block_on ( async {
264+ // Fetch contract info
265+ let contract_info = if let Some ( abi_path) = & opt. abi {
269266 // Load ABI from file if provided
270- if let Some ( abi_path) = & opt. abi {
271- let abi_str = fs:: read_to_string ( abi_path)
272- . with_context ( || format ! ( "Failed to read ABI file: {}" , abi_path. display( ) ) ) ?;
273- let abi: serde_json:: Value = serde_json:: from_str ( & abi_str)
274- . with_context ( || format ! ( "Failed to parse ABI file: {}" , abi_path. display( ) ) ) ?;
275-
276- // Try to get start block from API if not provided
277- let start_block = if let Some ( block) = & opt. start_block {
278- block. parse :: < u64 > ( ) . ok ( )
279- } else {
280- // Try to fetch from API
281- match ContractService :: load ( ) . await {
282- Ok ( service) => service. get_start_block ( network, address) . await . ok ( ) ,
283- Err ( _) => None ,
284- }
285- } ;
286-
287- Ok :: < _ , anyhow:: Error > ( crate :: services:: ContractInfo {
288- abi,
289- name : opt
290- . contract_name
291- . clone ( )
292- . unwrap_or_else ( || "Contract" . to_string ( ) ) ,
293- start_block,
294- } )
267+ let abi_str = fs:: read_to_string ( abi_path)
268+ . with_context ( || format ! ( "Failed to read ABI file: {}" , abi_path. display( ) ) ) ?;
269+ let abi: serde_json:: Value = serde_json:: from_str ( & abi_str)
270+ . with_context ( || format ! ( "Failed to parse ABI file: {}" , abi_path. display( ) ) ) ?;
271+
272+ // Try to get start block from API if not provided
273+ let start_block = if let Some ( block) = & opt. start_block {
274+ block. parse :: < u64 > ( ) . ok ( )
295275 } else {
296- // Fetch ABI from Etherscan/Sourcify
297- let service = ContractService :: load ( )
298- . await
299- . context ( "Failed to load contract service" ) ?;
300-
301- service
302- . get_contract_info ( network, address)
303- . await
304- . context ( "Failed to fetch contract info" )
276+ // Try to fetch from API
277+ match ContractService :: load ( ) . await {
278+ Ok ( service) => service. get_start_block ( network, address) . await . ok ( ) ,
279+ Err ( _) => None ,
280+ }
281+ } ;
282+
283+ crate :: services:: ContractInfo {
284+ abi,
285+ name : opt
286+ . contract_name
287+ . clone ( )
288+ . unwrap_or_else ( || "Contract" . to_string ( ) ) ,
289+ start_block,
305290 }
306- } ) ?;
291+ } else {
292+ // Fetch ABI from Etherscan/Sourcify
293+ let service = ContractService :: load ( )
294+ . await
295+ . context ( "Failed to load contract service" ) ?;
296+
297+ service
298+ . get_contract_info ( network, address)
299+ . await
300+ . context ( "Failed to fetch contract info" ) ?
301+ } ;
307302
308303 step (
309304 Step :: Done ,
0 commit comments