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.

Revisions

  1. mightybyte created this gist Jun 5, 2019.
    40 changes: 40 additions & 0 deletions hello-fv.pact
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    ;;
    ;; "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)