-
Notifications
You must be signed in to change notification settings - Fork 77
VS Code Snippets
Anton Trunov edited this page Jul 18, 2022
·
1 revision
The vscode-scilla plugin defines multiple useful code snippets. This page contains an extension to that set, including the most recent Scilla features related to contract addresses. Please, use the docs to integrate these snippets in your workflow.
{
"loop": {
"prefix": ["for-loop", "loop", "forall"],
"body": [
"forall ${1:list-to-iterate-on} ${2:procedure-name}"
],
"description": "Create a \"for-loop\", i.e. a forall statement to call a procedure repeatedly on list elements"
},
"read from a contract field": {
"prefix": ["field-read"],
"body": [
"${1:identifier} <- ${2:field};"
],
"description": "Read from a mutable contract field"
},
"write to a contract field": {
"prefix": ["field-write", "field-store"],
"body": [
"${1:field} := ${2:identifier}"
],
"description": "Write to a mutable contract field"
},
"read unary field map": {
"prefix": ["map-read"],
"body": [
"${1:optional-value} <- ${2:field-map}[${3:key}];",
"match $1 with",
"| Some ${4:value} => ${5:command(s)-to-do-if-key-is-present}",
"| None => ${6:commands-to-do-if-key-is-missing}",
"end"
],
"description": "Read a mutable contract map and analyze it immediately"
},
"read from blockchain state": {
"prefix": ["blockchain-read"],
"body": [
"${1:identifier} <-& ${2:blockchain-query};"
],
"description": "Read from blockchain state",
},
"read blocknumber": {
"prefix": ["blockchain-blocknumber", "blocknumber"],
"body": [
"${1:identifier} <-& BLOCKNUMBER;"
],
"description": "Read the block number from blockchain state",
},
"dynamic address cast": {
"prefix": ["address-cast", "blockchain-address-cast"],
"body": [
"${1:optional-address} <-& ${2:address} as ByStr20 with contract field ${3:field-name}: ${4:field-type} end;",
"match $1 with",
"| Some ${5:address} => ${6:command(s)-to-do-if-cast-succeeds}",
"| None => ${7:commands-to-do-if-dynamic-cast-fails}",
"end"
],
"description": "Dynamically cast an address to a contract address with required fields"
},
"contract address type with 1 field": {
"prefix": ["address-1"],
"body": [
"ByStr20 with contract field ${1:field-name}: ${2:field-type} end"
],
"description": "Contract address type with one field"
},
"contract address type with 2 fields": {
"prefix": ["address-2"],
"body": [
"ByStr20 with contract field ${1:field-name-1}: ${2:field-type-1}, ${3:field-name-2}: ${4:field-type-2} end"
],
"description": "Contract address type with two fields"
}
}