Skip to content

Instantly share code, notes, and snippets.

@LindaOrtega
Created June 3, 2019 15:46
Show Gist options
  • Save LindaOrtega/14af8bf4dfd111b138736dd46d2a7e59 to your computer and use it in GitHub Desktop.
Save LindaOrtega/14af8bf4dfd111b138736dd46d2a7e59 to your computer and use it in GitHub Desktop.
Bug when try to "Load into REPL"
(define-keyset "test-keyset" (read-keyset "test-keyset"))
(module acct-module "test-keyset"
@doc "account schema module"
(defschema account
@model [(invariant (>= balance 0))]
balance:integer
ks:keyset
)
(deftable accounts:{account})
)
(interface coin-sig
"Example Coin Contract"
(use acct-module)
(defun transfer (from:string to:string amount:integer)
@doc "Transfer money between accounts"
@model [(property (row-enforced accounts "ks" from))
(property (> amount 0))
;;(property (= 0 (column-delta accounts "balance")))
;;(property (<= 0 (cell-delta accounts "balance" from)))
(property (!= from to)) ]
)
)
(module test-impl "test-keyset"
@doc "test if implementing test-sig resolves schema type"
(use acct-module)
(implements coin-sig)
(defun transfer (from:string to:string amount:integer)
(with-read accounts from { 'balance := from-bal, 'ks := from-ks }
(with-read accounts to { 'balance := to-bal }
(enforce-keyset from-ks)
(enforce (>= from-bal amount) "Insufficient Funds")
(enforce (> amount 0) "Non-positive amount")
(enforce (!= from to) "Sender is the recipient")
(update accounts from { "balance": (- 0 amount) })
(update accounts to { "balance": (+ to-bal amount) }))))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment