You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The constructor arguments are provided when initializing a specific instance of a smart contract. The provided constructor arguments are added to the start of the contract's script before the opcode logic. Because the constructor arguments are part of the full smart contract script, they are conceptually similar to hard-coded constants in your contract logic. Constructor arguments are a way to create 'global constants' accessible from different functions inside your contract.
34
+
The constructor arguments are provided when initializing a specific instance of a smart contract. The provided constructor arguments are added to the start of the contract's script before the opcode logic. Because the constructor arguments are part of the full smart contract script, they are conceptually similar to hard-coded values in your contract logic. Constructor arguments are a way to create 'global variables' accessible from different functions inside your contract. Note that constructor arguments are variables and can be reassigned inside the contract functions.
35
35
36
36
:::info
37
37
The typings for the constructor arguments are only semantic and used when initializing the contract with the SDK. This means when not using the SDK you could still pass a different byte length item to `bytes32 hash`.
The function arguments are provided when attempting to spend from the contract. This means that these arguments can be crafted in a specific way by anyone to see if they can exploit the contract logic. Because of this it is important to realize these are 'untrusted arguments'.
64
+
Function arguments are provided by the user in the unlocking script of the transaction inputs when spending from the contract. Note that function arguments are variables and can be reassigned inside the function body.
65
+
66
+
Because the arguments are provided by the user when spending from the contract, these are 'untrusted arguments'. This means that these arguments can be crafted in a specific way by anyone to see if they can exploit the contract logic.
67
+
68
+
:::note
69
+
Function parameters are passed in the reversed order of their declaration. This can be important when debugging, optimizing or when creating transactions manually.
70
+
:::
65
71
66
72
In CashScript the types for the function arguments are **not** enforced automatically at the contract level. This can be especially relevant for types like `bool`, `bytesX` and other semantic bytes types. Instead this type information is only used by the SDK to check whether these arguments match the expected type during transaction building.
67
73
68
74
:::caution
69
75
The typings for the function arguments are only semantic, this means the length of bounded bytes types like `bytes20` are **not** contract enforced automatically. Instead add an explicit length check `require(item.length == 20)`.
70
76
:::
71
77
72
-
:::note
73
-
Function parameters are passed in the reversed order of their declaration. This can be important when debugging, optimizing or when creating transactions manually.
74
-
:::
75
-
76
78
## Statements
77
79
CashScript functions are made up of a collection of statements that determine whether money may be spent from the contract.
CashScript uses nested scopes for parameters, variables and global functions. There cannot be two identical names within the same scope or within a nested scope.
180
+
181
+
There are the following scopes in the nesting order:
182
+
183
+
-**Global scope** - contains global functions and global variables (e.g. `sha256`, `hash160`, `checkSig`, etc.)
// Function scope (contains function parameters - recipientSig)
199
+
function transfer(sig recipientSig) {
200
+
require(checkSig(recipientSig, recipient));
201
+
}
202
+
203
+
// Function scope (contains function parameters - senderSig)
204
+
function timeout(sig senderSig) {
205
+
require(checkSig(senderSig, sender));
206
+
207
+
// Local scope (contains local variable - newTimeout)
208
+
// This is just an example local scope, not a real contract
209
+
if (timeout > 100_000) {
210
+
int newTimeout = 100_000;
211
+
require(tx.time >= newTimeout);
212
+
} else {
213
+
require(tx.time >= timeout);
214
+
}
215
+
216
+
// After the local scope, 'newTimeout' is no longer accessible
217
+
}
218
+
}
219
+
220
+
```
221
+
175
222
## Comments
176
223
Comments can be added anywhere in the contract file. Comment semantics are similar to languages like JavaScript or C. This means that single-line comments can be added with `// ...`, while multiline comments can be added with `/* ... */`.
0 commit comments