Stateful Contracts - netrium/Netrium GitHub Wiki
Stateful contracts
Return to Making Decisions
Some contracts require the need to maintain some form of internal state, either for constraining decisions (for example, with a Virtual Power Plant or Gas Swing) or for performing stageful computations (for example, with a Weather Derivative).
Netrium uses the Read/LetIn
keyword to allow state to be maintained inside the contract. Note that since Haskell variables are immutable, each instance of the keyword is actually working on an independent variable. It can be made to appear as if it is working on the same variable through variable name sharing.
For the Gas Swing Contract, where the read/LetIn
process is used to constrain the number of variations from the Normal delivery level allowed over the lifetime of the contract, the process is as follows:
First, the contract sets the constraint:
Next, the contract checks the state of the constraint:
Finally, the contract alters the value in the constraint: