A peer-to-peer stack for code collaboration
UUIDs are just used as nonces and other improvements.
James Henri Haydonb57868428ee5
diff --git a/docs/source/reference.rst b/docs/source/reference.rstindex 1652ab5..03991c8 100644--- a/docs/source/reference.rst+++ b/docs/source/reference.rst@@ -358,6 +358,7 @@ is empty, in which case an exception is thrown.Given a sequence ``xs`` and a function ``f``, returns a sequence withthe same elements ``x`` of ``xs`` but sorted according to ``(f x)``.+<<<<<<< HEAD``zip``~~~~~~~@@ -365,6 +366,8 @@ Takes two sequences and returns a sequence of corresponding pairs. Inone sequence is shorter than the other, the excess elements of thelonger sequence are discarded.+=======+>>>>>>> UUIDs are just used as nonces and other improvements.Dicts-----@@ -942,6 +945,7 @@ functions before sending these to a remote chain.Return an empty chain dictionary with the given url.+<<<<<<< HEAD``(@var ident)``~~~~~~~~~~~~~~~~@@ -949,6 +953,15 @@ A lens for variables in states of chains.``(eval-in-chain expr chain)``~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+=======+``@var``+~~~~~~~~++A lens for variables in states of chains.++``eval-in-chain``+~~~~~~~~~~~~~~~~~+>>>>>>> UUIDs are just used as nonces and other improvements.Evaluates 'expr' in the 'chain' and returns a dict with the ':result'and the resulting ':chain'.@@ -1042,4 +1055,4 @@ the next state.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Update a ref containing a chain with the new expressions from the remote-chain\ No newline at end of file+chaindiff --git a/rad/monadic/issue-remote.rad b/rad/monadic/issue-remote.radindex d251379..a4add26 100644--- a/rad/monadic/issue-remote.rad+++ b/rad/monadic/issue-remote.rad@@ -6,24 +6,26 @@"monadic/radicle/issues")(def issues- "Issues are stored in a dict in a ref."+ "Issues are stored in a dict in a ref, keyed by issue-number."(ref {}))-(def issue-counter (lookup :next (make-counter)))+(def issue-counter+ "We use a stateful counter for giving issues numbers."+ (lookup :next (make-counter)))-(def used-ids- "We keep track of the UUIDs which have been used in the chain."+(def used-nonces+ "We keep track of the UUIDs which have been used as nonces in inputs."(ref set/empty))-(def id-free?- "Check that an ID has not been used yet."- (fn [id]- (not (set/member? id (read-ref used-ids)))))+(def unused-nonce?+ "Check that a nonce has not been used already."+ (fn [nonce]+ (not (set/member? nonce (read-ref used-nonces)))))-(def mark-used-id+(def mark-used-nonce"Mark a UUID as used."- (fn [id]- (modify-ref used-ids (fn [s] (set/insert id s)))))+ (fn [nonce]+ (modify-ref used-nonces (fn [s] (set/insert nonce s)))))(def set-issues"A helper to set stuff in the issues ref."@@ -35,13 +37,14 @@(fn [l f](over-ref issues l f)))-(def validator/free-uuid- "Given a predicate which says if an ID is free, checks input is a free UUID."+(def validator/nonce+ "Validator for unused nonces."(validator/and[validator/uuid- (validator/pred "ID is free" id-free?)]))+ (validator/pred "Nonce not already used" unused-nonce?)]))(def validator/text+ "A validator for text."(fn [max-len](validator/and[(validator/type :string)@@ -52,73 +55,79 @@(def validator/timestamp(validator/type :string))-(def validator/entity- "Checks that the input as a valid new *chain entity*, that is, it has an unused- UUID, is marked with this chain name, and is signed."+(def validator/input+ "Checks that the input as a valid new *chain input*, that is, it has an unused+ nonce, is marked with this chain name, and is signed."(validator/and[(validator/keys- {:id validator/free-uuid+ {:nonce validator/nonce:chain-id (validator/= chain-id);; NOTE that the timestamp is claimed by the author, is not verified, and;; may be incorrect.:created-at validator/timestamp})validator/signed]))-(def strip-entity- "After an entity has been saved to the chain, we no longer need to keep the- chain-id or the signature, since this has already been checked."- (fn [e]- (delete-many [:chain-id :signature] e)))+(def validator/issue-number+ "A validator for numbers which refer to existing issues."+ (validator/pred "Existing issue number" (fn [n] (member? n (read-ref issues)))))(def validator/comment- "Checks a comment is a chain entity which refers to an issue and has a text- body."+ "A comment should have a body."+ (validator/keys+ {:body (validator/text 4000)}))++(def validator/comment-input+ "A comment input should refer to an existing issue."(validator/and- [validator/entity- (validator/keys- {:issue-id validator/uuid- :body (validator/text 4000)})]))+ [validator/input+ validator/comment+ (validator/keys {:issue-number validator/issue-number})]))-(def validator/issue- "Checks an issue a chain entity with a title, body, etc."+(def validator/issue-input+ "An issue should have all the required fields, be a signed input, etc."(validator/and- [validator/entity+ [validator/input(validator/keys- {:title (validator/text 100)- :body (validator/text 4000)- :labels (validator/every (validator/text 80))- :state (validator/member [:open :closed])- :comments (validator/every validator/comment)})]))--(def strip-comment- (fn [c]- (delete :issue-id (strip-entity c))))+ {:title (validator/text 100)+ :body (validator/text 4000)+ :labels (validator/every (validator/text 80))+ :state (validator/member [:open :closed])+ :comments (validator/every validator/comment)})]))++(def strip-input+ "After an entity input has been processed/verified, we no longer need some of+ the fields."+ (fn [e]+ (delete-many [:chain-id :signature :nonce :issue-number] e)))(def create-issue"Create an issue from a dict, checking it is valid and storing it in `issues`."(fn [i]- (def id (lookup :id i))- (validator/issue i)+ (validator/issue-input i)+ (def n (issue-counter))(def i_- (strip-entity+ (strip-input(<> i- {:number (issue-counter)- :comments (map strip-comment (lookup :comments i))})))- (set-issues (@ id) i_)- (mark-used-id id)))+ {:number n+ :comments (map strip-input (lookup :comments i))})))+ (set-issues (@ n) i_)+ (mark-used-nonce (lookup :nonce i))))(def close-issue- "Set the state of an issue to `:closed`."- (fn [id]- (set-issues (.. (@ id) (@ :state)) :closed)))+ "Given an issue number, sets the state of the issue to `:closed`."+ (fn [n]+ (validator/issue-number n)+ (set-issues (.. (@ n) (@ :state)) :closed)))(def add-comment"Add a comment to an issue."(fn [c]- (def id (lookup :id c))- (validator/comment c)- (mod-issues (.. (@ id) (@ :comments)) (fn [cs] (add-right (strip-comment c) cs)))- (mark-used-id id)))+ (validator/comment-input c)+ (def c_ (strip-input c))+ (over-issues+ (.. (@ (lookup :issue-number c)) (@ :comments))+ (fn [cs] (add-right c_ cs)))+ (mark-used-nonce (lookup :nonce c))));; These are intended for clients to run locally with eval-in-chaindiff --git a/rad/monadic/issues.rad b/rad/monadic/issues.radindex 6def03e..130330f 100644--- a/rad/monadic/issues.rad+++ b/rad/monadic/issues.rad@@ -16,61 +16,77 @@(fn [](def url (lookup :url (read-ref issues-chain)))(send-prelude! url)- (send-code! url "rad/chains/issue-remote.rad")))+ (send-code! url "rad/monadic/issue-remote.rad")))(def sign-entity!- "Assumes a key pair is stored at `my-keys.rad`. Using that key pair, will sign- an entity (a dict) by adding `:author` and `:signature` fields, so that it is- valid according to `validator/signed`."+ "Assumes a key pair is stored at `my-keys.rad`. Using that key pair, will sign a+ dict by adding `:author` and `:signature` fields, so that it is valid+ according to `validator/signed`, while also adding a `:nonce`."(fn [e]+ (def nonce (uuid!))+ (def e_ (<> e {:chain-id radicle-issues-chain-id+ :nonce nonce}))(def ks (read (read-file! "my-keys.rad")))- (def sig (gen-signature! (lookup :private-key ks) (show (insert :chain-id radicle-issues-chain-id e))))- (<> e+ (def sig+ (gen-signature! (lookup :private-key ks)+ (show e_)))+ (<> e_{:author (lookup :public-key ks)- :signature sig- :chain-id radicle-issues-chain-id})))+ :signature sig})))(def simple-issue+ "Create an open issue with no comments or labels."(fn [tit bod]- {:title tit- :body bod- :labels []- :state :open- :comments []+ {:title tit+ :body bod+ :labels []+ :state :open+ :comments []+ :created-at (now!)}))++(def simple-comment+ "Create a comment for an issue."+ (fn [issue-number bod]+ {:body bod+ :issue-number issue-number:created-at (now!)}))(def create-issue!- "Create a new remote issue. Signs the issue and all it's comments with the key- stored `my-keys.rad`."+ "Create a new remote issue with the keys in `my-keys.rad`."(fn [i]- (def issue-id (uuid!))- (def comment-entities- (map (fn [c]- (sign-entity! (<> c {:id (uuid!)- :issue-id issue-id})))- (lookup :comments i)))- (def e- (sign-entity!- (<> i {:id issue-id- :comments comment-entities})))(send! (lookup :url (read-ref issues-chain))- [(list 'create-issue e)])- ))+ [(list 'create-issue (sign-entity! i))])))++(def add-comment!+ "Create a remote comment with the keys in `my-keys.rad`."+ (fn [c]+ (send! (lookup :url (read-ref issues-chain))+ [(list 'add-comment (sign-entity! c))])))(def simple-create-issue!- (fn [tit bod]- (create-issue! (simple-issue tit bod))))+ "Create a remote issue with sensible defaults."+ (fn [tit bod]+ (create-issue! (simple-issue tit bod))))++(def simple-add-comment!+ "Create a remote comment."+ (fn [in b]+ (add-comment! (simple-comment in b))))(def list-issues- "Given an issues ref `x`, returns its issues. Does not itself update the chain."+ "Return the full map of issues."(fn [](lookup :result (eval-in-chain '(list-issues) (read-ref issues-chain)))))(def fetch+ "Update the locally cached state of the chain."(fn [](update-chain-ref issues-chain)))(def import-github+ "Imports the github issues stored in file `githubissues.rad`. To create this+ file use the `radicle-github-issues` executable. Will add a note to all+ `:body`s that this is an imported entity."(fn [](def note-imported(fn [x]@@ -89,31 +105,28 @@(map(fn [i] (note-imported (note-comments i)))issues))- (map create-issue! imported)- ))+ (map create-issue! imported)))(def short+ "Short render of an issue."(fn [i](string-append(show (lookup :number i))": "- (lookup :id i)- " - "(lookup :title i))))(def list-last"Get the last `n` issues."(fn [n](def is (sort-by (fn [i] (- 0 (lookup :number i))) (values (list-issues))))- (take n is)- ))+ (take n is)))(def get-by-id(fn [id](lookup id (list-issues))))(:test- "creating, manipulating and querying issue chains"+ "creating, manipulating and querying the issue chain"[:setup(do(def pk (gen-key-pair! (default-ecc-curve)))diff --git a/rad/prelude.rad b/rad/prelude.radindex 36fb0a1..0115e37 100644--- a/rad/prelude.rad+++ b/rad/prelude.rad@@ -63,4 +63,4 @@(fn []"radicle is a LISP-like language intended for programming chains, and interacting with those chains.- Type (doc '<name>) for further documentation of <name>."))+ Type (doc '<name>) for further documentation of <name>."))\ No newline at end of filediff --git a/test/spec/Radicle/Internal/TestCapabilities.hs b/test/spec/Radicle/Internal/TestCapabilities.hsindex a29f959..ac496be 100644--- a/test/spec/Radicle/Internal/TestCapabilities.hs+++ b/test/spec/Radicle/Internal/TestCapabilities.hs@@ -10,6 +10,7 @@ import qualified Data.Sequence as Seqimport qualified Data.Time as Timeimport GHC.Exts (fromList)import qualified System.FilePath.Find as FP+import qualified Data.Time as Timeimport Radicleimport Radicle.Internal.Core (addBinding)