-set-balance | (fn [addr id bal] (let [h (get-holding %0) orec (get %3 %1) rec (cond %4 (assoc %4 0 %2) (vector %2 nil)) ] (set-holding %0 (assoc %3 %1 %5)))) | nil |
mint | (fn [amount] (let [id *scope* token (cond (get #71/tokens %1) *result* (fail :STATE "token does not exist")) [controller supply] %2 ] (cond (#10/trusted? %3 *caller* :mint %0) nil (fail :TRUST "No rights to mint")) (let [amount (#71/-qc %0) new-supply (+ %4 %5) bal (#71/-get-balance *caller* %1) new-bal (+ %7 %5) ] (cond (<= 0 %6) nil (fail :ASSERT "Assert failed: (<= 0 new-supply)")) (cond (<= 0 %8) nil (fail :ASSERT "Assert failed: (<= 0 new-bal)")) (#71/-set-balance *caller* %1 %8) (do (def tokens (assoc #71/tokens %1 (vector %3 %6))) %6)))) | nil |
tokens | {} | nil |
change-control | (fn [controller] (do (cond (callable? %0) *result* (fail :ARGUMENT "controller must be a callable value")) (let [trec (cond (get #71/tokens *scope*) *result* (fail :TRUST "Not allowed to update controller")) cont (nth %1 0) _ (cond (#10/trusted? %2 *caller* :control *scope*) *result* (fail :TRUST "Not allowed to update controller")) nrec (assoc %1 0 %0) ] (def tokens (assoc #71/tokens *scope* %3))))) | nil |
create | (fn ([id] (do (cond (keyword? %0) *result* (fail "Token ID must be a keyword")) (cond (contains-key? #71/tokens %0) (fail "Token already exists!")) (def tokens (assoc #71/tokens %0 (vector *caller* 0))) %0))) | "Creates a new token and returns its id. Caller will be controller of token. Returns ID." |
decimals | (fn ([] (get (get #71/tokens *scope*) 2 0))) | nil |
total-supply | (fn ([] (get-in #71/tokens (vector *scope* 1)))) | nil |
quantity-add | (fn [a b] (let [a (cond %0 (int %0) 0) b (cond %1 (int %1) 0) ] (+ %2 %3))) | nil |
asset-lib | #65 | nil |
balance | (fn ([addr] (let [hs (get-holding %0) rec (get %1 *scope*) ] (cond %2 (nth %2 0) 0)))) | nil |
direct-transfer | (fn [addr amount data] (let [addr (address %0) amount (#71/-qc %1) id *scope* bal (#71/-get-balance *caller* %5) tbal (#71/-get-balance %3 %5) ] (cond (< %4 0) (fail :ARGUMENT "negative transfer")) (cond (> %4 %6) (fail :FUNDS "insufficent token balance")) (cond (= *caller* %3) (do (log "TR" %3 %3 %4 %6 %6 %2) (return %4)) nil) (let [nsb (- %6 %4) nrb (+ %7 %4) ] (log "TR" *caller* %3 %4 %8 %9 %2) (#71/-set-balance *caller* %5 %8) (#71/-set-balance %3 %5 %9)))) | nil |
quantity-subset? | (fn [a b] (let [a (cond %0 (int %0) 0) b (cond %1 (int %1) 0) ] (<= %2 %3))) | nil |
offer | (fn [receiver quantity] (let [id *scope* quantity (#71/-qc %1) receiver (address %0) hs (get-holding *caller*) rec (get %5 %2) ] (cond %6 (let [os (nth %6 1) nrec (cond (<= %3 0) (assoc %6 1 (dissoc %7 %4)) (assoc %6 1 (assoc %7 %4 %3))) ] (set-holding *caller* (assoc %5 %2 %8))) (do (cond (get #71/tokens %2) *result* (fail :STATE "token does not exist")) (set-holding *caller* (hash-map %2 (vector 0 (hash-map %4 %3)))))) %3)) | nil |
-get-balance | (fn [addr id] (let [h (get-holding %0) rec (get %2 %1) ] (cond %3 (nth %3 0) 0))) | nil |
trust | #10 | nil |
get-offer | (fn [sender receiver] (let [id *scope* rec (cond (get (get-holding %0) %2) *result* (return 0)) ] (cond (get (nth %3 1) %1) *result* 0))) | nil |
-qc | (fn [q] (cond (int? %0) %0 (nil? %0) 0 (fail :ARGUMENT "Invalid token quantity"))) | "Checks a token quantity." |
quantity-sub | (fn [a b] (let [a (cond %0 (int %0) 0) b (cond %1 (int %1) 0) ] (cond (>= %2 %3) (- %2 %3) 0))) | nil |
accept | (fn [sender quantity] (let [id *scope* quantity (#71/-qc %1) _ (cond (zero? %3) (return 0) (< %3 0) (fail :ARGUMENT "Negative accept amount")) receiver *caller* hs (get-holding %0) rec (get %5 %2) ] (cond %6 (let [os (nth %6 1) off (cond (get %7 %4) *result* (fail :STATE "No offer to receiver")) _ (cond (< %8 %3) (fail :STATE "insufficient offer")) bal (nth %6 0) nbal (- %9 %3) _ (cond (< %10 0) (fail :FUNDS "insufficent balance to accept")) noff (- %8 %3) nos (cond (<= %11 0) (dissoc %7 %4) (assoc %7 %4 %11)) nrec (vector %10 %12) ] (set-holding %0 (assoc %5 %2 %13)) (#71/-set-balance %4 %2 (+ (#71/-get-balance %4 %2) %3)) %3) (fail "No offers from sender")))) | nil |