godprotocol 1.2.31 → 1.2.33
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/Objects/Oracle.js +46 -3
- package/html/index.js +65 -63
- package/html/load.js +11 -10
- package/package.json +1 -1
- package/utils/create_server.js +46 -9
package/Objects/Oracle.js
CHANGED
|
@@ -5,15 +5,34 @@ class Oracle_client {
|
|
|
5
5
|
this.server = server;
|
|
6
6
|
|
|
7
7
|
this.repo_cache = new Object();
|
|
8
|
+
this.repos = [];
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
add_repo = async (repo) => {
|
|
12
|
+
this.repos.push(await this.Repos.cloth_repo(repo.repo));
|
|
13
|
+
|
|
11
14
|
await this.fetch({
|
|
12
15
|
method: "add_repo",
|
|
13
16
|
args: repo,
|
|
14
17
|
});
|
|
15
18
|
};
|
|
16
19
|
|
|
20
|
+
write_local = async (path, content) => {
|
|
21
|
+
let repo = this.repos[0];
|
|
22
|
+
if (repo) {
|
|
23
|
+
repo.write(path, content);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
read_local = async (path) => {
|
|
28
|
+
let repo = this.repos[0];
|
|
29
|
+
if (repo) {
|
|
30
|
+
let content = await repo.read(path);
|
|
31
|
+
return content;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
|
|
17
36
|
write = async (path, content) => {
|
|
18
37
|
await this.fetch({
|
|
19
38
|
method: Array.isArray(content) ? "write_bulk" : "write",
|
|
@@ -58,12 +77,13 @@ class Oracle_client {
|
|
|
58
77
|
};
|
|
59
78
|
|
|
60
79
|
fetch = async (payload) => {
|
|
80
|
+
let auth_token = await this.get_auth_token();
|
|
61
81
|
let headers;
|
|
62
|
-
if (payload.method !== "authenticate" && !
|
|
82
|
+
if (payload.method !== "authenticate" && !auth_token) {
|
|
63
83
|
await this.sync(this.client);
|
|
64
84
|
} else if (payload.method !== "authenticate") {
|
|
65
85
|
headers = {
|
|
66
|
-
authorisation:
|
|
86
|
+
authorisation: auth_token,
|
|
67
87
|
};
|
|
68
88
|
}
|
|
69
89
|
|
|
@@ -96,8 +116,31 @@ class Oracle_client {
|
|
|
96
116
|
});
|
|
97
117
|
|
|
98
118
|
if (auth.token) {
|
|
99
|
-
this.
|
|
119
|
+
await this.set_auth_token(auth.token);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
get_auth_token = async () => {
|
|
124
|
+
let token = this.auth_token;
|
|
125
|
+
if (!token) {
|
|
126
|
+
token = await this.read_local(this.token_addr);
|
|
127
|
+
if (token) {
|
|
128
|
+
token = JSON.parse(token);
|
|
129
|
+
this.auth_token = token.token;
|
|
130
|
+
this.client = token.client;
|
|
131
|
+
}
|
|
100
132
|
}
|
|
133
|
+
return this.auth_token;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
token_addr = `.accounts/sign`;
|
|
137
|
+
|
|
138
|
+
set_auth_token = async (token) => {
|
|
139
|
+
this.auth_token = token;
|
|
140
|
+
this.write_local(
|
|
141
|
+
this.token_addr,
|
|
142
|
+
JSON.stringify({ client: this.client, token })
|
|
143
|
+
);
|
|
101
144
|
};
|
|
102
145
|
|
|
103
146
|
cloth_repo = async (repo) => {
|
package/html/index.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import create from
|
|
2
|
-
import run from
|
|
3
|
-
import load from
|
|
4
|
-
import parse from
|
|
5
|
-
|
|
6
|
-
let routes = [
|
|
7
|
-
|
|
8
|
-
const forms = (route, manager)=>{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const header_script = (manager)=>{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
let domain = manager.options.server_domain;
|
|
23
|
+
if (domain.startsWith("127")) domain = `http://${domain}`;
|
|
24
|
+
else domain = `https://${domain}`;
|
|
25
|
+
|
|
26
|
+
return ` let ftch = async(path, body)=>{
|
|
27
27
|
try{
|
|
28
28
|
let fch = await fetch("${domain}".concat(path), {
|
|
29
29
|
method: 'POST',
|
|
@@ -39,11 +39,11 @@ const header_script = (manager)=>{
|
|
|
39
39
|
console.log(e)
|
|
40
40
|
return {message: e.message}
|
|
41
41
|
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
42
|
+
}`;
|
|
43
|
+
};
|
|
44
44
|
|
|
45
45
|
const header = (route) => {
|
|
46
|
-
|
|
46
|
+
let tml = `<nav class="navbar navbar-expand-lg navbar-light bg-light shadow-sm">
|
|
47
47
|
<div class="container">
|
|
48
48
|
<a class="navbar-brand fw-bold" href="/">GODPROTOCOL</a>
|
|
49
49
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
|
@@ -53,23 +53,25 @@ const header = (route) => {
|
|
|
53
53
|
|
|
54
54
|
<div class="collapse navbar-collapse justify-content-center" id="navbarNav">
|
|
55
55
|
<ul class="navbar-nav" id="nav-list">
|
|
56
|
-
|
|
56
|
+
`;
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
routes.map((r) => {
|
|
59
|
+
tml = `${tml}<li class='nav-item'><a href='/${r}' class="nav-link text-capitalize ${
|
|
60
|
+
route === r ? "active text-danger fw-bold" : ""
|
|
61
|
+
}">${r.replace(/_/g, " ")}</a></li>`;
|
|
62
|
+
});
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
tml = `${tml}</ul>
|
|
63
65
|
</div>
|
|
64
66
|
</div>
|
|
65
|
-
</nav
|
|
67
|
+
</nav>`;
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
+
return tml;
|
|
70
|
+
};
|
|
69
71
|
|
|
70
72
|
const footer = (route) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
let yr = new Date().getFullYear();
|
|
74
|
+
let tml = `<footer class="mt-auto py-3 bg-light text-center">
|
|
73
75
|
<div class="container">
|
|
74
76
|
<p class="mb-1">
|
|
75
77
|
Made with <i class="bi bi-heart-fill text-danger"></i> by
|
|
@@ -80,18 +82,18 @@ const footer = (route) => {
|
|
|
80
82
|
<span id="year">${2025 - yr !== 0 ? `${2025} - ${yr}` : yr}</span>
|
|
81
83
|
</small>
|
|
82
84
|
</div>
|
|
83
|
-
</footer
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const set_page = (route, manager)=>{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
</footer>`;
|
|
86
|
+
|
|
87
|
+
return tml;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const set_page = (route, manager) => {
|
|
91
|
+
let title = `GODPROTOCOL`;
|
|
92
|
+
let init_acc = manager.options.init_account;
|
|
93
|
+
if (init_acc) {
|
|
94
|
+
title = `${init_acc.name} - ${title}`;
|
|
95
|
+
}
|
|
96
|
+
let tml = `
|
|
95
97
|
<html>
|
|
96
98
|
<head>
|
|
97
99
|
<meta charset="UTF-8">
|
|
@@ -103,21 +105,21 @@ const set_page = (route, manager)=>{
|
|
|
103
105
|
|
|
104
106
|
</head>
|
|
105
107
|
|
|
106
|
-
<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
|
|
108
|
+
<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>`;
|
|
107
109
|
|
|
108
|
-
|
|
110
|
+
tml = `${tml}${header(route)}`;
|
|
109
111
|
|
|
110
|
-
|
|
112
|
+
tml = `${tml}<script>${header_script(manager)}</script>`;
|
|
111
113
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
if (route !== "") {
|
|
115
|
+
tml = `${tml}${forms(route, manager)}`;
|
|
116
|
+
}
|
|
115
117
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
tml = `${tml}${footer(route)}`;
|
|
119
|
+
tml = `${tml}<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script></div></body> </html>
|
|
120
|
+
`;
|
|
119
121
|
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
+
return tml;
|
|
123
|
+
};
|
|
122
124
|
|
|
123
|
-
export {set_page}
|
|
125
|
+
export { set_page };
|
package/html/load.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const script = (manager)=> {
|
|
2
|
-
|
|
1
|
+
const script = (manager) => {
|
|
2
|
+
return `
|
|
3
3
|
const account_selection_el = document.getElementById('account_selection'), address_el = document.getElementById('address'),
|
|
4
4
|
sequence_el = document.getElementById('sequence'),
|
|
5
5
|
id_el = document.getElementById('ID'),
|
|
@@ -96,14 +96,15 @@ load.addEventListener('click', e=>{
|
|
|
96
96
|
|
|
97
97
|
ftch('/load', data)
|
|
98
98
|
.then(res=>{
|
|
99
|
+
console.log(res)
|
|
99
100
|
message_box.textContent = res.done ? 'Sequence loaded successfully! - ' + res.datapath : res.message
|
|
100
101
|
return;
|
|
101
102
|
}).catch(err=>console.log(err))
|
|
102
103
|
|
|
103
|
-
})
|
|
104
|
-
}
|
|
104
|
+
}) `;
|
|
105
|
+
};
|
|
105
106
|
|
|
106
|
-
const load = (manager)=>{
|
|
107
|
+
const load = (manager) => {
|
|
107
108
|
let tml = `<!-- Container for the Load form -->
|
|
108
109
|
<div class="container my-5">
|
|
109
110
|
<div class="row justify-content-center">
|
|
@@ -155,11 +156,11 @@ const load = (manager)=>{
|
|
|
155
156
|
<div id="message-box" class="mt-3"></div>
|
|
156
157
|
</div>
|
|
157
158
|
</div>
|
|
158
|
-
</div
|
|
159
|
+
</div>`;
|
|
159
160
|
|
|
160
|
-
|
|
161
|
+
tml = `${tml} <script>${script(manager)}</script>`;
|
|
161
162
|
|
|
162
|
-
|
|
163
|
-
}
|
|
163
|
+
return tml;
|
|
164
|
+
};
|
|
164
165
|
|
|
165
|
-
export default load
|
|
166
|
+
export default load;
|
package/package.json
CHANGED
package/utils/create_server.js
CHANGED
|
@@ -4,6 +4,36 @@ import { generate_random_string } from "generalised-datastore/utils/functions.js
|
|
|
4
4
|
let PORT = Number(process.env.PORT) || 1408,
|
|
5
5
|
account_uids = {};
|
|
6
6
|
|
|
7
|
+
const set_account_uid = async (uid, account_name, manager) => {
|
|
8
|
+
account_uids[uid] = account_name;
|
|
9
|
+
manager.oracle.write_local(
|
|
10
|
+
`.account_uids/${uid}`,
|
|
11
|
+
JSON.stringify({
|
|
12
|
+
account_name,
|
|
13
|
+
timestamp: Date.now(),
|
|
14
|
+
})
|
|
15
|
+
);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const get_account = async (uid, manager) => {
|
|
19
|
+
if (account_uids[uid]) return account_uids[uid];
|
|
20
|
+
let account_name = await manager.oracle.read_local(`.account_uids/${uid}`);
|
|
21
|
+
|
|
22
|
+
if (account_name) account_name = JSON.parse(account_name);
|
|
23
|
+
|
|
24
|
+
if (account_name && account_name.timestamp) {
|
|
25
|
+
// UID valid for a day
|
|
26
|
+
if (Date.now() - account_name.timestamp > 86400000) {
|
|
27
|
+
delete account_uids[uid];
|
|
28
|
+
return null;
|
|
29
|
+
} else {
|
|
30
|
+
account_name = account_name.account_name;
|
|
31
|
+
account_uids[uid] = account_name;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return account_name;
|
|
35
|
+
};
|
|
36
|
+
|
|
7
37
|
export const handle_routes = async (req, res, manager, app) => {
|
|
8
38
|
try {
|
|
9
39
|
// CORS
|
|
@@ -69,7 +99,7 @@ export const handle_routes = async (req, res, manager, app) => {
|
|
|
69
99
|
result = { message: "Incorrect password." };
|
|
70
100
|
} else {
|
|
71
101
|
const uid = generate_random_string(16, "alnum");
|
|
72
|
-
|
|
102
|
+
await set_account_uid(uid, data.name, manager);
|
|
73
103
|
result = { uid, message: "Account signed-in successfully." };
|
|
74
104
|
}
|
|
75
105
|
} else {
|
|
@@ -78,7 +108,7 @@ export const handle_routes = async (req, res, manager, app) => {
|
|
|
78
108
|
});
|
|
79
109
|
if (new_acc) {
|
|
80
110
|
const uid = generate_random_string(16, "alnum");
|
|
81
|
-
|
|
111
|
+
await set_account_uid(uid, data.name, manager);
|
|
82
112
|
result = { uid, message: "Account created successfully." };
|
|
83
113
|
} else {
|
|
84
114
|
result = { message: "Account creation failed." };
|
|
@@ -94,14 +124,21 @@ export const handle_routes = async (req, res, manager, app) => {
|
|
|
94
124
|
case "/load":
|
|
95
125
|
case "/run":
|
|
96
126
|
case "/parse": {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
127
|
+
let account_name = await get_account(data.account, manager),
|
|
128
|
+
message;
|
|
129
|
+
if (account_name && typeof account_name === "object") {
|
|
130
|
+
message = `Session expired. Please sign in again.`;
|
|
131
|
+
account_name = null;
|
|
132
|
+
}
|
|
133
|
+
if (!account_name) {
|
|
134
|
+
result = {
|
|
135
|
+
message: message || `Account ${data.account} not found`,
|
|
136
|
+
};
|
|
100
137
|
} else {
|
|
101
|
-
|
|
102
|
-
if (req.url === "/load") result = await
|
|
103
|
-
if (req.url === "/run") result = await
|
|
104
|
-
if (req.url === "/parse") result = await
|
|
138
|
+
let account_obj = await manager.get_account(account_name);
|
|
139
|
+
if (req.url === "/load") result = await account_obj.load(data);
|
|
140
|
+
if (req.url === "/run") result = await account_obj.run(data);
|
|
141
|
+
if (req.url === "/parse") result = await account_obj.parse(data);
|
|
105
142
|
}
|
|
106
143
|
break;
|
|
107
144
|
}
|