Registry code working well enough to demo (various checks not performed in either...
[robmyers:artworld-ethereum.git] / contract / custom_works.se
1 HEX = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
2 ARTWORK = ["<svg><rect x=\"23\" y=\"23\" ", "height=\"123\" width=\"123\" ", "style=\"fill:none;stroke:#", ";stroke-width:32\" /></svg>"]
3 ARTWORK.LENGTH = 10
4 ARTWORK.INSERT.END = 8
5
6 // Make sure we have enough gas to run the contact
7 //if tx.value < tx.basefee * 500:
8     // If not, stop
9 //    stop
10
11 // If there are enough arguments
12 // and the command to create the work is being given
13 if msg.datasize == 1 and msg.data[0] == "create":
14     artwork = array(ARTWORK.LENGTH)
15     artwork[0] = ARTWORK[0]
16     artwork[1] = ARTWORK[1]
17     artwork[2] = ARTWORK[2]
18     artwork[9] = ARTWORK[3]
19     // Copy the most significant hex bytes of the key as an html colour
20     index = 0
21     hash.bytes = msg.sender
22     while index < 3:
23         current.byte = hash.bytes % 256
24         hash.bytes = hash.bytes / 256
25         hi = HEX[current.byte / 16]
26         lo = HEX[current.byte % 16]
27         artwork[ARTWORK.INSERT.END - (index * 2)] = lo
28         artwork[ARTWORK.INSERT.END - (index * 2) + 1] = hi
29         index = index + 1
30     return(artwork, ARTWORK.LENGTH)
31 // Otherwise
32 else:
33     // Logical false for failure
34     return(0)