Skip to content

Commit 4be4fa8

Browse files
committed
refactor
1 parent a984e8a commit 4be4fa8

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/dfx/src/lib/builders/motoko.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ impl MotokoBuilder {
4141
})
4242
}
4343

44+
fn obtain_canister_maps(pool: &CanisterPool) -> (BTreeMap<String, String>, BTreeMap<String, String>) {
45+
// from name to principal:
46+
let id_map = pool
47+
.get_canister_list()
48+
.iter()
49+
.map(|c| (c.get_name().to_string(), c.canister_id().to_text()))
50+
.collect();
51+
// from principal to name:
52+
let rev_id_map = pool
53+
.get_canister_list()
54+
.iter()
55+
.map(|c| (c.canister_id().to_text(), c.get_name().to_string()))
56+
.collect();
57+
(id_map, rev_id_map)
58+
}
59+
4460
/// Accomplish build given the already calculated canister dependencies
4561
fn do_build(
4662
&self,
@@ -315,29 +331,16 @@ impl CanisterBuilder for MotokoBuilder {
315331
) -> DfxResult<BuildOutput> {
316332
let motoko_info = canister_info.as_info::<MotokoCanisterInfo>()?;
317333

318-
// from name to principal:
319-
let id_map = pool
320-
.get_canister_list()
321-
.iter()
322-
.map(|c| (c.get_name().to_string(), c.canister_id().to_text()))
323-
.collect();
324-
// from principal to name:
325-
let rev_id_map: BTreeMap<String, String> = pool
326-
.get_canister_list()
327-
.iter()
328-
.map(|c| (c.canister_id().to_text(), c.get_name().to_string()))
329-
.collect();
330-
331-
let cache = &self.cache;
332-
get_imports(cache.as_ref(), &motoko_info, &mut *pool.imports.borrow_mut(), pool)?;
334+
let (id_map, rev_id_map) = Self::obtain_canister_maps(pool);
335+
get_imports(self.cache.as_ref(), &motoko_info, &mut *pool.imports.borrow_mut(), pool)?;
333336

334337
self.do_build(
335338
pool,
336339
canister_info,
337340
config,
338341
&id_map,
339342
&rev_id_map,
340-
cache.as_ref(),
343+
self.cache.as_ref(),
341344
)
342345
}
343346

0 commit comments

Comments
 (0)