forked from julia-social/julia_did_chialisp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoin_control.clsp
More file actions
74 lines (65 loc) · 2.83 KB
/
Copy pathcoin_control.clsp
File metadata and controls
74 lines (65 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
;; Copyright 2026 Julia.Social, Inc.
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
(mod (curried-args solution)
(include *standard-cl-26*)
(defun print (l x) (i (all "$print$" l x) x x))
(include "condition_codes.clib")
(include "sha256tree.clib")
; This module sends a message to another coin with a message. If the other
; coin has p2_JDID or p2_claim as its inner puzzle, the message will be the
; treehash of the conditions that coin should emit. We do not check the type
; of the receiving coin.
(embed-file did-doc-announce-puzzlehash bin "DIDdoc_announce.clsp.hash.bin")
(embed-file invalidate-puzzlehash bin "invalidate.clsp.hash.bin")
(embed-file pass-thru-puzzlehash bin "pass_thru.clsp.hash.bin")
(embed-file present-claims-puzzlehash bin "present_claims.clsp.hash.bin")
(embed-file present-delegated-puzzlehash bin "present_delegated.clsp.hash.bin")
(defun-inline construct-message (message coin-id)
(list SEND_MESSAGE 0x17 (concat "JDIDP" message) coin-id) ; mode 0x17 = 00010111b = sender puzzle, receiver coin id
)
; validates child puzzle hash is in the allowed set before executing
(defun select-child (curried-args child-hash solution)
(if (if (= child-hash did-doc-announce-puzzlehash) 1
(if (= child-hash invalidate-puzzlehash) 1
(if (= child-hash pass-thru-puzzlehash) 1
(if (= child-hash present-claims-puzzlehash) 1
(= child-hash present-delegated-puzzlehash)))))
(a (f solution) (list curried-args (r solution)))
(x 110)
)
)
; recursively emits coin-control SEND_MESSAGE conditions, then delegates to child puzzle
(defun construct-output (curried-args count solution)
(if (> count 0)
; emit more coin-control messages
(assign
child-output (construct-output curried-args (- count 1) (r (r solution)))
(list (f child-output)
(c (construct-message (f solution) (f (r solution))) (f (r child-output))))
)
; if we're done with coin-control messages, run the subpuzzle
(if (l solution)
(select-child curried-args (sha256tree (f solution)) solution)
(list curried-args ())
)
)
)
; solution format:
; count
; pairs of:
; message
; coin-id
; optional child-puzzle followed by its solution
(construct-output curried-args (f solution) (r solution))
)