check-trusted? | (fn [subject action object] (cond (empty? *scope*) (#9/trust/trusted? #9/root-controller %0 %1 %2) (let [[& ps pname] *scope* cont (get-in #9/cns-database (vector %3 %4 1)) ] (#9/trust/trusted? %5 %0 %1 %2)))) | nil |
-check | (fn [sym] (cond (symbol? %0) (split (name %0) \.) (fail :ARGUMENT "CNS name must be a Symbol"))) | nil |
update | (fn [sym value] (cond (#9/read %0) (let [rec *result* ] (apply #9/create %0 (assoc %2 0 %1))) (fail :STATE (str "CNS record to update does not exist: " %0)))) | "Updates a CNS entry with given value. Record must already exist." |
change-control | (fn [controller] (let [path *scope* ] (cond (not (#9/trust/trusted? (get #9/cns-owners %1) *caller* :control)) (fail :TRUST "Forbidden to change CNS node controller") nil) (def cns-owners (assoc-in #9/cns-owners (vector %1) %0)))) | "Changes controller for a CNS node. May only be performed by a current controller." |
root-controller | #6 | nil |
resolve | (fn [sym] (get (#9/read %0) 0)) | "Resolves a CNS entry. Returns nil if entry does not exist" |
cns-write | (fn [pname values] (do (cond (str? %0) *result* (fail :ARGUMENT "CNS path element must be a String")) (#9/-check-values %1) (let [sm (get #9/cns-database *scope*) ] (cond %2 *result* (#9/error :STATE "CNS Node key not valid")) (cond (get %2 %0) (let [rec *result* ] (cond (#9/trust/trusted? (get %3 1) *caller* :update) *result* (fail :TRUST "Forbidden to update CNS record"))) (cond (#9/trust/trusted? (#9/-controller *scope*) *caller* :create %0) *result* (fail :TRUST "Forbidden to create CNS record"))) (def cns-database (assoc-in #9/cns-database (vector *scope* %0) %1)) %1))) | "Writes a CNS record from this Actor. Assumes a path vector passed in *scope*." |
create | (fn ([sym & vals] (let [nv (count %1) _ (cond (> %2 4) (fail :ARITY "Too many CNS record values")) path (#9/-check %0) n (count %3) ] (cond (zero? %4) (fail :ARGUMENT "CNS path must have at least one segment")) (loop [i 0 ref #9/root ] (let [pname (get %3 %5) ] (cond (nil? %6) (fail :STATE (str "No CNS child path at: " (slice %3 0 %5))) (>= (inc %5) %4) (let [rec (cond (< %2 4) (let [evs (call* %6 0 cns-read %7) evs (cond %8 *result* (vector nil *address* nil nil)) ] (concat %1 (slice %9 %2 4))) %1) ] (call* %6 0 cns-write %7 %8)) (let [rec (call* %6 0 cns-read %7) ] (cond (get %8 3) (let [child *result* ] (recur (inc %5) %9)) (let [cont (cond (get %1 1) *result* *address*) nref (call* %6 0 cns-create-node %7 %9) rec (cond %8 (assoc %8 3 %10) (vector nil %9 nil %10)) ] (call* %6 0 cns-write %7 %11) (recur (inc %5) %10)))))))))) | "Creates a CNS entry with given data [value, controller, metadata, child]" |
cns-owners | {["convex" "trust"] #6,["currency"] #6,["torus"] #6,["asset" "wrap"] #6,["asset"] #6,["asset" "box"] #6,["convex"] #6,["asset" "nft"] #6,[] #6} | nil |
root | [#9 []] | nil |
cns-create-node | (fn [pname owner] (do (cond (#9/trust/trusted? (get #9/cns-owners *scope*) *caller* :create %0) *result* (fail :TRUST "Forbidden to create CNS node")) (let [rec (get-in #9/cns-database (vector *scope* %0)) _ (cond (get %2 3) (let [existing *result* ] (return %3))) path (conj *scope* %0) ref (vector #9 %3) ] (def cns-owners (assoc-in #9/cns-owners (vector %3) %1)) (def cns-database (assoc-in #9/cns-database (vector %3) {})) %4))) | "Creates a child CNS node, if it does not yet exist. Returns child node scoped reference." |
cns-database | {["convex" "trust"] {"whitelist" [#75 #6 nil nil],"delegate" [#74 #6 nil nil],"monitors" [#76 #6 nil nil],"ownership-monitor" [#73 #6 nil nil]},["currency"] {"GBPF" [#130 #6 nil nil],"USDF" [#128 #6 nil nil]},["torus"] {"exchange" [#66 #6 nil nil]},["asset" "wrap"] {"convex" [#72 #6 nil nil]},["asset"] {"wrap" [nil #6 nil [#9 ["asset" "wrap"]]],"nft" [nil #6 nil [#9 ["asset" "nft"]]],"box" [#70 #6 nil [#9 ["asset" "box"]]],"multi-token" [#71 #6 nil nil]},["asset" "box"] {"actor" [#69 #6 nil nil]},["convex"] {"core" [#8 #6 nil nil],"trust" [#10 #6 nil [#9 ["convex" "trust"]]],"fungible" [#64 #6 nil nil],"registry" [#9 #6 nil nil],"asset" [#65 #6 nil nil],"governance" [#77 #6 nil nil],"cns" [#9 #6 nil [#9 []]]},["asset" "nft"] {"simple" [#67 #6 nil nil],"basic" [#68 #6 nil nil]},[] {"currency" [nil #6 nil [#9 ["currency"]]],"torus" [nil #6 nil [#9 ["torus"]]],"asset" [nil #6 nil [#9 ["asset"]]],"init" [#1 #1 nil nil],"convex" [nil #6 nil [#9 ["convex"]]]}} | nil |
cns-read | (fn [pname] (get-in #9/cns-database (vector *scope* %0))) | "Reads a child CNS record from this CNS node. Assumes a path vector passed in *scope*." |
cns-delete-node | (fn [pname owner] (do (cond (#9/trust/trusted? (get #9/cns-owners *scope*) *caller* :delete %0) *result* (fail :TRUST "Forbidden to delete CNS node")) (let [path (conj *scope* %0) existing (get #9/cns-database %2) ] (cond %3 (do (def cns-owners (dissoc #9/cns-owners %2)) (def cns-database (dissoc #9/cns-database %2))) nil) (def cns-database (#8/dissoc-in #9/cns-database (vector *scope* %0))) (boolean %3)))) | "Deletes a child CNS node. Returns true if deleted" |
trust | #10 | nil |
lookup | (fn [addr] (get-holding (address %0))) | "Looks up registry metadata for a given address." |
-controller | (fn [path] (cond (empty? %0) (cond (vector? %0) #9/root-controller (fail :ARGMENT "CNS path must be a vector")) (let [[& ps p] %0 ] (get-in #9/cns-database (vector %1 %2 1))))) | nil |
read | (fn [sym] (query (let [path (#9/-check %0) n (count %1) ] (loop [i 0 ref #9/root ] (let [pname (nth %1 %3) rec (call* %4 0 cns-read %5) ] (cond (nil? %6) (return nil) (>= (inc %3) %2) (return %6) (cond (nth %6 3) (let [child *result* ] (recur (inc %3) %7))))))))) | "Reads a CNS record as a [value controller metadata child] vector, or nil if record does not exist." |
-check-values | (fn [values] (cond (vector? %0) (cond (= 4 (count %0)) %0 (fail :ARGUMENT "CNS record must have 4 elements")) (fail :ARGUMENT "CNS record must be a Vector"))) | nil |
register | (fn [data] (set-holding *caller* %0)) | "Registers metadata for the *caller* account. Metadata can be an arbitrary value, but by convention is a map with defined fields." |
control | (fn [sym cont] (cond (#9/read %0) (let [rec *result* ] (apply #9/create %0 (assoc %2 1 %1))) (fail :STATE "CNS record does not exist"))) | "Change controller for a CNS node." |