1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use crate::utils::solc::{CompiledContract, SolcError};
use crate::utils::{Ganache, GanacheInstance, Geth, GethInstance, Solc};
use std::collections::HashMap;
pub async fn compile(solc: Solc) -> Result<HashMap<String, CompiledContract>, SolcError> {
tokio::task::spawn_blocking(|| solc.build()).await.unwrap()
}
pub async fn launch_ganache(ganache: Ganache) -> GanacheInstance {
tokio::task::spawn_blocking(|| ganache.spawn())
.await
.unwrap()
}
pub async fn compile_and_launch_ganache(
solc: Solc,
ganache: Ganache,
) -> Result<(HashMap<String, CompiledContract>, GanacheInstance), SolcError> {
let solc_fut = compile(solc);
let ganache_fut = launch_ganache(ganache);
let (solc, ganache) = futures_util::join!(solc_fut, ganache_fut);
solc.map(|solc| (solc, ganache))
}
pub async fn launch_geth(geth: Geth) -> GethInstance {
tokio::task::spawn_blocking(|| geth.spawn()).await.unwrap()
}
pub async fn compile_and_launch_geth(
solc: Solc,
geth: Geth,
) -> Result<(HashMap<String, CompiledContract>, GethInstance), SolcError> {
let solc_fut = compile(solc);
let geth_fut = launch_geth(geth);
let (solc, geth) = futures_util::join!(solc_fut, geth_fut);
solc.map(|solc| (solc, geth))
}