forked from bluesign/tinyFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
105 lines (77 loc) · 2.34 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<script src="wasm_exec.js"></script>
<script>
window.runtime = {
ledger: new Map(),
getValue: function(owner, key) {
window.info("get value: " + owner.toString() + key.toString());
return this.ledger.get(owner.toString()+key.toString());
},
setValue: function(owner, key, value) {
window.info("set value: " + owner.toString() + key.toString() + " = " + value);
this.ledger.set(owner.toString()+key.toString(), value);
},
log: function(msg) {
window.info("Cadence: " + msg);
}
};
window.info = function(msg){
document.write("<pre>" , msg.replaceAll("\\n", "<br>"));
document.write("</pre><br>");
}
var go = new Go();
WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {
go.run(result.instance);
var transaction = {
script: `
transaction {
prepare(signer: auth(Storage) &Account) {
log(signer);
log("Hello, World!");
signer.storage.save("tinyFlow", to: /storage/tiny);
}
}
`,
referenceBlockId: "0000000000000001",
proposalKey:{
address: "0000000000000001",
keyIndex: 1,
sequenceNumber: 1,
},
authorizers: ["0000000000000001"],
};
window.info("send transaction 1");
window.info(JSON.stringify(transaction, undefined, 2));
window.sendTransaction(transaction);
var transaction2 = {
script: `
transaction {
prepare(signer: auth(Storage) &Account) {
log("Transaction 2");
var msg = signer.storage.load<String>(from: /storage/tiny);
log(msg)
}
}
`,
referenceBlockId: "0000000000000001",
proposalKey:{
address: "0000000000000001",
keyIndex: 1,
sequenceNumber: 1,
},
authorizers: ["0000000000000001"],
};
window.info("send transaction 2");
window.info(JSON.stringify(transaction2, undefined, 2));
window.sendTransaction(transaction2);
});
</script>
</head>
<body>
<script>
</script>
</body>
</html>