Observe statement is used to capture values from the state and sets it to a value.
observe map <- ModMutate.State.num:
If an observe statement ends with an ‘:’ sign then it can have a body in which the value that has been observed can be used. If a variable is not declared in advance the value is lost after the observe statement.
Multiple targets and values can be listed in a single statement, e.g.
observe name, symbol <- Mod.State.name, Mod.State.symbol
Mutate statement is used to set a module value to the state.
mutate n -> ModMutate.State.check
In this case the the value in ‘n’ is set to the check field of the persistent state.
mutate num <- ModMutate.State.num:
If a mutate statement ends with a ‘:’ then the statement can have a context block. In the the case of the mutate statement with a context the final value of
num after execution of the block is set back into the persistent state at the end of the mutation context.
num can’t be a variable name that’s already declared and it’s local to the mutate block.
observe, mutate accepts multiple targets & values in a statement.
coco ModMutate state persistent: num Map[String]U64 check U64 endpoint deployer Init!(): pass endpoint invokable Sum!(num1 U64, str String): mutate num <- ModMutate.State.num: num[str] += num1 endpoint invokable Num() -> (output Map[String]U64): observe output <- ModMutate.State.num endpoint invokable Numplusone(str String) -> (output U64): observe map <- ModMutate.State.num: output = map[str] + 1 endpoint invokable SetCheck!(n U64): mutate n -> ModMutate.State.check