2 (def 'next-record 0x10)
4 ;; Next record position
5 ;; This starts one cell above the maximum value of RipeMD
6 [[next-record]] 0x10000000000000000000000000000000000000000
13 ;; 0 - first cell in message
14 [action] (calldataload 0)
15 (when (= @action "register")
17 ;;TODO: Check correct message length
18 ;;TODO: Check digest in range
20 [digest] (calldataload 32)
21 ;; If already registered, don't continue
23 (return "Arwork already registered."))
24 ;; Get storage for new record
25 [storage] @@next-record
29 [storage] (+ @storage 1)
31 ;; Artist resale percentage
32 [storage] (+ @storage 1)
33 [[@storage]] (calldataload 64)
34 ;; Artist is the current owner
35 [storage] (+ @storage 1)
37 ;; Skip purchaser and price
38 [storage] (+ @storage 3)
39 ;; Copy over the url and description
40 ;; 96 is 32 x 3 = 3rd cell in message
42 (for [i] 6 (< @i 64) [i] (+ @i 1)
44 [[@storage]] (calldataload @source)
45 [storage] (+ @storage 1)
46 [source] (+ @source 32)
48 ;; Store digest-to-record link
49 [[@digest]] @@next-record
50 ;; Increment next record position
51 [[next-record]] (+ @@next-record RECORD-SIZE)
53 (when (= @action "offer")
55 ;;TODO: Check correct message length
56 ;;TODO: Check digest in range
57 ;; Get artwork record storage for digest or stop
58 ;; 32 = second cell in message
59 [storage] @@(calldataload 32)
61 (return "Artwork not registered."))
62 ;; If the caller is the owner
63 (when (= @@ (+ @storage 3) (caller))
66 [[(+ @storage 4)]] (calldataload 64)
68 [[(+ @storage 5)]] (calldataload 96)
71 (when (= @action "accept")
73 ;;TODO: Check correct message length
74 ;;TODO: Check digest in range
75 ;;TODO: Error messages for bad price or buyer
76 ;; Get artwork record storage for digest or stop
77 ;; 32 = second cell in message
78 [storage] @@(calldataload 32)
80 (return "Artwork not registered."))
81 [buyer] @@(+ @storage 4)
82 [price] @@(+ @storage 5)
83 ;; If the caller is the buyer and it's the correct payment
84 ;; Or there's no buyer and it's the correct nonzero payment
85 (when (|| (&& (= @buyer (caller))
86 (= @price (callvalue)))
91 ;; Ethereum doesn't allow fractional amounts
92 ;; Warn users about making prices divisible
93 [hundredth] (/ @price 100)
94 [arr] @@(+ @storage 2)
96 (call (- (gas) 250) @@(+ @storage 1) (* @hundredth @arr) 0 0 0 0)
98 (call (- (gas) 250) @@(+ @storage 3) (* @hundredth (- 100 @arr)) 0 0 0 0)
100 [[(+ @storage 3)]] (caller)
101 ;; Clear offer subject and price