Skip to content

Instantly share code, notes, and snippets.

@mightybyte
Created June 5, 2019 21:45
Show Gist options
  • Save mightybyte/decaf13c4956f0a358c99e36a9bd4b9f to your computer and use it in GitHub Desktop.
Save mightybyte/decaf13c4956f0a358c99e36a9bd4b9f to your computer and use it in GitHub Desktop.
Hello world with formal verification
;;
;; "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