-
-
Notifications
You must be signed in to change notification settings - Fork 571
/
Copy pathindex.html
81 lines (69 loc) · 2.69 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
<html>
<head>
<title>Break OrbitDB</title>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<script type="text/javascript" src="orbitdb.js" charset="utf-8"></script>
<script type="text/javascript" src="ipfs.js" charset="utf-8"></script>
<script type="text/javascript" src="identities.js" charset="utf-8"></script>
<script type="text/javascript" src="ipfslog.min.js" charset="utf-8"></script>
</head>
<body>
<div style="padding: 0px 0px 25px 0px;">
<p>
<span id="waitForOpenDB"></span>
</p>
<button id="addData" type="button">Add random data</button>
<hr />
<h3> Log Data </h3>
<p>
<span id="logData"></span>
</p>
</div>
<!-- </div> -->
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', async () => {
const randStr = () => Math.random().toString(36).substring(6)
const ipfs = await Ipfs.create({
repo: './odb/'
})
const identity = await Identities.createIdentity({ id: 'A'})
const orbitdb = await OrbitDB.createInstance(ipfs, { identity })
const consistentLog = await orbitdb.log('concurrent', { syncLocal: true, sortFn: Log.Sorting.SortByEntryHash })
const inconsistentLog = await orbitdb.log('concurrent2')
window.consistentLog = consistentLog
window.inconsistentLog = inconsistentLog
waitForOpenDB.innerHTML = consistentLog.address.toString() + ' + ' + inconsistentLog.address.toString()
await consistentLog.load()
await inconsistentLog.load()
addData.addEventListener('click', async event => {
const data = randStr()
await consistentLog.add(data)
await inconsistentLog.add(data)
})
})
async function getConsistentLogLength () {
return window.consistentLog._oplog.length
}
async function getConsistentLogHash () {
return await window.consistentLog._oplog.toMultihash()
}
async function getConsistentEntries () {
return window.consistentLog.iterator({ limit: -1 }).collect()
}
async function getInconsistentLogLength () {
return window.inconsistentLog._oplog.length
}
async function getInconsistentLogHash () {
return await window.inconsistentLog._oplog.toMultihash()
}
async function getInconsistentEntries () {
return window.inconsistentLog.iterator({ limit: -1 }).collect()
}
async function loadLogs () {
await window.consistentLog.load()
await window.inconsistentLog.load()
}
</script>
</body>
</html>