Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Algob cli format for passing the arguments in script. #850

Merged
merged 25 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions .github/workflows/05-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,29 @@ jobs:
working-directory: ./examples/asa
run: |
pipenv run yarn algob deploy
pipenv run yarn algob run --script scripts/transfer/gold-contract-sc.js
pipenv run yarn algob run --script scripts/transfer/gold-delegated-lsig.js
pipenv run yarn algob run --script scripts/transfer/gold-to-john.js
pipenv run yarn algob run --script scripts/transfer/master-fund-john.js
pipenv run yarn algob run --script scripts/transfer/tesla-to-john.js
pipenv run yarn algob run scripts/transfer/gold-contract-sc.js
pipenv run yarn algob run scripts/transfer/gold-delegated-lsig.js
pipenv run yarn algob run scripts/transfer/gold-to-john.js
pipenv run yarn algob run scripts/transfer/master-fund-john.js
pipenv run yarn algob run scripts/transfer/tesla-to-john.js

- name: Example bond token
working-directory: ./examples/bond
run: |
pipenv run yarn algob deploy
pipenv run yarn algob run --script scripts/run/run.js
pipenv run yarn algob run scripts/run/run.js

- name: Example crowdfunding
working-directory: ./examples/crowdfunding
run: |
pipenv run yarn algob deploy
pipenv run yarn algob run --script scripts/transfer/donate.js
pipenv run yarn algob run scripts/transfer/donate.js

- name: Example htlc-pyteal-ts
working-directory: ./examples/htlc-pyteal-ts
run: |
pipenv run yarn algob deploy
pipenv run yarn algob run --script scripts/withdraw/htlc-withdraw.ts
pipenv run yarn algob run scripts/withdraw/htlc-withdraw.ts

- name: Example multisig
run: cd examples/multisig && pipenv run yarn algob deploy
Expand All @@ -106,20 +106,20 @@ jobs:
working-directory: ./examples/nft
run: |
pipenv run yarn algob deploy
pipenv run yarn algob run --script scripts/transfer/create-transfer-nft.js
pipenv run yarn algob run scripts/transfer/create-transfer-nft.js

- name: Example permissioned-token
working-directory: ./examples/permissioned-token
run: |
pipenv run yarn algob deploy
pipenv run yarn algob run --script scripts/admin/issue.js
pipenv run yarn algob run --script scripts/permissions/whitelist.js
pipenv run yarn algob run --script scripts/user/transfer.js
pipenv run yarn algob run --script scripts/admin/force-transfer.js
pipenv run yarn algob run --script scripts/admin/update-reserve.js
pipenv run yarn algob run --script scripts/permissions/change-perm-manager.js
pipenv run yarn algob run --script scripts/admin/kill.js
pipenv run yarn algob run --script scripts/user/opt-out.js
pipenv run yarn algob run scripts/admin/issue.js
pipenv run yarn algob run scripts/permissions/whitelist.js
pipenv run yarn algob run scripts/user/transfer.js
pipenv run yarn algob run scripts/admin/force-transfer.js
pipenv run yarn algob run scripts/admin/update-reserve.js
pipenv run yarn algob run scripts/permissions/change-perm-manager.js
pipenv run yarn algob run scripts/admin/kill.js
pipenv run yarn algob run scripts/user/opt-out.js

run-examples-batch-2:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -160,15 +160,15 @@ jobs:
working-directory: ./examples/permissioned-token-freezing
run: |
pipenv run yarn algob deploy
pipenv run yarn algob run --script scripts/transfer/set-clear-level.js
pipenv run yarn algob run --script scripts/transfer/transfer-asset.js
pipenv run yarn algob run scripts/transfer/set-clear-level.js
pipenv run yarn algob run scripts/transfer/transfer-asset.js

- name: Example permissioned-voting
working-directory: ./examples/permissioned-voting
run: |
pipenv run yarn algob deploy
pipenv run yarn algob run --script scripts/vote/vote.js
pipenv run yarn algob run --script scripts/vote/result.js
pipenv run yarn algob run scripts/vote/vote.js
pipenv run yarn algob run scripts/vote/result.js

- name: Example ref-templates
run: |
Expand All @@ -179,8 +179,8 @@ jobs:
working-directory: ./examples/stateful-counter
run: |
pipenv run yarn algob deploy
pipenv run yarn algob run --script scripts/interaction/call_application.js
pipenv run yarn algob run --script scripts/interaction/delete_application.js
pipenv run yarn algob run scripts/interaction/call_application.js
pipenv run yarn algob run scripts/interaction/delete_application.js

