Skip to content

Commit

Permalink
update docs to describe supported cadence doc pragma (#513)
Browse files Browse the repository at this point in the history
* update docs to describe supported cadence doc pragma

* fix missing end tag

* address PR Reviews

* fix spelling and add colons

* add missing :
  • Loading branch information
bthaile authored Jan 19, 2024
1 parent 1f4014f commit d866924
Showing 1 changed file with 118 additions and 6 deletions.
124 changes: 118 additions & 6 deletions docs/tools/flow-cli/flix.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Available Commands:

### Execute

The Flow CLI provides a `flix` command to `execute` FLIX. The Cadence being execute in the FLIX can be a transaciton or script.
The Flow CLI provides a `flix` command to `execute` FLIX. The Cadence being execute in the FLIX can be a transaction or script.

```shell
flow flix execute <query> [<argument> <argument>...] [flags]
Expand Down Expand Up @@ -77,7 +77,7 @@ Generate FLIX json file. This command will take in a Cadence file and produce a

:::warning

When generating a FLIX template, make sure all contract dependencies have been deployed to the supported networks. Add any aliases to your flow.json that will be needed to populate dependencies. Verify all depenencies have been populated after generating.
When generating a FLIX template, make sure all contract dependencies have been deployed to the supported networks. Add any aliases to your flow.json that will be needed to populate dependencies. Verify all dependencies have been populated after generating.

:::

Expand All @@ -98,8 +98,85 @@ pub fun main(): String {
}
```


### Cadence Doc Pragma:
It's recommended to use pragma to set the metadata for the script or transaction. More information on [Cadence Doc Pragma FLIP](https://github.com/onflow/flips/blob/main/application/20230406-interaction-template-cadence-doc.md)

A pragma is short for "pragmatic information", it's special instructions to convey information to a processor in this case the utility that generates FLIX.
```cadence
import "HelloWorld"
#interaction (
version: "1.1.0",
title: "Update Greeting",
description: "Update the greeting on the HelloWorld contract",
language: "en-US",
)
transaction(greeting: String) {
prepare(acct: AuthAccount) {
log(acct.address)
}
execute {
HelloWorld.updateGreeting(newGreeting: greeting)
}
}
```

:::info
Cadence v0.42.7 supports additional Cadence pragma functionality that FlIX utility can use to generate FLIX. It will support parameters "title" and "description".
:::


The resulting json metadata is extracted from Cadence Doc Pragma
```json
{
"f_type": "InteractionTemplate",
"f_version": "1.1.0",
"id": "",
"data": {
"type": "transaction",
"interface": "",
"messages": [
{
"key": "title",
"i18n": [
{
"tag": "en-US",
"translation": "Update Greeting"
}
]
},
{
"key": "description",
"i18n": [
{
"tag": "en-US",
"translation": "Update the greeting on the HelloWorld contract"
}
]
}
],
"cadence": {},
"dependencies": [],
"parameters": [
{
"label": "greeting",
"index": 0,
"type": "String",
"messages": []
}
]
}
}
```

Example of using a prefilled FLIX json file. No need to use Cadence pragma when using a prefilled FLIX json file. This method separates FLIX specific information from the transaction or script Cadence. Use the `flow flix generate` command:

```shell
# Generate FLIX json file using cadence transaction or script passing in a pre filled FLIX json file. The json file will get filled out by the `flow flix generate` command
flow flix generate cadence/scripts/read-helloworld.cdc --pre-fill cadence/templates/read-helloworld.prefill.json --save cadence/templates/read-helloworld.template.json
```

Expand All @@ -112,7 +189,42 @@ pub fun main(): String {
}
```

Example of json prefill file with message metadata
Example of json prefill file with message metadata:
```json
{
"f_type": "InteractionTemplate",
"f_version": "1.1.0",
"id": "",
"data": {
"type": "script",
"interface": "",
"messages": [
{
"key": "title",
"i18n": [
{
"tag": "en-US",
"translation": "Get Greeting"
}
]
},
{
"key": "description",
"i18n": [
{
"tag": "en-US",
"translation": "Call HelloWorld contract to get greeting"
}
]
}
]
}
}

```

The resulting FLIX json file after generation:

```json
{
"f_type": "InteractionTemplate",
Expand All @@ -127,7 +239,7 @@ Example of json prefill file with message metadata
"i18n": [
{
"tag": "en-US",
"translation": "Get Gretting"
"translation": "Get Greeting"
}
]
},
Expand Down Expand Up @@ -198,7 +310,7 @@ flow flix package transfer-flow --save ./package/transfer-flow.js
```

```shell
# Geneate package code for a FLIX script using id, since there is no saving file, the result will display in terminal
# Generate package code for a FLIX script using id, since there is no saving file, the result will display in terminal
flow flix package bd10ab0bf472e6b58ecc0398e9b3d1bd58a4205f14a7099c52c0640d9589295f
```

Expand Down

1 comment on commit d866924

@vercel
Copy link

@vercel vercel bot commented on d866924 Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.