Skip to content

Instantly share code, notes, and snippets.

@joelburget
Created May 21, 2018 18:16
Show Gist options
  • Save joelburget/bb53420695aeb57aedff9ff6dee9763c to your computer and use it in GitHub Desktop.
Save joelburget/bb53420695aeb57aedff9ff6dee9763c to your computer and use it in GitHub Desktop.
(enforce-pact-version "2.3")
(define-keyset 'central-bank-admin-keyset
(read-keyset "central-bank-admin-keyset"))
(module central-bank-module 'central-bank-admin-keyset
"central bank"
(defschema central-bank-schema
("central bank"
(invariants
[ (= 1000000 (+ reserve circulation))
(>= reserve 0)
(>= circulation 0)
]))
reserve:integer
circulation:integer)
(deftable central-bank-table:{central-bank-schema})
(defun issue (amt:integer)
"Issue some amount of currency"
(let*
((before (read central-bank-table "singleton"))
(new-reserve (- (at 'reserve before) amt))
(new-circulation (+ (at 'circulation before) amt))
)
(enforce (> amt 0) "")
(enforce (>= new-reserve 0) "")
(update central-bank-table "singleton" {
'reserve: new-reserve,
'circulation: new-circulation
}))
))
(env-keys ["centralbankadmin" "user123" "user456"])
(env-data { "central-bank-admin-keyset": ["centralbankadmin"] })
(begin-tx)
(load "test.pact")
(commit-tx)
(verify 'central-bank-module)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment