1+ use clarinet_lib:: integrate:: { self , DevnetOrchestrator , NodeObserverEvent } ;
2+ use clarinet_lib:: types:: DevnetConfigFile ;
3+ use neon:: prelude:: * ;
4+ use std:: path:: PathBuf ;
15use std:: sync:: mpsc;
26use std:: thread;
3- use std:: path:: PathBuf ;
47use std:: { env, process} ;
5- use clarinet_lib:: types:: DevnetConfigFile ;
6- use neon:: prelude:: * ;
7- use clarinet_lib:: integrate:: { self , DevnetOrchestrator , NodeObserverEvent } ;
88
99type DevnetCallback = Box < dyn FnOnce ( & Channel ) + Send > ;
1010
1111struct StacksDevnet {
1212 tx : mpsc:: Sender < DevnetCommand > ,
13- devnet_event_rx : mpsc:: Receiver < NodeObserverEvent >
13+ devnet_event_rx : mpsc:: Receiver < NodeObserverEvent > ,
1414}
1515
1616enum DevnetCommand {
@@ -42,14 +42,15 @@ impl StacksDevnet {
4242 let channel = cx. channel ( ) ;
4343
4444 thread:: spawn ( move || {
45-
46- let manifest_path = get_manifest_path_or_exit ( Some ( "/Users/ludovic/Coding/clarinet/clarinet-cli/examples/counter/Clarinet.toml" . into ( ) ) ) ;
45+ let manifest_path = get_manifest_path_or_exit ( Some (
46+ "/Users/ludovic/Coding/clarinet/clarinet-cli/examples/counter/Clarinet.toml" . into ( ) ,
47+ ) ) ;
4748 let devnet_overrides = DevnetConfigFile :: default ( ) ;
4849 let devnet = DevnetOrchestrator :: new ( manifest_path, Some ( devnet_overrides) ) ;
4950
5051 if let Ok ( DevnetCommand :: Start ( callback) ) = rx. recv ( ) {
5152 // Start devnet
52- integrate:: run_devnet ( devnet, Some ( devnet_events_tx) , false ) ;
53+ integrate:: run_devnet ( devnet, Some ( devnet_events_tx) , false ) ;
5354 if let Some ( c) = callback {
5455 c ( & channel) ;
5556 }
@@ -74,10 +75,16 @@ impl StacksDevnet {
7475 }
7576 } ) ;
7677
77- Ok ( Self { tx, devnet_event_rx : devnet_events_rx } )
78+ Ok ( Self {
79+ tx,
80+ devnet_event_rx : devnet_events_rx,
81+ } )
7882 }
7983
80- fn start ( & self , callback : Option < DevnetCallback > ) -> Result < ( ) , mpsc:: SendError < DevnetCommand > > {
84+ fn start (
85+ & self ,
86+ callback : Option < DevnetCallback > ,
87+ ) -> Result < ( ) , mpsc:: SendError < DevnetCommand > > {
8188 self . tx . send ( DevnetCommand :: Start ( callback) )
8289 }
8390
@@ -87,7 +94,6 @@ impl StacksDevnet {
8794}
8895
8996impl StacksDevnet {
90-
9197 fn js_new ( mut cx : FunctionContext ) -> JsResult < JsBox < StacksDevnet > > {
9298 let devnet = StacksDevnet :: new ( & mut cx) . or_else ( |err| cx. throw_error ( err. to_string ( ) ) ) ?;
9399 Ok ( cx. boxed ( devnet) )
@@ -116,43 +122,47 @@ impl StacksDevnet {
116122 }
117123
118124 fn js_on_stacks_block ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
119-
120125 // Get the first argument as a `JsFunction`
121126 let callback = cx. argument :: < JsFunction > ( 0 ) ?. root ( & mut cx) ;
122127 let callback = callback. into_inner ( & mut cx) ;
123128
124- let devnet = cx. this ( ) . downcast_or_throw :: < JsBox < StacksDevnet > , _ > ( & mut cx) ?;
129+ let devnet = cx
130+ . this ( )
131+ . downcast_or_throw :: < JsBox < StacksDevnet > , _ > ( & mut cx) ?;
125132
126133 while let Ok ( message) = devnet. devnet_event_rx . recv ( ) {
127134 match message {
128135 _ => {
129136 println ! ( "Hello world :)" ) ;
130- let args: Vec < Handle < JsValue > > = vec ! [ cx. null( ) . upcast( ) , cx. number( 1 as f64 ) . upcast( ) ] ;
137+ let args: Vec < Handle < JsValue > > =
138+ vec ! [ cx. null( ) . upcast( ) , cx. number( 1 as f64 ) . upcast( ) ] ;
131139 let _res = callback. call ( & mut cx, devnet, args) ?;
132140 // let expected = cx.boolean(true);
133141 // if res.strict_equals(&mut cx, expected) {
134142 // break;
135143 // }
136144 }
137145 }
138- }
146+ }
139147 Ok ( cx. undefined ( ) )
140148 }
141149
142150 fn js_on_bitcoin_block ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
143-
144151 // Get the first argument as a `JsFunction`
145152 let callback = cx. argument :: < JsFunction > ( 0 ) ?. root ( & mut cx) ;
146153 let callback = callback. into_inner ( & mut cx) ;
147154
148- let devnet = cx. this ( ) . downcast_or_throw :: < JsBox < StacksDevnet > , _ > ( & mut cx) ?;
155+ let devnet = cx
156+ . this ( )
157+ . downcast_or_throw :: < JsBox < StacksDevnet > , _ > ( & mut cx) ?;
149158
150159 while let Ok ( message) = devnet. devnet_event_rx . recv ( ) {
151160 match message {
152161 _ => {
153162 println ! ( "Hello world :)" ) ;
154163 // let this = cx.undefined();
155- let args: Vec < Handle < JsValue > > = vec ! [ cx. null( ) . upcast( ) , cx. number( 1 as f64 ) . upcast( ) ] ;
164+ let args: Vec < Handle < JsValue > > =
165+ vec ! [ cx. null( ) . upcast( ) , cx. number( 1 as f64 ) . upcast( ) ] ;
156166 let _res = callback. call ( & mut cx, devnet, args) ?;
157167 break ;
158168 // // callback.call(&mut cx, this, vec![])?;
@@ -168,7 +178,7 @@ impl StacksDevnet {
168178 // DevnetMessage::Close => break,
169179 }
170180 }
171- }
181+ }
172182
173183 // db.send(move |conn, channel| {
174184 // let result = conn
@@ -203,7 +213,10 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
203213 cx. export_function ( "stackDevnetNew" , StacksDevnet :: js_new) ?;
204214 cx. export_function ( "stackDevnetStart" , StacksDevnet :: js_start) ?;
205215 cx. export_function ( "stackDevnetOnStacksBlock" , StacksDevnet :: js_on_stacks_block) ?;
206- cx. export_function ( "stackDevnetOnBitcoinBlock" , StacksDevnet :: js_on_bitcoin_block) ?;
216+ cx. export_function (
217+ "stackDevnetOnBitcoinBlock" ,
218+ StacksDevnet :: js_on_bitcoin_block,
219+ ) ?;
207220 cx. export_function ( "stackDevnetTerminate" , StacksDevnet :: js_terminate) ?;
208221 Ok ( ( ) )
209222}
0 commit comments