Last active
June 18, 2018 18:07
-
-
Save joelburget/4fdcdd512c3b8f3ce88f60269b586127 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
(update accounts from { "balance": (- from-bal amount) }) | |
(update accounts to { "balance": (+ to-bal amount) }))) | |
;; | |
(update accounts "brian" { "balance": (- previous-balance 1000000) }) | |
(update accounts "brian" { "balance": (+ previous-balance 1000000) }) |
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.4.1") | |
(define-keyset 'accounts-admin-keyset | |
(read-keyset "accounts-admin-keyset")) | |
(module accounts 'accounts-admin-keyset | |
"Demo module" | |
(defschema account | |
("account" | |
(invariant (>= balance 0))) | |
balance:integer | |
ks:keyset) | |
(deftable accounts:{account}) | |
(defun transfer (from:string to:string amount:integer) | |
("Transfer money between accounts" | |
(properties [ | |
(row-enforced 'accounts 'ks from) | |
(= (column-delta 'accounts 'balance) 0) | |
])) | |
(let ((from-bal (at 'balance (read accounts from))) | |
(from-ks (at 'ks (read accounts from))) | |
(to-bal (at 'balance (read accounts to)))) | |
(enforce-keyset from-ks) | |
(enforce (> amount 0)) | |
(enforce (>= from-bal amount) "Insufficient Funds") | |
(enforce (!= to from)) | |
(update accounts from { "balance": (- from-bal amount) }) | |
(update accounts to { "balance": (+ to-bal amount) })))) |
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 ["accountadmin" "user123" "user456"]) | |
(env-data { "accounts-admin-keyset": ["accountadmin"] }) | |
(begin-tx) | |
(load "test.pact") | |
(commit-tx) | |
(verify 'accounts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment