-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample6.html
More file actions
79 lines (42 loc) · 1.71 KB
/
example6.html
File metadata and controls
79 lines (42 loc) · 1.71 KB
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
<pre>
POT JS Example 6: Network II
Check source and browser console.
This page connects to a local Swarm network.
It can be tried by running `make example6`, which takes care of
the local network and the Swarm batch id. The script connects
to the http server at port 8080, the Swarm queen node at 1633.
What those make rules do is essentially:
fdp-play start --detach
swarm-cli stamp buy --yes --verbose --depth 20 --amount 1b > .batch_creation
grep "Stamp ID:" .batch_creation | cut -c11-74 > .batch_id
npx http-server -c1 . &
open "http://127.0.0.1:8080/example6.html?bee=http://127.0.0.1:1633&batch=$(cat .batch_id)"
If the batch id file exists, or the http server is already
running, the make rules will skip the respective lines.
Use `make stop` to stop the servers, or keep them running for
the next examples.
<img src=favicon.ico>
</pre>
<script src="lib/pot-web.js" verbosity=2></script>
<script>
(async () => {
await pot.ready()
batch = new URLSearchParams(window.location.search).get('batch');
kvs1 = new pot.Kvs("http://localhost:1633", batch)
console.log("kvs #1 -- put hello : POT!")
await kvs1.put("hello", "POT!")
value = await kvs1.get("hello")
console.log("kvs #1 -- key ‹hello› has:", value)
ref1 = await kvs1.save()
console.log("kvs #1 -- trie root is :", ref1)
kvs2 = await pot.load(ref1, "http://localhost:1633", batch)
value2 = await kvs2.get("hello")
console.log("kvs #2 -- key ‹hello› has:", value2)
ref2 = await kvs2.save()
console.log("kvs #2 -- trie root is :", ref2)
console.log("kvs #2 -- put baz : true")
await kvs2.put("baz", true)
ref3 = await kvs2.save()
console.log("kvs #2 -- trie root is :", ref3)
})()
</script>