; lib/artdag/post.sx — project an artdag job to/from a feed "post object", so a job ; can ride as the :object of a feed activity ({:actor :verb :object :at :tags}) per the ; host loop. A post object is content-addressed and self-verifying: ; {:type "artdag/job" :id :wire wire>} ; The :id IS the post/object id (the stable structural digest = natural AP object id); ; the :wire is the self-describing, write/read-safe payload from serialize.sx whose ; records each carry their own content-id. The dag<->feed-activity wrapping (actor/verb/ ; at/tags) stays on the host/feed side; this file is only the job<->object projection. ; Depends on dag.sx + serialize.sx (and execute.sx for post-run). (define artdag/post-type "artdag/job") ; a job = a dag + the output node (by author name) the post is "about". (define artdag/job->post-object (fn (dag output-name) {:id (artdag/dag-id dag output-name) :type artdag/post-type :wire (artdag/dag->wire dag)})) (define artdag/post-object? (fn (x) (and (= (type-of x) "dict") (= (get x :type) artdag/post-type) (has-key? x :id) (has-key? x :wire)))) (define artdag/post-object-id (fn (post) (get post :id))) (define artdag/post-object-wire (fn (post) (get post :wire))) ; integrity: the payload's records each verify (id == recomputed content-id) AND the ; claimed post id is actually produced by the job (present among the wire records). (define artdag/post-object-verify (fn (post) (and (artdag/post-object? post) (artdag/wire-verify (get post :wire)) (artdag/member? (get post :id) (map (fn (rec) (nth rec 0)) (get post :wire)))))) ; decode the payload back into a runnable dag (pure; verify separately, mirroring ; serialize.sx's wire->dag / wire-verify split). (define artdag/post-object->job (fn (post) (artdag/wire->dag (get post :wire)))) ; ---- string transport (drop into a feed activity / SXTP body) ---- (define artdag/job->post-string (fn (dag output-name) (write-to-string (artdag/job->post-object dag output-name)))) (define artdag/post-string->object (fn (s) (read (open-input-string s)))) ; ---- run a received post: decode -> run -> result at the post id ---- ; the peer recomputes the job (content-addressed, so a warm cache hits everything it ; already has). Returns the result of the output node the post is about. (define artdag/post-run (fn (post runner cache) (artdag/result-of (artdag/run (artdag/post-object->job post) runner cache) (artdag/post-object-id post))))