godprotocol 1.1.32 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Datatypes/arr.js +559 -254
- package/Datatypes/bool.js +8 -5
- package/Datatypes/callable.js +1 -1
- package/Datatypes/cls.js +193 -24
- package/Datatypes/conf.js +2 -2
- package/Datatypes/err.js +25 -0
- package/Datatypes/func.js +89 -13
- package/Datatypes/functions/storage.js +572 -12
- package/Datatypes/functions/wallet.js +49 -0
- package/Datatypes/instance.js +87 -122
- package/Datatypes/num.js +192 -153
- package/Datatypes/str.js +188 -122
- package/Datatypes/twa.js +346 -71
- package/Datatypes/voi.js +9 -4
- package/Index.js +1 -1
- package/Instances/account.js +0 -0
- package/Instances/event.js +0 -0
- package/Instances/fold.js +103 -0
- package/Instances/folder_queries.js +46 -0
- package/Instances/response.js +31 -0
- package/Objects/Account.js +160 -110
- package/Objects/Blockweb.js +6 -11
- package/Objects/Callable.js +223 -188
- package/Objects/Chain.js +127 -142
- package/Objects/Datatypes.js +114 -588
- package/Objects/Manager.js +349 -39
- package/Objects/Oracle.js +283 -210
- package/Objects/Repository.js +12 -33
- package/Objects/Trinity.js +9 -7
- package/Objects/Utils.js +8 -8
- package/Objects/Virtual_machine.js +320 -320
- package/README.md +0 -0
- package/callables/functions/assert.js +10 -0
- package/callables/functions/display.js +2 -3
- package/callables/functions/env.js +5 -0
- package/callables/functions/event.js +14 -0
- package/callables/functions/exit.js +3 -2
- package/callables/functions/folder.js +15 -0
- package/callables/functions/get_uid.js +6 -0
- package/callables/functions/hash.js +7 -0
- package/callables/functions/import_.js +62 -0
- package/callables/functions/local.js +9 -0
- package/callables/functions/net.js +33 -18
- package/callables/functions/parse.js +35 -0
- package/callables/functions/query.js +12 -0
- package/callables/functions/render.js +9 -13
- package/callables/functions/servers.js +10 -0
- package/callables/functions/spawn.js +7 -0
- package/callables/functions/store.js +75 -0
- package/callables/functions/super_.js +24 -0
- package/callables/functions/typeof.js +32 -0
- package/callables/functions/wait.js +9 -0
- package/callables/register.js +193 -8
- package/html/create.js +110 -0
- package/html/index.js +114 -0
- package/html/load.js +165 -0
- package/html/parse.js +171 -0
- package/html/run.js +151 -0
- package/html/util.js +5 -0
- package/package.json +5 -3
- package/repos/fs.js +114 -0
- package/repos/github.js +73 -0
- package/repos/ram.js +47 -0
- package/utils/create_server.js +66 -26
- package/utils/hash.js +3 -2
- package/utils/ops.js +2 -0
- package/utils/oracle_handlers.js +7 -0
- package/utils/services.js +18 -51
- package/utils/socket_server.js +36 -0
- package/utils/vm_utils.js +241 -137
- package/callables/functions/assign.js +0 -6
package/callables/register.js
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
|
-
import twain from "./functions/twain";
|
|
2
|
-
import display from "./functions/display";
|
|
3
|
-
import net from "
|
|
4
|
-
import quit from "
|
|
5
|
-
import render from "./functions/render";
|
|
1
|
+
import twain from "./functions/twain.js";
|
|
2
|
+
import display from "./functions/display.js";
|
|
3
|
+
import net from "./functions/net.js";
|
|
4
|
+
import quit from "./functions/exit.js";
|
|
5
|
+
import render from "./functions/render.js";
|
|
6
|
+
import import_ from "./functions/import_.js";
|
|
7
|
+
import get_uid from "./functions/get_uid.js";
|
|
8
|
+
import hash from "./functions/hash.js";
|
|
9
|
+
import servers from "./functions/servers.js";
|
|
10
|
+
import local from "./functions/local.js";
|
|
11
|
+
import store, {retrieve} from "./functions/store.js";
|
|
12
|
+
import type_of, {instance_of} from "./functions/typeof.js";
|
|
13
|
+
import super_ from "./functions/super_.js";
|
|
14
|
+
import spawn from "./functions/spawn.js";
|
|
15
|
+
import { emit, listen } from "./functions/event.js";
|
|
16
|
+
import folder from "godprotocol/callables/functions/folder.js";
|
|
17
|
+
import parse from "godprotocol/callables/functions/parse.js";
|
|
18
|
+
import assert from "godprotocol/callables/functions/assert.js";
|
|
19
|
+
import env from "godprotocol/callables/functions/env.js";
|
|
20
|
+
import wait from "godprotocol/callables/functions/wait.js";
|
|
21
|
+
import query from "godprotocol/callables/functions/query.js";
|
|
22
|
+
|
|
6
23
|
|
|
7
24
|
const register = async (account) => {
|
|
8
25
|
let set = account.vm.set;
|
|
9
26
|
|
|
27
|
+
set('spawn', {
|
|
28
|
+
callable: spawn,
|
|
29
|
+
config: {
|
|
30
|
+
parameters: [
|
|
31
|
+
{name: 'spawn', position: 0}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
10
36
|
set("display", {
|
|
11
37
|
callable: display,
|
|
12
38
|
config: {
|
|
@@ -14,6 +40,34 @@ const register = async (account) => {
|
|
|
14
40
|
},
|
|
15
41
|
});
|
|
16
42
|
|
|
43
|
+
set("assert", {
|
|
44
|
+
callable: assert,
|
|
45
|
+
config: {
|
|
46
|
+
parameters: [{ name: "predicate", position: 0}],
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
set("query", {
|
|
51
|
+
callable: query,
|
|
52
|
+
config: {
|
|
53
|
+
parameters: [{ name: "object", position: 0}, { name: "filter", position: 0}],
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
set("wait", {
|
|
58
|
+
callable: wait,
|
|
59
|
+
config: {
|
|
60
|
+
parameters: [{ name: "duration", position: 0}],
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
set("env", {
|
|
65
|
+
callable: env,
|
|
66
|
+
config: {
|
|
67
|
+
parameters: [],
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
17
71
|
set("Twain", {
|
|
18
72
|
callable: twain,
|
|
19
73
|
config: {
|
|
@@ -21,13 +75,132 @@ const register = async (account) => {
|
|
|
21
75
|
},
|
|
22
76
|
});
|
|
23
77
|
|
|
78
|
+
set("get_uid", {
|
|
79
|
+
callable: get_uid,
|
|
80
|
+
config: {
|
|
81
|
+
parameters: [{ name: "object", position: 0 }],
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
set("listen", {
|
|
86
|
+
callable: listen,
|
|
87
|
+
config: {
|
|
88
|
+
parameters: [
|
|
89
|
+
{ name: "name", position: 0 },
|
|
90
|
+
{ name: "handler", position: 1 },
|
|
91
|
+
{ name: "key", position: 2 }
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
set("emit", {
|
|
97
|
+
callable: emit,
|
|
98
|
+
config: {
|
|
99
|
+
parameters: [
|
|
100
|
+
{ name: "name", position: 0 },
|
|
101
|
+
{ name: "args", position: 1 },
|
|
102
|
+
{ name: "key", position: 2 }
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
set("folder", {
|
|
108
|
+
callable: folder,
|
|
109
|
+
config: {
|
|
110
|
+
parameters: [
|
|
111
|
+
{ name: "name", position: 0 },
|
|
112
|
+
{ name: "options", position: 1 },
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
set("get_uid", {
|
|
118
|
+
callable: get_uid,
|
|
119
|
+
config: {
|
|
120
|
+
parameters: [{ name: "object", position: 0 }],
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
set("super", {
|
|
125
|
+
callable: super_,
|
|
126
|
+
config: {
|
|
127
|
+
parameters: [{name:'args', spread: true}, { name: "index", position: 0 }, { name: "object", position: 0 }],
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
set("local", {
|
|
132
|
+
callable: local,
|
|
133
|
+
config: {
|
|
134
|
+
parameters: [
|
|
135
|
+
{ name: "name_address", position: 0 },
|
|
136
|
+
{ name: "args", position: 1 }
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
set("hash", {
|
|
142
|
+
callable: hash,
|
|
143
|
+
config: {
|
|
144
|
+
parameters: [{ name: "object", position: 0 }],
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
set("typeof", {
|
|
149
|
+
callable: type_of,
|
|
150
|
+
config: {
|
|
151
|
+
parameters: [{ name: "object", position: 0 }],
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
set("instanceof", {
|
|
156
|
+
callable: instance_of,
|
|
157
|
+
config: {
|
|
158
|
+
parameters: [{ name: "object", position: 0 }],
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
set("store", {
|
|
163
|
+
callable: store,
|
|
164
|
+
config: {
|
|
165
|
+
parameters: [
|
|
166
|
+
{ name: "object", position: 0 },
|
|
167
|
+
{ name: "validation", position: 1 },
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
set("retrieve", {
|
|
173
|
+
callable: retrieve,
|
|
174
|
+
config: {
|
|
175
|
+
parameters: [
|
|
176
|
+
{ name: "address", position: 0 },
|
|
177
|
+
{ name: "_id", position: 1 },
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
set("servers", {
|
|
183
|
+
callable: servers,
|
|
184
|
+
config: {
|
|
185
|
+
parameters: [{ name: "account", position: 0 }],
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
set("parse", {
|
|
190
|
+
callable: parse,
|
|
191
|
+
config: {
|
|
192
|
+
parameters: [{ name: "address", position: 0 }, {name: "options", position: 1}],
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
|
|
24
196
|
set("net", {
|
|
25
197
|
callable: net,
|
|
26
198
|
config: {
|
|
27
199
|
parameters: [
|
|
28
|
-
{ name: "server", position: 0 },
|
|
29
200
|
{ name: "path", position: 0 },
|
|
30
|
-
{ name: "payload", position:
|
|
201
|
+
{ name: "payload", position: 1 },
|
|
202
|
+
{ name: "account", position: 2 },
|
|
203
|
+
{ name: "server", position: 3 },
|
|
31
204
|
],
|
|
32
205
|
},
|
|
33
206
|
});
|
|
@@ -42,7 +215,19 @@ const register = async (account) => {
|
|
|
42
215
|
set("render", {
|
|
43
216
|
callable: render,
|
|
44
217
|
config: {
|
|
45
|
-
parameters: [
|
|
218
|
+
parameters: [
|
|
219
|
+
{ name: "object", position: 0 },
|
|
220
|
+
{ name: "parent", position: 1 },
|
|
221
|
+
{ name: "query_selector", position: 2 },
|
|
222
|
+
{ name: "rerender", position: 3 }
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
set("import", {
|
|
228
|
+
callable: import_,
|
|
229
|
+
config: {
|
|
230
|
+
parameters: [{ name: "address", position: 0 }, { name: "identifiers", position: 1 }],
|
|
46
231
|
},
|
|
47
232
|
});
|
|
48
233
|
};
|
package/html/create.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {message_box} from './util.js'
|
|
2
|
+
|
|
3
|
+
const script = (manager)=> {
|
|
4
|
+
return `
|
|
5
|
+
const account_id_el = document.getElementById('account_id'), account_password_el = document.getElementById('account_password'),
|
|
6
|
+
show_password = document.getElementById('show_password'), create_account = document.getElementById('create_account')
|
|
7
|
+
|
|
8
|
+
show_password.addEventListener('click', e=>{
|
|
9
|
+
account_password_el.setAttribute('type', e.target.checked ? 'text' : 'password')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
let message_box = document.getElementById('message-box')
|
|
13
|
+
|
|
14
|
+
create_account.addEventListener('click', e=>{
|
|
15
|
+
e.preventDefault();
|
|
16
|
+
console.log('click click', "http://${manager.options.server_domain}")
|
|
17
|
+
|
|
18
|
+
let name = account_id_el.value.trim(), password = account_password_el.value.trim();
|
|
19
|
+
|
|
20
|
+
if (!name || !password){
|
|
21
|
+
message_box.textContent = 'Please completely fill all form fields.'
|
|
22
|
+
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
message_box.textContent = ''
|
|
25
|
+
}, 2500);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fetch("http://${manager.options.server_domain.concat('/create_account')}", {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
header: {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
Accept: 'application/json'
|
|
34
|
+
},
|
|
35
|
+
body: JSON.stringify({name, password})
|
|
36
|
+
})
|
|
37
|
+
.then(data=>data.json())
|
|
38
|
+
.then(res=>{
|
|
39
|
+
let accs = sessionStorage.getItem('accounts')
|
|
40
|
+
if (accs) accs = JSON.parse(accs)
|
|
41
|
+
else accs = new Array()
|
|
42
|
+
|
|
43
|
+
if (res.uid){
|
|
44
|
+
let indx = accs.findIndex(ac=>ac.name === name)
|
|
45
|
+
if (indx !== -1){
|
|
46
|
+
accs[indx].uid = res.uid
|
|
47
|
+
} else {
|
|
48
|
+
accs.push({name, uid: res.uid})
|
|
49
|
+
}
|
|
50
|
+
sessionStorage.setItem('accounts', JSON.stringify(accs))
|
|
51
|
+
|
|
52
|
+
account_password_el.value = ''
|
|
53
|
+
account_id_el.value = ''
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
message_box.textContent = res.uid ? 'Account signed succesfully!' : res.message
|
|
57
|
+
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
message_box.textContent = ''
|
|
60
|
+
}, 2500);
|
|
61
|
+
return;
|
|
62
|
+
})
|
|
63
|
+
.catch(err=>console.log(err))
|
|
64
|
+
|
|
65
|
+
}) `
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const create = (manager)=>{
|
|
69
|
+
let tml = `<div class="container my-5">
|
|
70
|
+
<div class="row justify-content-center">
|
|
71
|
+
<div class="col-md-6">
|
|
72
|
+
<form id="create-form" class="card p-4 shadow-sm">
|
|
73
|
+
<h4 class="mb-4 text-center">Create Account</h4>
|
|
74
|
+
|
|
75
|
+
<!-- Account Name -->
|
|
76
|
+
<div class="mb-3">
|
|
77
|
+
<label for="account_id" class="form-label">Account Name</label>
|
|
78
|
+
<input type="text" class="form-control" id="account_id" placeholder="Name" required>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<!-- Password -->
|
|
82
|
+
<div class="mb-3">
|
|
83
|
+
<label for="account_password" class="form-label">Password</label>
|
|
84
|
+
<input type="password" class="form-control" id="account_password" placeholder="Password" required>
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<!-- Show Password -->
|
|
88
|
+
<div class="form-check mb-3">
|
|
89
|
+
<input class="form-check-input" type="checkbox" id="show_password">
|
|
90
|
+
<label class="form-check-label" for="show_password">Show Password</label>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<!-- Submit -->
|
|
94
|
+
<div class="d-grid">
|
|
95
|
+
<button type="submit" class="btn btn-primary" id="create_account">Submit</button>
|
|
96
|
+
</div>
|
|
97
|
+
</form>
|
|
98
|
+
|
|
99
|
+
<!-- Message box placeholder -->
|
|
100
|
+
<div id="message-box" class="mt-3"></div>
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
</div>`
|
|
104
|
+
|
|
105
|
+
tml = `${tml} <script>${script(manager)}</script>`
|
|
106
|
+
|
|
107
|
+
return tml
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default create
|
package/html/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import create from './create.js'
|
|
2
|
+
import run from './run.js'
|
|
3
|
+
import load from './load.js'
|
|
4
|
+
import parse from './parse.js'
|
|
5
|
+
|
|
6
|
+
let routes = ['create_account', 'load', 'run', 'parse']
|
|
7
|
+
|
|
8
|
+
const forms = (route, manager)=>{
|
|
9
|
+
let pair = {
|
|
10
|
+
create_account: create,
|
|
11
|
+
load,
|
|
12
|
+
run,
|
|
13
|
+
parse,
|
|
14
|
+
}
|
|
15
|
+
let rt = pair[route]
|
|
16
|
+
if (rt) return rt(manager)
|
|
17
|
+
|
|
18
|
+
return ''
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const header_script = (manager)=>{
|
|
22
|
+
return ` let ftch = async(path, body)=>{
|
|
23
|
+
let fch = await fetch("http://${manager.options.server_domain}".concat(path), {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
header: {
|
|
26
|
+
'Content-Type': 'application/json',
|
|
27
|
+
Accept: 'application/json'
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify(body)
|
|
30
|
+
})
|
|
31
|
+
let response = await fch.json()
|
|
32
|
+
return response;
|
|
33
|
+
}`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const header = (route) => {
|
|
37
|
+
let tml = `<nav class="navbar navbar-expand-lg navbar-light bg-light shadow-sm">
|
|
38
|
+
<div class="container">
|
|
39
|
+
<a class="navbar-brand fw-bold" href="/">GODPROTOCOL</a>
|
|
40
|
+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
|
41
|
+
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
42
|
+
<span class="navbar-toggler-icon"></span>
|
|
43
|
+
</button>
|
|
44
|
+
|
|
45
|
+
<div class="collapse navbar-collapse justify-content-center" id="navbarNav">
|
|
46
|
+
<ul class="navbar-nav" id="nav-list">
|
|
47
|
+
`
|
|
48
|
+
|
|
49
|
+
routes.map(r=>{
|
|
50
|
+
tml = `${tml}<li class='nav-item'><a href='/${r}' class="nav-link text-capitalize ${route === r ? 'active text-danger fw-bold' : ''}">${r.replace(/_/g, ' ')}</a></li>`
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
tml = `${tml}</ul>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
</nav>`
|
|
57
|
+
|
|
58
|
+
return tml
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const footer = (route) => {
|
|
62
|
+
let yr = new Date().getFullYear()
|
|
63
|
+
let tml = `<footer class="mt-auto py-3 bg-light text-center">
|
|
64
|
+
<div class="container">
|
|
65
|
+
<p class="mb-1">
|
|
66
|
+
Made with <i class="bi bi-heart-fill text-danger"></i> by
|
|
67
|
+
<a target="_blank" href="https://github.com/immanuel-savvy">Savvy</a>.
|
|
68
|
+
</p>
|
|
69
|
+
<small>
|
|
70
|
+
Airditor beta version 0.0.1 — Released under the <a target="_blank" href="https://opensource.org/licenses/MIT">MIT License</a>. ©
|
|
71
|
+
<span id="year">${2025 - yr !== 0 ? `${2025} - ${yr}` : yr}</span>
|
|
72
|
+
</small>
|
|
73
|
+
</div>
|
|
74
|
+
</footer>`
|
|
75
|
+
|
|
76
|
+
return tml
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const set_page = (route, manager)=>{
|
|
80
|
+
let title = `GODPROTOCOL`
|
|
81
|
+
let init_acc = manager.init_account
|
|
82
|
+
if (init_acc){
|
|
83
|
+
title = `${init_acc.name} - ${title}`
|
|
84
|
+
}
|
|
85
|
+
let tml = `
|
|
86
|
+
<html>
|
|
87
|
+
<head>
|
|
88
|
+
<meta charset="UTF-8">
|
|
89
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
90
|
+
<title>GodProtocol</title>
|
|
91
|
+
<!-- Bootstrap 5 CDN -->
|
|
92
|
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
93
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
|
|
94
|
+
|
|
95
|
+
</head>
|
|
96
|
+
|
|
97
|
+
<body class="d-flex flex-column min-vh-100"><div class="container text-center my-5"><h1 id='page-title' class='mb-4'>${title}</h1>`
|
|
98
|
+
|
|
99
|
+
tml = `${tml}${header(route)}`
|
|
100
|
+
|
|
101
|
+
tml = `${tml}<script>${header_script(manager)}</script>`
|
|
102
|
+
|
|
103
|
+
if (route !== ''){
|
|
104
|
+
tml = `${tml}${forms(route, manager)}`
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
tml = `${tml}${footer(route)}`
|
|
108
|
+
tml = `${tml}<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script></div></body> </html>
|
|
109
|
+
`
|
|
110
|
+
|
|
111
|
+
return tml
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export {set_page}
|
package/html/load.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
const script = (manager)=> {
|
|
2
|
+
return `
|
|
3
|
+
const account_selection_el = document.getElementById('account_selection'), address_el = document.getElementById('address'),
|
|
4
|
+
sequence_el = document.getElementById('sequence'),
|
|
5
|
+
id_el = document.getElementById('ID'),
|
|
6
|
+
should_compile = document.getElementById('should_compile'), load = document.getElementById('load'), retrieve_code = document.getElementById('retrieve_code')
|
|
7
|
+
|
|
8
|
+
sequence_el.addEventListener('keyup', e=>{
|
|
9
|
+
retrieve_code.textContent = 'Retrieve'
|
|
10
|
+
})
|
|
11
|
+
should_compile.addEventListener('click', e=>{
|
|
12
|
+
let message_box = document.getElementById('message-box')
|
|
13
|
+
|
|
14
|
+
document.getElementById('sequence_label').textContent = e.target.checked ? 'Code' : 'Sequence'
|
|
15
|
+
retrieve_code.style.visibility = e.target.checked ? 'visible' : 'hidden'
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
retrieve_code.addEventListener('click', async e=>{
|
|
19
|
+
e.preventDefault()
|
|
20
|
+
|
|
21
|
+
let account = account_selection_el.selectedIndex
|
|
22
|
+
console.log(account)
|
|
23
|
+
|
|
24
|
+
if (!account){
|
|
25
|
+
message_box.innerHTML = 'Provide an account, or <a href="http://${manager.options.server_domain}/create_account">create one here</a>'
|
|
26
|
+
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
message_box.textContent = ''
|
|
29
|
+
}, 2500);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let account_uid = account_selection_el.children[account].id
|
|
34
|
+
|
|
35
|
+
e.target.value = 'Retrieving...'
|
|
36
|
+
let code = await ftch("/parse", {
|
|
37
|
+
address: address_el.value,
|
|
38
|
+
from: '.codes',
|
|
39
|
+
account: account_uid,
|
|
40
|
+
account_name: account_selection_el.children[account].value
|
|
41
|
+
})
|
|
42
|
+
console.log(code, 'uhhh')
|
|
43
|
+
if (code.result){
|
|
44
|
+
sequence_el.value = code.result;
|
|
45
|
+
e.target.textContent = 'Retrieve'
|
|
46
|
+
}else e.target.textContent = code.message
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
let message_box = document.getElementById('message-box')
|
|
50
|
+
|
|
51
|
+
document.addEventListener('DOMContentLoaded', e=>{
|
|
52
|
+
let accs = sessionStorage.getItem('accounts')
|
|
53
|
+
if (!accs) return;
|
|
54
|
+
|
|
55
|
+
let tml = '<option default>--Select Account--</option>'
|
|
56
|
+
if (accs){
|
|
57
|
+
accs = JSON.parse(accs)
|
|
58
|
+
accs.map(acc=>{
|
|
59
|
+
let el = document.createElement('option')
|
|
60
|
+
el.id = acc.uid
|
|
61
|
+
el.value = acc.uid
|
|
62
|
+
el.textContent = acc.name
|
|
63
|
+
|
|
64
|
+
account_selection_el.appendChild(el)
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
load.addEventListener('click', e=>{
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
|
|
72
|
+
let id = id_el.value.trim(), address = address_el.value.trim(), sequence = sequence_el.value.trim(), account = account_selection_el.selectedIndex, compiler = should_compile.checked;
|
|
73
|
+
|
|
74
|
+
if (!account){
|
|
75
|
+
message_box.innerHTML = 'Provide an account, or <a href="http://${manager.options.server_domain}/create_account">create one here</a>'
|
|
76
|
+
|
|
77
|
+
setTimeout(() => {
|
|
78
|
+
message_box.textContent = ''
|
|
79
|
+
}, 2500);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let account_uid = account_selection_el.children[account].id
|
|
84
|
+
if (!address || !sequence){
|
|
85
|
+
message_box.textContent = 'Please completely fill all form fields.'
|
|
86
|
+
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
message_box.textContent = ''
|
|
89
|
+
}, 2500);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let data = {
|
|
94
|
+
_id: id, address, sequence, compiler, account: account_uid, account_name: account_selection_el.children[account].value
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
ftch('/load', data)
|
|
98
|
+
.then(res=>{
|
|
99
|
+
message_box.textContent = res.done ? 'Sequence loaded successfully! - ' + res.datapath : res.message
|
|
100
|
+
return;
|
|
101
|
+
}).catch(err=>console.log(err))
|
|
102
|
+
|
|
103
|
+
}) `
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const load = (manager)=>{
|
|
107
|
+
let tml = `<!-- Container for the Load form -->
|
|
108
|
+
<div class="container my-5">
|
|
109
|
+
<div class="row justify-content-center">
|
|
110
|
+
<div class="col-md-8">
|
|
111
|
+
<form id="load-form" class="card p-4 shadow-sm">
|
|
112
|
+
<h4 class="mb-4 text-center">Load</h4>
|
|
113
|
+
|
|
114
|
+
<!-- Account Selection -->
|
|
115
|
+
<div class="mb-3">
|
|
116
|
+
<label for="account_selection" class="form-label">Account</label>
|
|
117
|
+
<select id="account_selection" class="form-select" required>
|
|
118
|
+
<option selected disabled>-- Select Account --</option>
|
|
119
|
+
<!-- Options will be injected via JS -->
|
|
120
|
+
</select>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<!-- Address -->
|
|
124
|
+
<div class="mb-3">
|
|
125
|
+
<label for="address" class="form-label">Address</label>
|
|
126
|
+
<input type="text" class="form-control" id="address" placeholder="Address" required>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<!-- ID (Optional) -->
|
|
130
|
+
<div class="mb-3">
|
|
131
|
+
<label for="ID" class="form-label">ID (optional)</label>
|
|
132
|
+
<input type="text" class="form-control" id="ID" placeholder="ID">
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
<!-- Sequence -->
|
|
136
|
+
<div class="mb-3">
|
|
137
|
+
<label for="sequence" class="form-label">Code</label>
|
|
138
|
+
<a href="#" id="retrieve_code" class="ms-2 fst-italic fw-bold">Retrieve</a>
|
|
139
|
+
<textarea class="form-control mt-2" id="sequence" rows="4" placeholder="Sequence"></textarea>
|
|
140
|
+
</div>
|
|
141
|
+
|
|
142
|
+
<!-- Compile Option -->
|
|
143
|
+
<div class="form-check mb-3">
|
|
144
|
+
<input class="form-check-input" type="checkbox" id="should_compile" checked>
|
|
145
|
+
<label class="form-check-label" for="should_compile">Should compile</label>
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
<!-- Submit Button -->
|
|
149
|
+
<div class="d-grid">
|
|
150
|
+
<button type="submit" class="btn btn-success" id="load">Send</button>
|
|
151
|
+
</div>
|
|
152
|
+
</form>
|
|
153
|
+
|
|
154
|
+
<!-- Message box -->
|
|
155
|
+
<div id="message-box" class="mt-3"></div>
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
</div>`
|
|
159
|
+
|
|
160
|
+
tml = `${tml} <script>${script(manager)}</script>`
|
|
161
|
+
|
|
162
|
+
return tml
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default load
|