Created
June 5, 2019 21:45
-
-
Save mightybyte/decaf13c4956f0a358c99e36a9bd4b9f to your computer and use it in GitHub Desktop.
Hello world with formal verification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
;; "Hello, world!" smart contract/module | |
;; | |
;; Define the module. | |
(module hello-world MODULE_ADMIN | |
"A smart contract to greet the world." | |
; no-op module admin for example purposes. | |
; in a real contract this could enforce a keyset, or | |
; tally votes, etc. | |
(defcap MODULE_ADMIN () true) | |
(defschema message-schema | |
@doc "Message schema" | |
@model [(invariant (!= msg ""))] | |
msg:string) | |
(deftable | |
message:{message-schema}) | |
(defun set-message | |
( | |
m:string | |
) | |
"Set the message that will be used next" | |
(write message "0" {"msg": m}) | |
) | |
(defun greet () | |
"Do the hello-world dance" | |
(with-default-read message "0" { "msg": "" } { "msg":= msg } | |
(format "Hello {}!" [msg]))) | |
) | |
(create-table message) | |
(set-message "world") | |
(greet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment