Check stateful annotations

Functions must be annotated as `stateful` in order to
- Update the contract state (using `put`)
- Call `Chain.spend` or other primitive functions that cost tokens
- Call an Oracle or AENS function that requires a signature
- Make a remote call with a non-zero value
- Construct a lambda calling a stateful function

It does not need to be stateful to
- Read the contract state
- Call another contract with value=0, even when the remote function is stateful
This commit is contained in:
Ulf Norell
2019-05-13 13:39:17 +02:00
parent e1a798aef4
commit 5aed8b3ef5
18 changed files with 152 additions and 59 deletions
+4 -4
View File
@@ -4,19 +4,19 @@ contract SpendContract =
contract SpendTest =
function spend(to, amount) =
stateful function spend(to, amount) =
let total = Contract.balance
Chain.spend(to, amount)
total - amount
function withdraw(amount) : int =
stateful function withdraw(amount) : int =
spend(Call.caller, amount)
function withdraw_from(account, amount) =
stateful function withdraw_from(account, amount) =
account.withdraw(amount)
withdraw(amount)
function spend_from(from, to, amount) =
stateful function spend_from(from, to, amount) =
from.withdraw(amount)
Chain.spend(to, amount)
Chain.balance(to)