Skip to content

Commit 71de5f8

Browse files
committed
fmt + clippy
1 parent ae754b8 commit 71de5f8

File tree

11 files changed

+199
-225
lines changed

11 files changed

+199
-225
lines changed

build.rs

+25-15
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,35 @@ use clvmr::Allocator;
55
use toml::{Table, Value};
66

77
use clvm_tools_rs::classic::clvm_tools::clvmc::CompileError;
8-
use clvm_tools_rs::classic::platform::argparse::ArgumentValue;
98
use clvm_tools_rs::classic::clvm_tools::comp_input::RunAndCompileInputData;
9+
use clvm_tools_rs::classic::platform::argparse::ArgumentValue;
1010
use clvm_tools_rs::compiler::comptypes::CompileErr;
1111
use clvm_tools_rs::compiler::srcloc::Srcloc;
1212

1313
fn do_compile(title: &str, filename: &str) -> Result<(), CompileError> {
1414
let mut allocator = Allocator::new();
1515
let mut arguments: HashMap<String, ArgumentValue> = HashMap::new();
16-
arguments.insert("include".to_string(), ArgumentValue::ArgArray(vec![ArgumentValue::ArgString(None, ".".to_string())]));
16+
arguments.insert(
17+
"include".to_string(),
18+
ArgumentValue::ArgArray(vec![ArgumentValue::ArgString(None, ".".to_string())]),
19+
);
1720

1821
let file_content = fs::read_to_string(filename).map_err(|e| {
19-
CompileErr(Srcloc::start(filename), format!("failed to read {filename}: {e:?}"))
22+
CompileErr(
23+
Srcloc::start(filename),
24+
format!("failed to read {filename}: {e:?}"),
25+
)
2026
})?;
2127

22-
arguments.insert("path_or_code".to_string(), ArgumentValue::ArgString(Some(filename.to_string()), file_content));
28+
arguments.insert(
29+
"path_or_code".to_string(),
30+
ArgumentValue::ArgString(Some(filename.to_string()), file_content),
31+
);
2332

2433
let parsed = RunAndCompileInputData::new(&mut allocator, &arguments).map_err(|e| {
2534
CompileError::Modern(
2635
Srcloc::start("*error*"),
27-
format!("error building chialisp {title}: {e}")
36+
format!("error building chialisp {title}: {e}"),
2837
)
2938
})?;
3039
let mut symbol_table = HashMap::new();
@@ -37,19 +46,20 @@ fn do_compile(title: &str, filename: &str) -> Result<(), CompileError> {
3746
fn compile_chialisp() -> Result<(), CompileError> {
3847
let srcloc = Srcloc::start("chialisp.toml");
3948
let chialisp_toml_text = fs::read_to_string("chialisp.toml").map_err(|e| {
40-
CompileError::Modern(srcloc.clone(), format!("Error reading chialisp.toml: {e:?}"))
49+
CompileError::Modern(
50+
srcloc.clone(),
51+
format!("Error reading chialisp.toml: {e:?}"),
52+
)
4153
})?;
4254

43-
let chialisp_toml = chialisp_toml_text.parse::<Table>().map_err(|e| {
44-
CompileError::Modern(srcloc, format!("Error parsing chialisp.toml: {e:?}"))
45-
})?;
55+
let chialisp_toml = chialisp_toml_text
56+
.parse::<Table>()
57+
.map_err(|e| CompileError::Modern(srcloc, format!("Error parsing chialisp.toml: {e:?}")))?;
4658

47-
if let Some(compiles) = chialisp_toml.get("compile") {
48-
if let Value::Table(t) = compiles {
49-
for (k,v) in t.iter() {
50-
if let Value::String(s) = v {
51-
do_compile(k, &s)?;
52-
}
59+
if let Some(Value::Table(t)) = chialisp_toml.get("compile") {
60+
for (k, v) in t.iter() {
61+
if let Value::String(s) = v {
62+
do_compile(k, s)?;
5363
}
5464
}
5565
}

src/channel_handler/game.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clvm_traits::{ClvmEncoder, ToClvm};
2-
use clvmr::{NodePtr, run_program};
2+
use clvmr::{run_program, NodePtr};
33

44
use clvm_tools_rs::classic::clvm::sexp::proper_list;
55

@@ -65,11 +65,11 @@ impl Game {
6565
.expect("should be an atom");
6666
let required_size_factor = Amount::new(
6767
atom_from_clvm(allocator, template_list[3])
68-
.and_then(|a| u64_from_atom(a))
68+
.and_then(u64_from_atom)
6969
.expect("should be an atom"),
7070
);
7171
let initial_max_move_size = atom_from_clvm(allocator, template_list[4])
72-
.and_then(|a| usize_from_atom(a))
72+
.and_then(usize_from_atom)
7373
.expect("should be an atom");
7474
let initial_validation_program = ValidationProgram::new(allocator, template_list[5]);
7575
let initial_validation_program_hash =
@@ -82,7 +82,7 @@ impl Game {
8282
};
8383
let initial_state = template_list[7];
8484
let initial_mover_share_proportion = atom_from_clvm(allocator, template_list[8])
85-
.and_then(|a| usize_from_atom(a))
85+
.and_then(usize_from_atom)
8686
.expect("should be an atom");
8787
Ok(Game {
8888
id: game_id,

src/channel_handler/game_handler.rs

+18-21
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn run_code(
155155
pub enum TheirTurnResult {
156156
FinalMove(NodePtr),
157157
MakeMove(NodePtr, GameHandler, Vec<u8>),
158-
Slash(Evidence, Aggsig),
158+
Slash(Evidence, Box<Aggsig>),
159159
}
160160

161161
impl GameHandler {
@@ -206,10 +206,7 @@ impl GameHandler {
206206
inputs.amount.clone(),
207207
(
208208
inputs.last_mover_share.clone(),
209-
(
210-
inputs.last_max_move_size.clone(),
211-
(inputs.entropy.clone(), ()),
212-
),
209+
(inputs.last_max_move_size, (inputs.entropy.clone(), ())),
213210
),
214211
),
215212
)
@@ -249,27 +246,27 @@ impl GameHandler {
249246
}
250247

251248
let max_move_size =
252-
if let Some(mm) = atom_from_clvm(allocator, pl[4]).and_then(|a| usize_from_atom(a)) {
249+
if let Some(mm) = atom_from_clvm(allocator, pl[4]).and_then(usize_from_atom) {
253250
mm
254251
} else {
255252
return Err(Error::StrErr("bad max move size".to_string()));
256253
};
257-
let mover_share =
258-
if let Some(ms) = atom_from_clvm(allocator, pl[5]).and_then(|a| u64_from_atom(a)) {
259-
Amount::new(ms)
260-
} else {
261-
return Err(Error::StrErr(format!(
262-
"bad share {}",
263-
disassemble(allocator.allocator(), pl[5], None)
264-
)));
265-
};
254+
let mover_share = if let Some(ms) = atom_from_clvm(allocator, pl[5]).and_then(u64_from_atom)
255+
{
256+
Amount::new(ms)
257+
} else {
258+
return Err(Error::StrErr(format!(
259+
"bad share {}",
260+
disassemble(allocator.allocator(), pl[5], None)
261+
)));
262+
};
266263
let message_parser = if pl[7] == allocator.allocator().null() {
267264
None
268265
} else {
269266
Some(MessageHandler::from_nodeptr(pl[7]))
270267
};
271268
let validation_program_hash =
272-
if let Some(h) = atom_from_clvm(allocator, pl[2]).map(|a| Hash::from_slice(a)) {
269+
if let Some(h) = atom_from_clvm(allocator, pl[2]).map(Hash::from_slice) {
273270
h
274271
} else {
275272
return Err(Error::StrErr("bad hash".to_string()));
@@ -312,7 +309,7 @@ impl GameHandler {
312309
let driver_args = (
313310
inputs.amount.clone(),
314311
(
315-
Node(inputs.last_state.clone()),
312+
Node(inputs.last_state),
316313
(
317314
Node(
318315
allocator
@@ -322,7 +319,7 @@ impl GameHandler {
322319
(
323320
inputs.new_move.validation_info_hash.clone(),
324321
(
325-
inputs.new_move.basic.max_move_size.clone(),
322+
inputs.new_move.basic.max_move_size,
326323
(inputs.new_move.basic.mover_share.clone(), ()),
327324
),
328325
),
@@ -362,10 +359,10 @@ impl GameHandler {
362359

363360
if move_type == 0 {
364361
if pl.len() < 2 {
365-
return Err(Error::StrErr(format!(
362+
Err(Error::StrErr(format!(
366363
"bad length for move result {}",
367364
disassemble(allocator.allocator(), run_result, None)
368-
)));
365+
)))
369366
} else if pl.len() < 3 {
370367
Ok(TheirTurnResult::FinalMove(pl[1]))
371368
} else {
@@ -390,7 +387,7 @@ impl GameHandler {
390387
let sig_bytes = allocator.allocator().atom(pl[2]).to_vec();
391388
Ok(TheirTurnResult::Slash(
392389
Evidence::from_nodeptr(pl[1]),
393-
Aggsig::from_slice(&sig_bytes)?,
390+
Box::new(Aggsig::from_slice(&sig_bytes)?),
394391
))
395392
} else {
396393
Err(Error::StrErr("unknown move result type".to_string()))

0 commit comments

Comments
 (0)