run-examples-batch-3:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -221,15 +221,19 @@ jobs:
working-directory: ./examples/unique-nft-asa
run: |
pipenv run yarn algob deploy
pipenv run yarn algob run --script scripts/run/transfer-nft.js
pipenv run yarn algob run scripts/run/transfer-nft.js
- name: Example inner-tx-create-assets
working-directory: ./examples/inner-tx-create-assets
run: |
pipenv run yarn algob deploy
pipenv run yarn algob run --script scripts/run/useInnerTxn.js
pipenv run yarn algob run --script scripts/run/useGroupTxn.js
pipenv run yarn algob run scripts/run/useInnerTxn.js
pipenv run yarn algob run scripts/run/useGroupTxn.js
- name: Trampoline
working-directory: ./examples/trampoline
run: |
pipenv run yarn algob deploy
pipenv run yarn algob run --script scripts/run/create-fund-app.js
pipenv run yarn algob run scripts/run/create-fund-app.js
- name: Script Argument Example
working-directory: ./examples/script-argument-example
run: |
pipenv run yarn algob run scripts/script.js --arg '{"name":"this was passed as agrument"}'
2 changes: 1 addition & 1 deletion docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Check the _requirements_ section above first.\_
1. Add assets and smart-contracts in the `assets` directory.
1. Add deployment scripts in `scripts` directory.
1. Run `yarn run algob deploy` to compile and deploy everything (all scripts nested directly in /scripts).
1. Run `yarn run algob run --script scriptPath/scriptName` to run a script.
1. Run `yarn run algob run scriptPath/scriptName` to run a script.
1. To run `algob` on different network (by default the `default` network is used) use

yarn run algob --network <other_network_name> <command>
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/debugging-teal.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ If it displays the `tealdbg` help, you're good to go.

