Commit b562697
refactor(motoko): canister: import + --actor-env-alias for external-canister calls (ic-pos, evm_block_explorer, llm_chatbot) (#1453)
* refactor(motoko): use canister: import + --actor-env-alias for external-canister calls
Apply the Tier 1 pattern (canister:<name> import backed by moc's
--actor-env-alias) to the three Motoko examples that call an external
canister already named + env-injected in icp.yaml:
- ic-pos → icrc1_ledger (drops the hand-written Ledger actor
type and the Account/Transfer/Transaction subtypes)
- evm_block_explorer → evm_rpc (drops the ~140-line EvmRpcApi type
surface: RpcServices/RpcConfig/BlockTag/errors/actor)
- llm_chatbot → llm (drops the LlmActor/Request/Response
boilerplate; keeps the public message types, which
are the backend's own API and are structurally
identical to the LLM canister's)
For each backend:
- import the target by name and drop the actor type + Runtime.envVar +
actor(id) plumbing (and the now-unneeded <system> params);
- commit the target's Candid interface, extracted from the exact pre-built
Wasm pinned in icp.yaml via `ic-wasm <wasm> metadata candid:service`
(icrc1_ledger.did, evm_rpc.did, llm.did);
- wire the import in mops.toml with
`--actor-env-alias <alias> PUBLIC_CANISTER_ID:<name> <did-path>`
(per-canister args replace the global [moc].args, so the global flags
are repeated).
The principal is still resolved from PUBLIC_CANISTER_ID:<name>, now at
canister install/upgrade rather than per call. Each backend's public
backend.did is byte-identical after the change (verified with
`mops generate candid backend`), so the frontends are unaffected.
READMEs document the typed import and, for these external targets, that
the committed .did is refreshed by re-extracting it from the pinned Wasm
(not `mops generate candid`).
Verified: all three build with `mops build`; evm_block_explorer deployed
locally and `get_evm_block(1)` returns Ethereum mainnet block 1 with the
correct hash and miner.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* refactor(motoko): move external-canister interfaces into a project-level candid/ dir
Address review feedback on the Tier 2 examples: keep a project's own
interface with its code (backend/backend.did, generated by
`mops generate candid`), and move the interfaces of *external* canisters
the project calls into a shared, project-root `candid/` directory:
- ic-pos: backend/icrc1_ledger.did -> candid/icrc1_ledger.did
- evm_block_explorer: backend/evm_rpc.did -> candid/evm_rpc.did
- llm_chatbot: backend/llm.did -> candid/llm.did
This separates first-party from vendored interfaces (a 586-line ledger
.did no longer sits next to the 20-line backend.did) and scales to
projects with several canisters that share an external interface — one
copy in candid/, referenced by each canister's mops.toml, rather than a
per-backend folder that would duplicate it.
Updates the `--actor-env-alias` did-paths in mops.toml, the in-code
comments, and the READMEs (which now explain the candid/ convention and
drop the vague "different kind of file" wording). Rebuilt all three;
each backend.did is unchanged.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* docs(motoko): explain both ways to refresh an external canister's .did
The refresh instructions previously said "re-extract it from that Wasm"
but never said where the Wasm comes from — it is only pinned by URL in
icp.yaml, not present in the project. Rewrite the note in all three Tier 2
examples to give two clear, self-contained options:
- from mainnet, by the canister's principal:
`icp canister metadata <principal> candid:service -e ic`
- from the pinned Wasm: download the exact pre-built artifact pinned in
icp.yaml (build.steps[].url), unpack it, then `ic-wasm ... candid:service`
Both were verified to reproduce the committed candid/*.did byte-for-byte.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent db0ca74 commit b562697
12 files changed
Lines changed: 1115 additions & 224 deletions
File tree
- motoko
- evm_block_explorer
- backend
- candid
- ic-pos
- backend
- candid
- llm_chatbot
- backend
- candid
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
69 | 88 | | |
70 | 89 | | |
71 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
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 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
161 | 13 | | |
162 | 14 | | |
163 | 15 | | |
164 | 16 | | |
165 | 17 | | |
166 | 18 | | |
167 | | - | |
168 | | - | |
| 19 | + | |
| 20 | + | |
169 | 21 | | |
170 | 22 | | |
171 | | - | |
| 23 | + | |
172 | 24 | | |
173 | 25 | | |
174 | 26 | | |
175 | 27 | | |
176 | | - | |
| 28 | + | |
177 | 29 | | |
178 | 30 | | |
179 | 31 | | |
| |||
0 commit comments