By default, a `Value`field is also stored, and manages the funds in the contract. Changing the `Value` field creates a transaction between the user interacting and the contract.
By default, a `Value`field is also stored, and manages the funds in the contract. Changing the `Value` field creates a transaction between the user interacting and the contract.
**Trigger**:
*Temporal:*:
```hs
triggerslotcancelGame;
triggercancelGame(:[|<plutus_code>|])?;
```
*Example*:
```java
lock(String,Value)fromOwner{
triggerslotcancelGame;
};
```
*Funds:*:
```java
triggerfundscancelGame;
```
*Example*:
```java
lock(String,Value)fromOwner{
triggerfundscancelGame;
triggercancelGame;
};
```
...
...
@@ -190,4 +239,86 @@ Due to how Plutus on-chain code functions, we only support certain types (that P
-`Ada`
-`Slot`
-`TokenName`
-`POSIXTime`
\ No newline at end of file
-`POSIXTime`
-`Bool`
### Business logic auxiliary functions ###
For the business logic definition, we provide auxiliary functions to aid the programmer in the development:
-`returnOk`
-`returnOkWith`
-`returnOutputOk`
-`returnError`
-`printMsg`
-`printError`
**`returnOk`**:
This function is useful if the programmer wishes to keep all variables' values.
*Example*:
```java
ping()fromP1[|returnOk|];
```
**`returnOkWith`**:
This function allows changes in some of the variable's values
*Example*:
```
protocol PingPong (role P1) {
field var1:Integer,var2:Integer,var3:Integer;
ping(newV:Integer) from P1[|
returnOkWith var1 newV var3 stateVal mempty
|];
}
```
NOTE: The last value is a Plutus constraint that the `ping`'s transition applies to a transaction. In this example, `mempty` means there is no constraint.
**`returnOutputOk`**:
This function does the same as `returnOkWith` but is more pratical. We recommend this function, especially if there is a large number of variables in the `field`.
*Example*:
```
protocol PingPong (role P1) {
field var1:Integer,var2:Integer,var3:Integer;
ping(newV:Integer) from P1[|
returnOutputOk $ setVar2 newV output
|];
}
```
The setter functions depend on the `field` variables declared. In the example above, the compiler creates the following setters:
-`setVar1`
-`setVar2`
-`setVar3`
Regardless of the `field` variables, the compiler always creates this two setters:
-`setStateVal`: Updates the smart contract's funds.
-`setConstraint`: Defines the Plutus constraint the endpoint uses for a transaction.
**`returnError`**: This function returns the endpoint in case of an error.
*Example*:
```java
ping()fromP1[|
returnError"Hi! I failed somewhere so im going to return with this error message."
|];
```
**`printMsg` & `printError`**
These two functions print, respectively, a normal message and an error message.