Creating transaction data (via `goal --dryrun-dump` or SDK) could be a lengthy process, especially when using a transaction group. `Algob` provides an easy way to use debugger: by simply supplying the transactions as an input to the `TealDbg` method (same transaction parameters that we supply to [executeTx](https://algobuilder.dev/api/algob/modules.html#executeTransaction) to execute same transaction on network).

NOTE: You use the `TealDbg` method in an algob script, which can be run using `algob deploy`/`algob run --script` commands.
NOTE: You use the `TealDbg` method in an algob script, which can be run using `algob deploy`/`algob run` commands.

### Using dry run for debugging a TEAL program in an algob script

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/deployer.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Deployer class has the following modes:
- Run Mode: In run mode user can access/read checkpoints, create logs but cannot write(create) checkpoints. Files placed in nested folders (non-direct children, eg: `scripts/transfer/run-script.js`) of `scripts/` folder are considered to be run in this mode.
To run a script in the _run_ mode (the script will receive deployer instance in _run_ mode\_):

yarn run algob run --script scripts/transfer/run-script.js
yarn run algob run scripts/transfer/run-script.js

**Note:** In run mode user can `deploy`, `update`, `delete` or perform all these operations in a group transaction using [`executeTx`](https://algobuilder.dev/api/algob/modules.html#executetransaction) function but the `checkpoints will not be created when using run mode.`

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/purestake-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
};
```

And while running the script, you can simply pass this cfg with the `--network` flag. (eg. `algob run --script scripts/run.js --network purestake`).
And while running the script, you can simply pass this cfg with the `--network` flag. (eg. `algob run scripts/run.js --network purestake`).

## IndexerV2

Expand Down
6 changes: 3 additions & 3 deletions docs/guide/user-script-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ layout: splash

In algob, scripts are JS files stored in the `scripts` directory and are meant to interact with the blockchain (deploy ASA, ASC1, run transactions...).

Scripts are run through `algob run --script` and `algob deploy` commands. `algob` is using `algob.config.js` to get information about network and accounts and is executing incremental scripts found in `scripts/`.
Scripts are run through `algob run` and `algob deploy` commands. `algob` is using `algob.config.js` to get information about network and accounts and is executing incremental scripts found in `scripts/`.

Please see the [architecture document](https://paper.dropbox.com/published/Algorand-builder-specs--A7njBF~7_VHYy0l3m3RAKgYVBg-c4ycJtlcmEaRIbptAPqNYS6#:h2=Scripts) to see how the scripts are organized and how to use them.

### Script execution

As noted above there are two commands to execute scripts:

- `algob run --script`
- `algob run`
- `algob deploy`

#### Run
Expand All @@ -25,7 +25,7 @@ Runs provided scripts and doesn't save script checkpoints.
Useful to query the current state of blockchain.
Example:

algob run --script scripts/script1.js
algob run scripts/script1.js

#### Deploy

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/t-01.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ async function run(runtimeEnv, deployer) {
module.exports = { default: run };
```

Similarly to `scripts/0-gold.js`, this file exports one default function. This function, however, will not be run using `algob deploy`. Instead, we will use `algob run --script`:
Similarly to `scripts/0-gold.js`, this file exports one default function. This function, however, will not be run using `algob deploy`. Instead, we will use `algob run`:

algob run --script scripts/transfer/gold-to-john.js
algob run scripts/transfer/gold-to-john.js

The main difference between `run` and `deploy` is that:

Expand Down
6 changes: 3 additions & 3 deletions examples/asa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ To deploy all assets simply run:

It will go through all files in directly placed in the `scripts/` directory (so, it doesn't go recursively into the subdirectories) and run them in the _deploy_ mode. For more information about the deployer read the [deployer guide](https://algobuilder.dev/guide/deployer.html).

Transfers can be executed by executing `algob run --script scripts/transfer/gold-to-john.js` and other scripts in `scripts/transfer/`.
Transfers can be executed by executing `algob run scripts/transfer/gold-to-john.js` and other scripts in `scripts/transfer/`.
These scripts contain logic to transfer assets to `john-account` but other accounts can be configured as well.

Balances can be queried by executing `algob run --script scripts/query/john-balances.js`.
Balances can be queried by executing `algob run scripts/query/john-balances.js`.

This example also includes smart signatures in (`assets/` directory) that showcase the two different modes of operation (contract & signature delegation):

Expand Down Expand Up @@ -58,5 +58,5 @@ This example is using PyTEAL, so make sure to follow the Python3 setup described

```
yarn algob deploy
yarn algob run --script scripts/query/john-balances.js
yarn algob run scripts/query/john-balances.js
```
2 changes: 1 addition & 1 deletion examples/asa/scripts/transfer/gold-delegated-lsig.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Description:
* This file demonstrates the example to run teal debugger for transfer Algorand
* Standard Assets(ASA) & MicroAlgos using delegated lsig (between 2 user accounts).
* You can run it using `algob run --script scripts/transfer/gold-delegated-lsig.debug.js`
* You can run it using `algob run scripts/transfer/gold-delegated-lsig.debug.js`
*/
const { types } = require("@algo-builder/web");
const { Tealdbg } = require("@algo-builder/algob");
Expand Down
8 changes: 4 additions & 4 deletions examples/crowdfunding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ To Create Crowdfunding Stateful Smart Contract Application

To Donate:

yarn run algob run --script scripts/transfer/donate.js
yarn run algob run scripts/transfer/donate.js

To Claim:

yarn run algob run --script scripts/transfer/claim.js
yarn run algob run scripts/transfer/claim.js

To Reclaim:

yarn run algob run --script scripts/transfer/reclaim.js
yarn run algob run scripts/transfer/reclaim.js

To Delete application and tranfer remaining funds to crreator:

yarn run algob run --script scripts/transfer/delete.js
yarn run algob run scripts/transfer/delete.js

- Some points to be noted:
- Creator can only claim funds when total goal is reached.
Expand Down
2 changes: 1 addition & 1 deletion examples/htlc-pyteal-ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ This example is using PyTEAL, so make sure to follow the Python3 setup described

```
yarn run algob deploy
yarn run algob run --script scripts/withdraw/htlc-withdraw.ts
yarn run algob run scripts/withdraw/htlc-withdraw.ts
```
4 changes: 2 additions & 2 deletions examples/inner-tx-create-assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ yarn run algob deploy
## Deploy new application, asset and log id by group transaction

```
yarn run algob run --script useGroupTxn.js
yarn run algob run useGroupTxn.js
```

## Deploy new application, asset and log id by inner transaction

```
yarn run algob run --script useInnerTxn.js
yarn run algob run useInnerTxn.js
```
4 changes: 2 additions & 2 deletions examples/multisig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ You need to **_save the signed logic signature file in `examples/multisig/assets
### Run

```
yarn run algob run --script scripts/multisig_goal_sc.js
yarn run algob run --script scripts/multisig_sdk_sc.js
yarn run algob run scripts/multisig_goal_sc.js
yarn run algob run scripts/multisig_sdk_sc.js
```

### More information
Expand Down
2 changes: 1 addition & 1 deletion examples/nft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ This example is using PyTEAL, so make sure to follow the Python3 setup described

```
yarn run algob deploy
yarn run algob run --script scripts/transfer/create-transfer-nft.js
yarn run algob run scripts/transfer/create-transfer-nft.js
```
4 changes: 2 additions & 2 deletions examples/permissioned-token-freezing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ yarn run algob deploy
### Run

```
yarn run algob run --script scripts/transfer/set-clear-level.js // set minimum level(to transfer asset)
yarn run algob run --script scripts/transfer/transfer-asset.js // transfer asset from Alice -> Bob
yarn run algob run scripts/transfer/set-clear-level.js // set minimum level(to transfer asset)
yarn run algob run scripts/transfer/transfer-asset.js // transfer asset from Alice -> Bob
```

### More information
Expand Down
4 changes: 2 additions & 2 deletions examples/permissioned-voting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ To Create Vote-Token Asset and Permissioned voting application:

To Cast a Vote:

yarn run algob run --script scripts/vote/vote.js
yarn run algob run scripts/vote/vote.js

To see the results and delete the application:

yarn run algob run --script scripts/vote/result.js
yarn run algob run scripts/vote/result.js
1 change: 1 addition & 0 deletions examples/script-argument-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
7 changes: 7 additions & 0 deletions examples/script-argument-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Script argument example

This example demonstrates how you can pass arguments to script.

The format for passing arguments:

`yarn algob script.js --arg '<JSON-String>'`
14 changes: 14 additions & 0 deletions examples/script-argument-example/algob.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require("fs");

// check if local config in /examples exists if yes then use it, otherwise use a template
// config provided by this repository.

let config = "../algob.config-local.js";
try {
fs.accessSync(config, fs.constants.F_OK);
} catch {
config = "../algob.config-template.js";
}
console.log("config file: ", config);

module.exports = require(config);
26 changes: 26 additions & 0 deletions examples/script-argument-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "script-argument-example",
"version": "1.0.0",
"main": "index.js",
"license": "Apache-2.0",
"dependencies": {
"@algo-builder/algob": "workspace:*",
"@algo-builder/runtime": "workspace:*",
"@algo-builder/web": "workspace:*",
"algosdk": "^1.22.0"
},
"devDependencies": {
"eslint": "^8.26.0",
"mocha": "^10.1.0"
},
"scripts": {
"algob": "algob",
"lint:check": "eslint --ext .js,.ts scripts",
"lint": "eslint --fix --ext .js,.ts scripts",
"build:docs": "echo ok",
"build": "echo ok"
},
"mocha": {
"file": "../../test/setup.js"
}
}
6 changes: 6 additions & 0 deletions examples/script-argument-example/scripts/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
async function run(runtimeEnv, deployer, arg) {
// arguments received here
console.log(arg);
}

module.exports = { default: run };
2 changes: 1 addition & 1 deletion examples/signed-txn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The standard transaction file extension is `.txn`, but the code accepts any exte
### Run

```
yarn run algob run --script scripts/transfer.js
yarn run algob run scripts/transfer.js
```

### More information
Expand Down
2 changes: 1 addition & 1 deletion examples/trampoline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ If you run the file fundApplication.py, it will generate two file TEAL approval.

```
yarn run algob deploy
yarn run algob run --script scripts/run/create-fund-app.js
yarn run algob run scripts/run/create-fund-app.js
```
4 changes: 2 additions & 2 deletions packages/algob/sample-project/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ To run the `sample-project`:

- To interact with your deployments you can create a script and run it using:

* `algob run --script scripts/path_to/file1`
* Don’t use algob run --script for deployments. This should be used only for auxiliary scripts, like ad-hock transactions (example: draining an account).
* `algob run scripts/path_to/file1`
* Don’t use algob run for deployments. This should be used only for auxiliary scripts, like ad-hock transactions (example: draining an account).

- Run tests:

Expand Down
Loading