@@ -107,7 +107,7 @@ impl StacksDevnet {
107107 Ok ( cx. undefined ( ) )
108108 }
109109
110- fn js_terminate ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
110+ fn js_stop ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
111111 cx. this ( )
112112 . downcast_or_throw :: < JsBox < StacksDevnet > , _ > ( & mut cx) ?
113113 . stop ( None )
@@ -127,15 +127,18 @@ impl StacksDevnet {
127127
128128 while let Ok ( message) = devnet. devnet_event_rx . recv ( ) {
129129 match message {
130- _ => {
131- println ! ( "Hello world :) " ) ;
130+ NodeObserverEvent :: NewStacksBlock => {
131+ println ! ( "New stacks block " ) ;
132132 let args: Vec < Handle < JsValue > > =
133133 vec ! [ cx. null( ) . upcast( ) , cx. number( 1 as f64 ) . upcast( ) ] ;
134134 let _res = callback. call ( & mut cx, devnet, args) ?;
135135 // let expected = cx.boolean(true);
136136 // if res.strict_equals(&mut cx, expected) {
137137 // break;
138138 // }
139+ break ;
140+ }
141+ _ => {
139142 }
140143 }
141144 }
@@ -153,24 +156,18 @@ impl StacksDevnet {
153156
154157 while let Ok ( message) = devnet. devnet_event_rx . recv ( ) {
155158 match message {
156- _ => {
157- println ! ( "Hello world :)" ) ;
158- // let this = cx.undefined();
159+ NodeObserverEvent :: NewBitcoinBlock => {
160+ println ! ( "New bitcoin block" ) ;
159161 let args: Vec < Handle < JsValue > > =
160162 vec ! [ cx. null( ) . upcast( ) , cx. number( 1 as f64 ) . upcast( ) ] ;
161163 let _res = callback. call ( & mut cx, devnet, args) ?;
162- break ;
163- // // callback.call(&mut cx, this, vec![])?;
164-
165- // }
166- // DevnetMessage::Callback(f) => {
167- // // The connection and channel are owned by the thread, but _lent_ to
168- // // the callback. The callback has exclusive access to the connection
169- // // for the duration of the callback.
170- // f(&channel);
164+ // let expected = cx.boolean(true);
165+ // if res.strict_equals(&mut cx, expected) {
166+ // break;
171167 // }
172- // // Immediately close the connection, even if there are pending messages
173- // DevnetMessage::Close => break,
168+ break ;
169+ }
170+ _ => {
174171 }
175172 }
176173 }
@@ -181,14 +178,14 @@ impl StacksDevnet {
181178
182179#[ neon:: main]
183180fn main ( mut cx : ModuleContext ) -> NeonResult < ( ) > {
184- cx. export_function ( "stackDevnetNew" , StacksDevnet :: js_new) ?;
185- cx. export_function ( "stackDevnetStart" , StacksDevnet :: js_start) ?;
186- cx. export_function ( "stackDevnetOnStacksBlock" , StacksDevnet :: js_on_stacks_block) ?;
181+ cx. export_function ( "stacksDevnetNew" , StacksDevnet :: js_new) ?;
182+ cx. export_function ( "stacksDevnetStart" , StacksDevnet :: js_start) ?;
183+ cx. export_function ( "stacksDevnetStop" , StacksDevnet :: js_stop) ?;
184+ cx. export_function ( "stacksDevnetWaitForStacksBlock" , StacksDevnet :: js_on_stacks_block) ?;
187185 cx. export_function (
188- "stackDevnetOnBitcoinBlock " ,
186+ "stacksDevnetWaitForBitcoinBlock " ,
189187 StacksDevnet :: js_on_bitcoin_block,
190188 ) ?;
191- cx. export_function ( "stackDevnetTerminate" , StacksDevnet :: js_terminate) ?;
192189 Ok ( ( ) )
193190}
194191
0 commit comments