Some bug fixes needed for some Serpent files.
[robmyers:artworld-ethereum.git] / serpent / numbered_works.se
1 init:
2     ARTWORK.NUMBER.INDEX = 1001 
3     contract.storage[ARTWORK.NUMBER.INDEX] = 0
4
5 code:
6     ARTWORK.BASE = "Work #                    "
7     ARTWORK.LENGTH = 26
8     ARTWORK.INSERT = 6
9     ARTWORK.NUMBER.INDEX = 1001
10     // Make sure we have enough gas to run the contact
11     if tx.value < tx.basefee * 400:
12         // If not, stop
13         stop
14
15     // Get the number of the work to produce
16     num = contract.storage[ARTWORK.NUMBER.INDEX]
17     // And format it into the string containing the artwork
18     index = ARTWORK.INSERT
19     work = ARTWORK.BASE
20     while num:
21         work[index] = "0123456789"[num % 10]
22         num = num / 10
23         index = index + 1
24     // Store the number to use for the next work
25     contract.storage[ARTWORK.NUMBER.INDEX] = contract.storage[ARTWORK.NUMBER.INDEX] + 1
26     // Return the work
27     return(work)