Skip to content

Instantly share code, notes, and snippets.

@mightybyte
Last active March 15, 2019 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mightybyte/c94200f4ba62067763111417d6e3e851 to your computer and use it in GitHub Desktop.
Save mightybyte/c94200f4ba62067763111417d6e3e851 to your computer and use it in GitHub Desktop.
Pact shared with pact-web.
;;---------------------------------
;; Doug demo testZZZ
;; Create a keyset named 'keyset' and add some key,
;; for loading this contract!
;;
;; Make sure the message is signed with this added key as well.
;;---------------------------------
(define-keyset 'module-keyset (read-keyset "keyset"))
;USD Ledger
(module paymentsUSDDoug 'module-keyset
(deftable payments-tableUSD)
(defun create-accountUSD (id initial-balance)
"Create a new account for ID with INITIAL-BALANCE funds"
(insert payments-tableUSD id { "balance": initial-balance }))
(defun debitUSD (from amount)
(with-read payments-tableUSD from { "balance":= from-bal }
(enforce (>= from-bal amount) "Insufficient Funds")
(update payments-tableUSD from
{ "balance": (- from-bal amount) })
(format "{} debited {}" [from amount])))
)
;create USD Ledger table
(create-table payments-tableUSD)
(create-accountUSD "Sarah" 100.00)
;JPY Ledger
(module paymentsJPY 'module-keyset
(deftable payments-tableJPY)
(defun create-accountJPY (id initial-balance)
"Create a new account for ID with INITIAL-BALANCE funds"
(insert payments-tableJPY id { "balance": initial-balance }))
(defun creditJPY (to amount)
(with-read payments-tableJPY to { "balance":= to-bal }
(update payments-tableJPY to
{ "balance": (+ to-bal amount) })
(format "{} credited {}" [to amount])))
)
;create JPY Ledger
(create-table payments-tableJPY)
(create-accountJPY "James" 0.0)
;Cross Border Transfer Specification
(module cross-border 'module-keyset
(defun transfer-usd-to-jpy-accts (from to amountUSD fx-rate)
(let* ((amountJPY (* amountUSD fx-rate)))
(debitUSD from amountUSD)
(creditJPY to amountJPY)
(format "{} transfered ${} USD to {} at the rate of {}" [from amountUSD to fx-rate])))
)
;do a transfer
(transfer-usd-to-jpy-accts "Sarah" "James" 50.0 104.57)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment