forked from lightningnetwork/lnd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·81 lines (76 loc) · 2.27 KB
/
index.html
File metadata and controls
executable file
·81 lines (76 loc) · 2.27 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
79
80
81
<html>
<head>
<title>LND WebAssembly</title>
<script src="wasm_exec.js"></script>
<script src="browserfs.js"></script>
<script type="text/javascript">
// Installs globals onto window:
// * Buffer
// * require (monkey-patches if already defined)
// * process
// You can pass in an arbitrary object if you do not wish to pollute
// the global namespace.
function setupBFS() {
return new Promise(resolve => {
var scope = {}
BrowserFS.install(scope);
// Configures BrowserFS to use the LocalStorage file system.
BrowserFS.configure({
fs: "LocalStorage"
}, function(e) {
if (e) {
// An error happened!
throw e;
}
// Otherwise, BrowserFS is ready-to-use!
resolve(scope.require('fs'));
});
})
}
</script>
<script type="text/javascript">
function fetchAndInstantiate(url, importObject) {
return fetch(url).then(response =>
response.arrayBuffer()
).then(bytes =>
WebAssembly.instantiate(bytes, importObject)
).then(results =>
results.instance
);
}
var go = new Go();
var mod = fetchAndInstantiate("/lnd.wasm", go.importObject);
window.onload = async function() {
const fs = await setupBFS()
const { writeSync, openSync, constants } = window.fs
// window.fs contains pre-setup fs, e.g. for console.log
// fs is a BrowserFS full emulator based on localStorage
window.fs = {
constants,
...fs,
openSync (path, flags, mode) {
console.log(`call openSync ${path}`, flags, mode)
const fd = fs.openSync(path, flags || 'a+', mode)
console.log('fd', fd)
return fd
},
writeSync (fd, buf, ...args) {
if (fd <= 2) {
// stdin, stdout goes to console.log
// this function is inherited from wasm_exec.js
return writeSync(fd, buf)
} else {
return fs.writeSync(fd, buf, ...args)
}
},
};
mod.then(function(instance) {
go.run(instance);
})
};
</script>
</head>
<body>
<h1>Hello LND!</h1>
</body>
</html>