Commit 77cc23b
committed
feat: introduce function support for deploy lifecycle hooks
Prior to this commits deployment lifecycle hooks had been defined as Array<string> due
to historical reasons (contracts.js) used to be a json file back in the days.
`deployIf`, `onDeploy` and `afterDeploy` can now be defined as (async)
function and have access to several dependencies such as contract instances and web3.
However, in order to have needed dependencies registered in the dependencies object,
all lifecycle hook dependencies need to be listed in the `deps` property
as shown below.
Also note that this is NOT a breaking change. Existing deployment lifecycle
hooks written in Array<string> style still work.
All three lifecycle hooks can now be defined as (async) functions and get an dependency
object with a shape like this:
```
interface DeploymentLifecycleHookDependencies {
contracts: Map<string, ContractInstance>;
web3: Web3Instance
}
```
`deployIf` lifecycle hook has to return a promise (or be defined using async/await and return
a value) like this:
```
contracts: {
MyToken: {...},
SimpleStorage: {
deps: ['MyToken'], // this is needed to make `MyToken` available within `dependencies`
deployIf: async (dependencies) => {
return dependencies.contracts.MyToken_address;
}
},
}
```
Vanilla promises (instead of async/await) can be used as well:
```
contracts: {
MyToken: {...},
SimpleStorage: {
deps: ['MyToken'],
deployIf: (dependencies) => {
return new Promise(resolve => resolve(dependencies.contracts.MyToken_address);
}
},
}
```
`onDeploy` as well, returns either a promise or is used using async/await:
```
contracts: {
SimpleStorage: {
onDeploy: async (dependencies) => {
const simpleStorage = dependencies.contracts.SimpleStorage;
const value = await simpleStorage.methods.get().call();
console.log(value);
}
},
}
```
`afterDeploy` has automatically access to all configured and deployed contracts of the dapp:
```
contracts: {
SimpleStorage: {...},
MyToken: {...},
afterDeploy: (dependencies) => {
console.log('Done!');
}
}
```
Closes #10291 parent cabfa93 commit 77cc23b
3 files changed
+137
-50
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
333 | | - | |
| 333 | + | |
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | | - | |
| 340 | + | |
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
410 | 416 | | |
411 | 417 | | |
412 | 418 | | |
413 | | - | |
414 | 419 | | |
415 | 420 | | |
416 | 421 | | |
| |||
427 | 432 | | |
428 | 433 | | |
429 | 434 | | |
430 | | - | |
431 | 435 | | |
432 | 436 | | |
433 | 437 | | |
434 | 438 | | |
435 | 439 | | |
436 | 440 | | |
437 | | - | |
438 | 441 | | |
439 | 442 | | |
440 | 443 | | |
| |||
443 | 446 | | |
444 | 447 | | |
445 | 448 | | |
446 | | - | |
| 449 | + | |
447 | 450 | | |
448 | 451 | | |
449 | 452 | | |
| |||
454 | 457 | | |
455 | 458 | | |
456 | 459 | | |
457 | | - | |
458 | 460 | | |
459 | 461 | | |
460 | 462 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
98 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
99 | 108 | | |
100 | | - | |
101 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
102 | 112 | | |
103 | 113 | | |
104 | 114 | | |
| |||
122 | 132 | | |
123 | 133 | | |
124 | 134 | | |
125 | | - | |
| 135 | + | |
126 | 136 | | |
127 | 137 | | |
128 | 138 | | |
| |||
133 | 143 | | |
134 | 144 | | |
135 | 145 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
144 | 170 | | |
145 | | - | |
146 | | - | |
| 171 | + | |
147 | 172 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | 173 | | |
155 | | - | |
156 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
157 | 177 | | |
158 | 178 | | |
159 | 179 | | |
160 | 180 | | |
161 | 181 | | |
162 | 182 | | |
163 | | - | |
| 183 | + | |
164 | 184 | | |
| 185 | + | |
165 | 186 | | |
166 | 187 | | |
167 | 188 | | |
168 | 189 | | |
169 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
170 | 235 | | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 236 | + | |
177 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
178 | 242 | | |
179 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
180 | 259 | | |
181 | 260 | | |
182 | 261 | | |
183 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
184 | 269 | | |
185 | 270 | | |
186 | 271 | | |
0 commit comments