|
34 | 34 | - [Deploy contract on LocalOsmosis](#deploy-contract-on-localosmosis)
|
35 | 35 | - [Contract Upgrade](#contract-upgrade)
|
36 | 36 | - [Signers](#signers)
|
| 37 | +- [Tasks](#tasks) |
37 | 38 | - [Console](#console)
|
38 | 39 | - [Typescript SDK Generation](#typescript-sdk-generation)
|
39 | 40 | - [Frontend](#frontend)
|
@@ -346,6 +347,96 @@ Whenever you run command that requires signing transactions, there are 3 options
|
346 | 347 | - `--signer-private-key` input of this option is the same as `--signer-mnemonic` except it expects base64 encoded private key
|
347 | 348 | - `--signer-keyring` use the OS secure store as backend to securely store your key. To manage them, you can find more information [here](./docs/commands/beaker_key.md).
|
348 | 349 |
|
| 350 | +### Tasks |
| 351 | +Sometimes you want to run a series of commands in a single command. For example, you want to deploy a set of contracts that one contract instantiation depends on another contract. You can do this by defining a task in the `tasks` directory. |
| 352 | + |
| 353 | +```sh |
| 354 | +beaker task new deploy |
| 355 | +``` |
| 356 | + |
| 357 | +This will create a new task file in `tasks/deploy.rhai`. |
| 358 | + |
| 359 | +Task is written in `Rhai` which is an embedded scripting language in Rust. You can find example of how to write Rhai [here](https://rhai.rs/book/start/examples/scripts.html). |
| 360 | + |
| 361 | +Using Rhai as a scripting language makes exposing all existing functionality of Beaker to the task script relatively simple. Currently, all the subcommands of `beaker wasm` are exposed to the task script. So you can do things like: |
| 362 | + |
| 363 | +```rhai |
| 364 | +let counter_contract = wasm::deploy(merge( |
| 365 | + #{ |
| 366 | + signer_account: "test1" |
| 367 | + contract_name: "counter", |
| 368 | + msg: #{} |
| 369 | + } |
| 370 | +)); |
| 371 | +
|
| 372 | +let counter_proxy_contract = wasm::deploy(merge( |
| 373 | + #{ |
| 374 | + signer_account: "test1" |
| 375 | + contract_name: "counter", |
| 376 | + msg: #{ |
| 377 | + counter_contract_address: counter_contract.address |
| 378 | + } |
| 379 | + } |
| 380 | +)); |
| 381 | +
|
| 382 | +``` |
| 383 | + |
| 384 | +The interface of `wasm::deploy` the same as the `beaker wasm deploy` command. Other functions in `wasm` module are also similar to their corresponding subcommands so you can refer to the [documentation](./docs/commands/beaker_wasm.md) for more information about what is avialable in the script. |
| 385 | + |
| 386 | +Note that additional feature here is that `msg` can also be passed as an object rather than passing JSON string to `raw`. |
| 387 | + |
| 388 | +There are also some additional helper function and macros that are exposed to the task script. |
| 389 | + |
| 390 | +#### `fs` module |
| 391 | +This module provides access to the file system. It is similar to the `std::fs` module in Rust. Morre information about the module can be found [here](https://github.com/rhaiscript/rhai-fs#rhai-script). This is how it can be used in the task script: |
| 392 | + |
| 393 | +```rhai |
| 394 | +file = fs::open_file("params.json"); |
| 395 | +``` |
| 396 | + |
| 397 | +#### `match_args` |
| 398 | + |
| 399 | +Matching command line arguments passed to the script and returns a map of the arguments |
| 400 | + |
| 401 | +```rhai |
| 402 | +// beaker task run deploy -- --signer test1 --build-flags no_wasm_opt |
| 403 | +let cli_args = match_args(["signer", "build_flags"]); |
| 404 | +
|
| 405 | +print(cli_args) // => #{ signer: "test1", "build_flags": "no_wasm_opt" } |
| 406 | +``` |
| 407 | + |
| 408 | +#### `merge` |
| 409 | +Merges 2 objects together. If there are duplicate keys, the value from the second object will be used. |
| 410 | + |
| 411 | +```rhai |
| 412 | +let a = #{ a: 1, b: 2 }; |
| 413 | +let b = #{ b: 3, c: 4 }; |
| 414 | +
|
| 415 | +let merged = merge(a, b); |
| 416 | +
|
| 417 | +print(merged) // => #{ a: 1, b: 3, c: 4 } |
| 418 | +``` |
| 419 | + |
| 420 | +#### `@assert` |
| 421 | +Perform assertion on the given condition. If the condition is false, the script will exit with an error. |
| 422 | +This is useful for ensuring that the script is running as expected. |
| 423 | + |
| 424 | +```rhai |
| 425 | +@assert(1 == 1); // pass |
| 426 | +@assert(1 == 2); // fail |
| 427 | +
|
| 428 | +@assert(1 != 2); // pass |
| 429 | +@assert(1 != 1); // fail |
| 430 | +
|
| 431 | +@assert(1 < 2); // pass |
| 432 | +@assert(1 > 2); // fail |
| 433 | +
|
| 434 | +@assert(1 <= 2); // pass |
| 435 | +@assert(1 >= 2); // fail |
| 436 | +``` |
| 437 | + |
| 438 | +For more example on how to use task, you can refer to the [example tasks](./examples/scripting-cookbook/tasks/). |
| 439 | + |
349 | 440 | ### Console
|
350 | 441 |
|
351 | 442 | After deployed, you can play with the deployed contract using:
|
|
0 commit comments