Skip to content

Instantly share code, notes, and snippets.

@gluk64
Created November 8, 2019 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gluk64/f9726d3d4e0380e14844b7931bf7197b to your computer and use it in GitHub Desktop.
Save gluk64/f9726d3d4e0380e14844b7931bf7197b to your computer and use it in GitHub Desktop.
Pact shared with chainweaver.
;;
;; "Hello, world!" smart contract/module
;;
;; To try it out, click "Load into REPL" and type into the repl:
;; (hello-world.set-message "universe")
;; (hello-world.greet)
;;
;; Check lines 21 and 34 to play with Formal Verification
;;
;; 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"
; uncomment the following to make the model happy!
; (enforce (!= m "") "set-message: must not be empty")
(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