Registry code working well enough to demo (various checks not performed in either...
[robmyers:artworld-ethereum.git] / ui / custom_works_sale.html
1 <html>
2 <head>
3   <script type="text/javascript"
4           src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
5   </script>
6   <script>
7     if (typeof(window.eth) === "undefined") {
8       document.write('Please run in AlethZero.<br/>');
9     }
10   </script>
11   <script type="text/javascript" src="BigInteger.js"></script>
12   <script type="text/javascript" src="ethString.js"></script>
13   <style>
14     body {
15       text-align: center;
16       font-family: sans;
17     }
18     h1 {
19       font-size: 72pt;
20     }
21     #toggle {
22       color: #B0C4DE;
23     }
24   </style>
25 <title>Custom Artwork</title>
26 </head>
27 <body>
28   <canvas id="artwork"></canvas>
29   <a id="create" href="javascript:void(0)" onclick="purchase();">purchase</a>
30   <script>
31     var contract = "";
32
33     var stripe_height = 100;
34
35     var fetch = function() {
36         var source = eth.storageAt(contract, eth.secretToAddress(eth.key)).bin()
37         if (source) {
38             var artwork = document.getElementById('artwork')
39             artwork.height = stripe_height;
40             var ctx = artwork.getContext('2d');
41             for(var i = 0; i < 10; i++) {
42                 // Get each 2 bytes, multiply by 16 to get 000..FFF
43                 ctx.fillStyle = source.substring(i * 2, i * 2 + 1) * 16;
44                 ctx.fillRect(x, 0, 1, stripe_height);
45             }
46         }
47     };
48
49     var purchase = function() {
50         var price = eth.storageAt(contract, 1001).bin();
51         if (confirm("This will take a payment of " + price +
52                     " and costs gas to run.")) {
53           var result = eth.transact(eth.key, "0", contract, padStr("toggle"), "10000", eth.gasPrice);
54           var artwork = "";
55           foreach(var element in result) {
56               artwork += element.unbin();
57           }
58           document.getElementById("artwork").innerText = artwork;
59           $("#purchase").hide();
60         }
61
62         eth.watch(contract, eth.secretToAddress(eth.key), fetch);
63         fetch();
64
65         
66     };
67   </script>
68 </body>
69 </html>