Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: consolidate datastore and burn datastore data #1562

Merged
merged 10 commits into from
Sep 30, 2024
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/clarinet-cli/src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ pub fn main() {
contract.epoch,
contract.clarity_version,
);
let mut analysis_db = AnalysisDatabase::new(&mut session.interpreter.datastore);
let mut analysis_db = AnalysisDatabase::new(&mut session.interpreter.clarity_datastore);
let mut analysis_diagnostics = match analysis::run_analysis(
&mut contract_analysis,
&mut analysis_db,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe("the sdk handle all clarity version", () => {

// `tenure-height` was introduced in clarity 3
let resOk3 = simnet.execute("(print tenure-height)");
expect(resOk3.result).toStrictEqual(Cl.uint(1));
expect(resOk3.result).toStrictEqual(Cl.uint(2));

// `block-height` was removed in clarity 3
expect(() => simnet.execute("(print block-height)")).toThrowError(
Expand Down
2 changes: 1 addition & 1 deletion components/clarity-events/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn main() {
};

{
let mut analysis_db = session.interpreter.datastore.as_analysis_db();
let mut analysis_db = session.interpreter.clarity_datastore.as_analysis_db();
let cost_track = LimitedCostTracker::new_free();
let type_checker = TypeChecker::new(&mut analysis_db, cost_track, true);
let settings = Settings::default();
Expand Down
69 changes: 37 additions & 32 deletions components/clarity-repl/src/repl/clarity_values.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Write;

use clarity::vm::{
types::{CharType, SequenceData},
Value,
Expand All @@ -22,47 +24,50 @@ pub fn uint8_to_value(mut value: &[u8]) -> Value {

pub fn value_to_string(value: &Value) -> String {
match value {
Value::Principal(principal_data) => {
format!("'{principal_data}")
}
Value::Principal(principal_data) => format!("'{}", principal_data),
Value::Tuple(tup_data) => {
let mut data = Vec::new();
for (name, value) in tup_data.data_map.iter() {
data.push(format!("{}: {}", &**name, value_to_string(value)))
let mut data = String::new();
for (name, value) in &tup_data.data_map {
write!(&mut data, "{}: {}, ", name, value_to_string(value)).unwrap();
}
format!("{{ {} }}", data.join(", "))
format!("{{ {} }}", data.trim_end_matches(", "))
}
Value::Optional(opt_data) => match opt_data.data {
Some(ref x) => format!("(some {})", value_to_string(x)),
Value::Optional(opt_data) => match &opt_data.data {
Some(x) => format!("(some {})", value_to_string(x)),
None => "none".to_string(),
},
Value::Response(res_data) => match res_data.committed {
true => format!("(ok {})", value_to_string(&res_data.data)),
false => format!("(err {})", value_to_string(&res_data.data)),
},
Value::Sequence(SequenceData::String(CharType::ASCII(data))) => {
format!("\"{}\"", String::from_utf8(data.data.clone()).unwrap())
Value::Response(res_data) => {
let committed = if res_data.committed { "ok" } else { "err" };
format!("({} {})", committed, value_to_string(&res_data.data))
}
Value::Sequence(SequenceData::String(CharType::UTF8(data))) => {
let mut result = String::new();
for c in data.data.iter() {
if c.len() > 1 {
// escape extended charset
result.push_str(&format!("\\u{{{}}}", hash::to_hex(&c[..])));
} else {
result.push(c[0] as char)
}
}
format!("u\"{result}\"")
Value::Sequence(SequenceData::String(CharType::ASCII(ascii_data))) => {
format!("\"{}\"", String::from_utf8_lossy(&ascii_data.data))
}
Value::Sequence(SequenceData::String(CharType::UTF8(utf8_data))) => {
let result = utf8_data
.data
.iter()
.map(|c| {
if c.len() > 1 {
format!("\\u{{{}}}", hash::to_hex(&c[..]))
} else {
(c[0] as char).to_string()
}
})
.collect::<Vec<_>>()
.join("");
format!("u\"{}\"", result)
}
Value::Sequence(SequenceData::List(list_data)) => {
let mut data = Vec::new();
for value in list_data.data.iter() {
data.push(value_to_string(value))
}
format!("(list {})", data.join(" "))
let data = list_data
.data
.iter()
.map(value_to_string)
.collect::<Vec<_>>()
.join(" ");
format!("(list {})", data)
}
_ => format!("{value}"),
_ => format!("{}", value),
}
}

Expand Down
Loading
Loading