Created
May 21, 2018 18:16
-
-
Save joelburget/bb53420695aeb57aedff9ff6dee9763c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 | |
})) | |
)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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