-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathmod.rs
More file actions
128 lines (112 loc) · 3.99 KB
/
mod.rs
File metadata and controls
128 lines (112 loc) · 3.99 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use crate::publish::Network;
use crate::types::{ChainConfig, ProjectManifest};
use clarity_repl::{repl, Terminal};
use std::fs;
use std::path::PathBuf;
pub fn load_session(
manifest_path: PathBuf,
start_repl: bool,
env: &Network,
) -> Result<(repl::Session, ChainConfig, Option<String>), String> {
let mut settings = repl::SessionSettings::default();
let mut project_path = manifest_path.clone();
project_path.pop();
let mut chain_config_path = project_path.clone();
// chain_config_path.pop();
chain_config_path.push("settings");
chain_config_path.push(match env {
Network::Devnet => "Devnet.toml",
Network::Testnet => "Testnet.toml",
Network::Mainnet => "Mainnet.toml",
});
let mut project_config = ProjectManifest::from_path(&manifest_path);
let chain_config = ChainConfig::from_path(&chain_config_path);
let mut deployer_address = None;
let mut initial_deployer = None;
settings.node = chain_config
.network
.node_rpc_address
.clone()
.take()
.unwrap_or(match env {
Network::Devnet => "http://127.0.0.1:20443".into(),
Network::Testnet => "https://stacks-node-api.testnet.stacks.co".into(),
Network::Mainnet => "https://stacks-node-api.mainnet.stacks.co".into(),
});
for (name, account) in chain_config.accounts.iter() {
let account = repl::settings::Account {
name: name.clone(),
balance: account.balance,
address: account.address.clone(),
mnemonic: account.mnemonic.clone(),
derivation: account.derivation.clone(),
};
if name == "deployer" {
initial_deployer = Some(account.clone());
deployer_address = Some(account.address.clone());
}
settings.initial_accounts.push(account);
}
for (name, config) in project_config.ordered_contracts().iter() {
let mut contract_path = project_path.clone();
contract_path.push(&config.path);
let code = match fs::read_to_string(&contract_path) {
Ok(code) => code,
Err(err) => {
return Err(format!(
"Error: unable to read {:?}: {}",
contract_path, err
))
}
};
settings
.initial_contracts
.push(repl::settings::InitialContract {
code: code,
path: contract_path.to_str().unwrap().into(),
name: Some(name.clone()),
deployer: deployer_address.clone(),
});
}
let links = match project_config.project.requirements.take() {
Some(links) => links,
None => vec![],
};
for link_config in links.iter() {
settings.initial_links.push(repl::settings::InitialLink {
contract_id: link_config.contract_id.clone(),
stacks_node_addr: None,
cache: None,
});
}
settings.include_boot_contracts = vec![
"pox".to_string(),
"costs-v1".to_string(),
"costs-v2".to_string(),
"bns".to_string(),
];
settings.initial_deployer = initial_deployer;
settings.costs_version = project_config.project.costs_version;
if let Some(analysis_passes) = project_config.project.analysis {
settings.analysis = analysis_passes;
}
let (session, output) = if start_repl {
let mut terminal = Terminal::new(settings.clone());
terminal.start();
(terminal.session.clone(), None)
} else {
let mut session = repl::Session::new(settings.clone());
let output = match session.start() {
Err(message) => {
println!("{}", message);
std::process::exit(1);
}
Ok((message, _)) => match message.is_empty() {
true => None,
false => Some(message)
}
};
(session, output)
};
Ok((session, chain_config, output))
}