Spread new convention "?", "!" and "is-"

This commit is contained in:
Ludovic Galabru
2019-11-19 17:27:52 -05:00
parent 62b8585426
commit 085dcf344b
18 changed files with 493 additions and 493 deletions

View File

@@ -11,9 +11,9 @@
(define-public (preorder
(name-hash (buff 20))
(name-price uint))
(if (is-ok? (contract-call! .tokens token-transfer
(if (is-ok (contract-call? .tokens token-transfer
burn-address name-price))
(begin (map-insert! preorder-map
(begin (map-insert preorder-map
(tuple (name-hash name-hash))
(tuple (paid name-price)
(buyer tx-sender)))
@@ -26,25 +26,25 @@
(salt uint))
(let ((preorder-entry
(expects! ;; name _must_ have been preordered.
(map-get preorder-map
(map-get? preorder-map
(tuple (name-hash (hash160 (xor name salt)))))
(err "no preorder found")))
(name-entry
(map-get name-map (tuple (name name)))))
(map-get? name-map (tuple (name name)))))
(if (and
;; name shouldn't *already* exist
(is-none? name-entry)
(is-none name-entry)
;; preorder must have paid enough
(<= (price-function name)
(get paid preorder-entry))
;; preorder must have been the current principal
(eq? tx-sender
(is-eq tx-sender
(get buyer preorder-entry)))
(if (and
(map-insert! name-map
(map-insert name-map
(tuple (name name))
(tuple (owner recipient-principal)))
(map-delete! preorder-map
(map-delete preorder-map
(tuple (name-hash (hash160 (xor name salt))))))
(ok u0)
(err "failed to insert new name entry"))

View File

@@ -1,13 +1,13 @@
(define-map tokens ((account principal)) ((balance uint)))
(define-private (get-balance (account principal))
(default-to u0 (get balance (map-get tokens (tuple (account account))))))
(default-to u0 (get balance (map-get? tokens (tuple (account account))))))
(define-private (token-credit! (account principal) (amount uint))
(if (<= amount u0)
(err "must move positive balance")
(let ((current-amount (get-balance account)))
(begin
(map-set! tokens (tuple (account account))
(map-set tokens (tuple (account account))
(tuple (balance (+ amount current-amount))))
(ok amount)))))
@@ -16,7 +16,7 @@
(if (or (> amount balance) (<= amount u0))
(err "must transfer positive balance and possess funds")
(begin
(map-set! tokens (tuple (account tx-sender))
(map-set tokens (tuple (account tx-sender))
(tuple (balance (- balance amount))))
(token-credit! to amount)))))