Skip to content

Commit 14fce9c

Browse files
committed
chore: cargo fmt
1 parent 20741e8 commit 14fce9c

File tree

4 files changed

+46
-26
lines changed

4 files changed

+46
-26
lines changed

node-bindings/src/lib.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
use clarinet_lib::integrate::{self, DevnetOrchestrator, NodeObserverEvent};
2+
use clarinet_lib::types::DevnetConfigFile;
3+
use neon::prelude::*;
4+
use std::path::PathBuf;
15
use std::sync::mpsc;
26
use std::thread;
3-
use std::path::PathBuf;
47
use std::{env, process};
5-
use clarinet_lib::types::DevnetConfigFile;
6-
use neon::prelude::*;
7-
use clarinet_lib::integrate::{self, DevnetOrchestrator, NodeObserverEvent};
88

99
type DevnetCallback = Box<dyn FnOnce(&Channel) + Send>;
1010

1111
struct StacksDevnet {
1212
tx: mpsc::Sender<DevnetCommand>,
13-
devnet_event_rx: mpsc::Receiver<NodeObserverEvent>
13+
devnet_event_rx: mpsc::Receiver<NodeObserverEvent>,
1414
}
1515

1616
enum 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

8996
impl 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
}

src/integrate/orchestrator.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use bollard::models::{HostConfig, PortBinding};
1010
use bollard::network::{ConnectNetworkOptions, CreateNetworkOptions, PruneNetworksOptions};
1111
use bollard::Docker;
1212
use crossterm::terminal::disable_raw_mode;
13+
use futures::stream::TryStreamExt;
1314
use std::collections::HashMap;
1415
use std::fs::{self, File};
1516
use std::io::Write;
1617
use std::path::PathBuf;
1718
use std::sync::mpsc::{Receiver, Sender};
1819
use tracing::info;
19-
use futures::stream::TryStreamExt;
2020

2121
#[derive(Default, Debug)]
2222
pub struct DevnetOrchestrator {
@@ -35,7 +35,10 @@ pub struct DevnetOrchestrator {
3535
}
3636

3737
impl DevnetOrchestrator {
38-
pub fn new(manifest_path: PathBuf, devnet_override: Option<DevnetConfigFile>) -> DevnetOrchestrator {
38+
pub fn new(
39+
manifest_path: PathBuf,
40+
devnet_override: Option<DevnetConfigFile>,
41+
) -> DevnetOrchestrator {
3942
let docker_client = Docker::connect_with_socket_defaults().unwrap();
4043

4144
let mut project_path = manifest_path.clone();
@@ -54,8 +57,8 @@ impl DevnetOrchestrator {
5457
(Some(ref mut devnet_config), Some(ref devnet_override)) => {
5558
devnet_config.disable_stacks_api = true;
5659
devnet_config.disable_bitcoin_explorer = true;
57-
devnet_config.disable_stacks_explorer = true;
58-
},
60+
devnet_config.disable_stacks_explorer = true;
61+
}
5962
_ => {}
6063
};
6164

@@ -1492,6 +1495,10 @@ events_keys = ["*"]
14921495
_ => return Err("Unable to get Docker client".into()),
14931496
};
14941497

1498+
// todo(ludo): should we spawn
1499+
// docker run -d -p 5000:5000 --name registry registry:2.7
1500+
// ?
1501+
14951502
// Prune
14961503
let mut filters = HashMap::new();
14971504
filters.insert(

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ pub mod utils;
2121

2222
pub fn hello_clarinet() -> String {
2323
format!("Hello Clarinet :)")
24-
}
24+
}

src/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ mod chain_config;
22
mod project_config;
33

44
pub use chain_config::{
5-
compute_addresses, AccountConfig, ChainConfig, ChainConfigFile, DevnetConfig, DevnetConfigFile
5+
compute_addresses, AccountConfig, ChainConfig, ChainConfigFile, DevnetConfig, DevnetConfigFile,
66
};
77
pub use project_config::{ContractConfig, MainConfig, MainConfigFile, RequirementConfig};

0 commit comments

Comments
 (0)