diff --git a/convex-core/src/main/cvx/convex/asset.cvx b/convex-core/src/main/cvx/convex/asset.cvx index f5870af70..0a863919d 100644 --- a/convex-core/src/main/cvx/convex/asset.cvx +++ b/convex-core/src/main/cvx/convex/asset.cvx @@ -21,8 +21,8 @@ "For more information, see those functions defined in this library whose purpose is to delegate to asset implementations in a generic way."] :name "Convex Asset API library"})) -;;;;;;;;;; Forward declarations -(declare balance transfer) +;;;;;;;;;; Forward declarations +(declare balance transfer) ;;;;;;;;;; Private @@ -41,7 +41,7 @@ ^{:doc {:description ["Accepts asset from sender." "If asset contains multiple assets, accepts each in turn. MUST fail if the asset cannot be accepted."] :examples [{:code "(accept sender [fungible-token-address 1000])"}] - :signature [{:params [sender asset]} + :signature [{:params [sender asset]} {:params [sender asset-path quantity]}] :errors {:STATE "If there is no sufficient offer to accept." :FUNDS "If sender has insufficient balance."}}} @@ -59,14 +59,14 @@ path (accept sender path quantity))) {} - asset) - - ;; a nil quantity can always be accepted - (nil? asset) nil - - (fail "Bad asset argument"))) - - ([sender path quantity] + asset) + + ;; a nil quantity can always be accepted + (nil? asset) nil + + (fail "Bad asset argument"))) + + ([sender path quantity] (call path (accept sender quantity)))) @@ -102,7 +102,7 @@ "May result in an error if the asset does not support open offers."] :examples [{:code "(offer receiver [fungible-token-address 1000])"} {:code "(offer receiver non-fungible-token-address #{1 4 6})"}] - :signature [{:params [receiver asset]} + :signature [{:params [receiver asset]} {:params [receiver asset-path quantity]}]}} ([receiver asset] @@ -116,9 +116,9 @@ (reduce (fn [m [path quantity]] (assoc m path (offer receiver path quantity))) {} - asset))) - - ([receiver path quantity] + asset))) + + ([receiver path quantity] (call path (offer receiver quantity)))) @@ -132,9 +132,9 @@ ([receiver asset] (cond (vector? asset) - (let [[path quantity] asset] - (recur receiver path quantity nil)) - + (let [[path quantity] asset] + (recur receiver path quantity nil)) + (map? asset) (reduce (fn [m [path quantity]] (assoc m @@ -146,21 +146,21 @@ :else (fail "Invalid asset"))) - ([receiver path quantity] - (recur receiver path quantity nil)) + ([receiver path quantity] + (recur receiver path quantity nil)) ([receiver path quantity data] - (cond - ;; First check if receiver has a callable receive-asset function. If so, use this - (callable? receiver 'receive-asset) + (cond + ;; First check if receiver has a callable receive-asset function. If so, use this + (callable? receiver 'receive-asset) (do (offer receiver path quantity) ;; Offer correct quantity - (call receiver - (receive-asset path quantity data))) - - ;; An actor without a receive-asset function is not a valid receiver? - (actor? receiver) (fail :STATE "Target Actor does not have receive-asset function") - + (call receiver + (receive-asset path quantity data))) + + ;; An actor without a receive-asset function is not a valid receiver? + (actor? receiver) (fail :STATE "Target Actor does not have receive-asset function") + (call path (direct-transfer receiver quantity))))) @@ -183,7 +183,7 @@ (defn balance ^{:doc {:description ["Returns asset balance for a specified owner, or for the current address if not supplied." "Return value will be in the quantity format as specified by the asset type."] - :examples [{:code "(balance asset-address)"} + :examples [{:code "(balance asset-address)"} {:code "(balance [asset-address asset-id] owner)"}] :signature [{:params [asset-path]} {:params [asset-path owner]}]}} @@ -191,9 +191,9 @@ (recur path *address*)) ([path owner] - (query ;; external call, so use query to avoid re-entrant secuity risks - (call path (balance owner))))) - + (query ;; external call, so use query to avoid re-entrant secuity risks + (call path (balance owner))))) + (defn burn ^{:doc {:description "Burns a quantity of the given asset, if allowed by the implementation. Amount must be a valid quantity owned by the user." :examples [{:code "(burn [my-token-address :FOO] 1000)"}] @@ -240,11 +240,11 @@ ;; Interpret nil as the 'zero' asset, which everybody owns (nil? asset) - true) - - ([owner path quantity] - (query ;; query because this is an external call - (let [bal (balance path owner)] + true) + + ([owner path quantity] + (query ;; query because this is an external call + (let [bal (balance path owner)] (call path (quantity-subset? quantity bal))))))