Registry code working well enough to demo (various checks not performed in either...
[robmyers:artworld-ethereum.git] / contract / art_is.lll
1 {
2  ;; Constant values
3  ;; Price base (wei), doubled for each definition up to DEFS-COUNT
4  (def 'PRICE-BASE 10)
5  ;; Add to the index to get the price base exponent
6  (def 'PRICE-FACTOR-ADD 10)
7  ;; Number of definitions
8  (def 'DEFS-COUNT 12)
9  ;; Range of values for definitions
10  (def 'DEF-MIN 0x1)
11  (def 'DEF-MAX 0x0F0F0F0F)
12
13  ;; Storage locations
14  (def 'artist 0x10)
15  (def 'defs-base 0x100)
16  (def 'theorists-base 0x200)
17
18  ;; State
19  ;; Contract owner/payee
20  [[artist]] (caller)
21
22  (return
23    0x0
24    (lll
25      {
26      [action] (calldataload 0)
27       (when (= @action "set")
28         {
29          [index] (calldataload 32)
30          [definition] (calldataload 64)
31          [price] (exp PRICE-BASE (+ @index 1 PRICE-FACTOR-ADD))
32          ;; If the index is in range and the caller paid enough to set it
33          (when (&& (>= @definition DEF-MIN)
34                    (<= @definition DEF-MAX)
35                    (< @index DEFS-COUNT)
36                    (= (callvalue) @price))
37            {
38             ;; Update definition
39             [[(+ defs-base @index)]] @definition
40             [[(+ theorists-base @index)]] (caller)
41             (- (gas) 100) @@artist @price 0 0 0 0
42             })
43          })
44       }
45      0x0))
46  }