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/utils/create_server.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import https from "https";
|
|
1
|
+
// import https from "https";
|
|
2
2
|
import http from "http";
|
|
3
|
+
import {set_page} from '../html/index.js'
|
|
4
|
+
import { generate_random_string } from "generalised-datastore/utils/functions.js";
|
|
3
5
|
|
|
4
|
-
let PORT = Number(process.env.PORT) || 1408;
|
|
6
|
+
let PORT = Number(process.env.PORT) || 1408, account_uids = new Object();
|
|
5
7
|
|
|
6
|
-
const handle_routes = (req, res, manager, app) => {
|
|
8
|
+
const handle_routes = async(req, res, manager, app) => {
|
|
7
9
|
let data = "";
|
|
8
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
9
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
10
10
|
|
|
11
|
+
|
|
11
12
|
if (req.method === "OPTIONS") {
|
|
12
13
|
res.writeHead(204, {
|
|
13
14
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -17,42 +18,82 @@ const handle_routes = (req, res, manager, app) => {
|
|
|
17
18
|
res.end();
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
21
|
+
if (req.url === '/'){
|
|
22
|
+
res.writeHead(200, {'Content-Type': 'text/html'})
|
|
23
|
+
res.end(set_page(req.url, manager))
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (['/create_account', '/load', '/run', '/parse', '/oracle'].includes(req.url)){
|
|
28
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
29
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
20
30
|
|
|
21
|
-
|
|
31
|
+
if (req.method === 'GET'){
|
|
32
|
+
let tml = set_page(req.url.slice(1), manager)
|
|
33
|
+
|
|
34
|
+
res.writeHead(200, {'Content-Type': 'text/html'})
|
|
35
|
+
res.end(tml)
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
22
39
|
req.on("data", (chunk) => {
|
|
23
40
|
data += chunk;
|
|
24
41
|
});
|
|
25
42
|
|
|
43
|
+
res.writeHead(200, { "Content-type": "application/json" });
|
|
44
|
+
|
|
26
45
|
req.on("end", async () => {
|
|
27
46
|
if (!data) {
|
|
28
47
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
29
48
|
res.end(JSON.stringify({ error: "Request body cannot be empty" }));
|
|
30
49
|
return;
|
|
31
50
|
}
|
|
32
|
-
|
|
33
51
|
data = JSON.parse(data)
|
|
34
52
|
let result;
|
|
35
53
|
|
|
36
54
|
if (req.url === '/create_account'){
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
let acc = await manager.get_account(data.name)
|
|
56
|
+
if (acc){
|
|
57
|
+
if(!await acc.verify(data.password)){
|
|
58
|
+
result = {message: "Incorrect password."}
|
|
59
|
+
} else {
|
|
60
|
+
let uid = generate_random_string(16, 'alnum')
|
|
61
|
+
account_uids[uid] = data.name
|
|
62
|
+
result = {uid, message: "Account signed-in successfully."}
|
|
63
|
+
}
|
|
64
|
+
}else {
|
|
65
|
+
result = await manager.add_account(data.name, {password: data.password})
|
|
66
|
+
result = result ? {uid: generate_random_string(16, 'alnum'), message: 'Account created successfully.'} : {message: 'Incorrect password.'}
|
|
67
|
+
account_uids[result.uid] = data.name
|
|
68
|
+
}
|
|
69
|
+
|
|
42
70
|
res.end(JSON.stringify(result))
|
|
43
|
-
}else if(req.url === '/
|
|
44
|
-
|
|
45
|
-
|
|
71
|
+
} else if (req.url === '/oracle') {
|
|
72
|
+
// console.log(data)
|
|
73
|
+
let reslt = await manager.oracle.call(data)
|
|
74
|
+
res.end(JSON.stringify(reslt))
|
|
75
|
+
} else {
|
|
76
|
+
let account = account_uids[data.account]
|
|
46
77
|
|
|
47
|
-
|
|
78
|
+
if (!account){
|
|
79
|
+
return res.end(JSON.stringify({message: `Account:${data.account} is not found.`}))
|
|
80
|
+
}
|
|
81
|
+
account = await manager.get_account(account)
|
|
82
|
+
if(req.url === '/load'){
|
|
83
|
+
result = await account.load(data)
|
|
84
|
+
|
|
85
|
+
res.end(JSON.stringify({datapath: result, done: true}))
|
|
86
|
+
}else if(req.url === '/run'){
|
|
87
|
+
result = await account.run(data)
|
|
48
88
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
89
|
+
res.end(JSON.stringify({thread_id: result.thread_id, callback: result.callback}))
|
|
90
|
+
}else if(req.url === '/parse'){
|
|
91
|
+
result = await account.parse(data)
|
|
92
|
+
|
|
93
|
+
res.end(result? JSON.stringify(result): JSON.stringify(null))
|
|
94
|
+
}
|
|
55
95
|
}
|
|
96
|
+
|
|
56
97
|
});
|
|
57
98
|
|
|
58
99
|
req.on("error", (e) => {
|
|
@@ -60,7 +101,7 @@ const handle_routes = (req, res, manager, app) => {
|
|
|
60
101
|
res.end(JSON.stringify({ status: "error", error_message: e.message }));
|
|
61
102
|
});
|
|
62
103
|
}else if (app){
|
|
63
|
-
app(req, res);
|
|
104
|
+
return app(req, res);
|
|
64
105
|
}
|
|
65
106
|
|
|
66
107
|
};
|
|
@@ -68,17 +109,16 @@ const handle_routes = (req, res, manager, app) => {
|
|
|
68
109
|
const create_server = async (settings) => {
|
|
69
110
|
return new Promise((resolve, reject) => {
|
|
70
111
|
settings = settings || {};
|
|
71
|
-
let { port,
|
|
112
|
+
let { port, manager } = settings;
|
|
72
113
|
|
|
73
114
|
port = port || PORT;
|
|
74
115
|
|
|
75
|
-
// console.log(__dirname)
|
|
76
116
|
let server = http.createServer(
|
|
77
117
|
// {
|
|
78
118
|
// key: fs.readFileSync(`${__dirname}/server.key`),
|
|
79
119
|
// cert: fs.readFileSync(`${__dirname}/server.cert`),
|
|
80
120
|
// },
|
|
81
|
-
(req, res) => handle_routes(req, res, manager, app)
|
|
121
|
+
async(req, res) => await handle_routes(req, res, manager, manager.options.app)
|
|
82
122
|
);
|
|
83
123
|
|
|
84
124
|
server.listen(port, () => {
|
package/utils/hash.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import crypto from 'crypto'
|
|
2
2
|
|
|
3
3
|
const hash = (data, alg) => {
|
|
4
|
-
|
|
4
|
+
alg = (alg || "sha256").replace(/-/g, '').toLowerCase()
|
|
5
|
+
let hash = crypto.createHash(alg);
|
|
5
6
|
|
|
6
7
|
hash.update(data);
|
|
7
8
|
|
package/utils/ops.js
CHANGED
package/utils/services.js
CHANGED
|
@@ -1,36 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const get_request = async (payload, cb) => {
|
|
4
|
-
let req = http.request(
|
|
5
|
-
{
|
|
6
|
-
...payload.options,
|
|
7
|
-
method: "GET",
|
|
8
|
-
headers: {
|
|
9
|
-
"Content-Type": "application/json",
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
(res) => {
|
|
13
|
-
let data = "";
|
|
14
|
-
|
|
15
|
-
res.on("data", (chunk) => {
|
|
16
|
-
data += chunk;
|
|
17
|
-
// cb && cb(chunk);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
res.on("end", () => {
|
|
21
|
-
cb && cb(data);
|
|
22
|
-
// console.log("Response:", data);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
req.on("error", (e) => {
|
|
28
|
-
cb && cb(e.message);
|
|
29
|
-
console.error(`Problem with request: ${e.message}`);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
req.end();
|
|
33
|
-
};
|
|
1
|
+
import http from 'http'
|
|
34
2
|
|
|
35
3
|
const post_request = (payload, cb) => {
|
|
36
4
|
// let options = {
|
|
@@ -43,27 +11,26 @@ const post_request = (payload, cb) => {
|
|
|
43
11
|
// 'Content-Length': Buffer.byteLength(postData),
|
|
44
12
|
// },
|
|
45
13
|
// };
|
|
46
|
-
console.log(payload);
|
|
47
14
|
|
|
15
|
+
// console.log(payload)
|
|
48
16
|
return new Promise((resolve, reject) => {
|
|
49
|
-
let data =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
: payload.data;
|
|
53
|
-
console.log('uh')
|
|
54
|
-
|
|
55
|
-
let req = http.request(
|
|
56
|
-
{
|
|
17
|
+
let data = payload.data
|
|
18
|
+
|
|
19
|
+
let header = {
|
|
57
20
|
...payload.options,
|
|
58
|
-
method: "POST",
|
|
21
|
+
method: payload.options.method || "POST",
|
|
59
22
|
headers: {
|
|
60
|
-
...payload.headers,
|
|
23
|
+
...payload.options.headers,
|
|
61
24
|
"Content-Type": "application/json",
|
|
62
|
-
"Content-Length": Buffer.byteLength(data),
|
|
63
25
|
},
|
|
64
26
|
rejectUnauthorized: false,
|
|
65
|
-
minVersion: "TLSv1.2",
|
|
66
|
-
}
|
|
27
|
+
// minVersion: "TLSv1.2",
|
|
28
|
+
}
|
|
29
|
+
if(payload.data){
|
|
30
|
+
header["Content-Length"] = Buffer.byteLength(data)
|
|
31
|
+
}
|
|
32
|
+
let req = http.request(
|
|
33
|
+
header,
|
|
67
34
|
(res) => {
|
|
68
35
|
let data = "";
|
|
69
36
|
|
|
@@ -72,8 +39,8 @@ const post_request = (payload, cb) => {
|
|
|
72
39
|
});
|
|
73
40
|
|
|
74
41
|
res.on("end", () => {
|
|
75
|
-
console.log('hey')
|
|
76
|
-
resolve(JSON.parse(data));
|
|
42
|
+
// console.log('hey')
|
|
43
|
+
resolve(data && JSON.parse(data));
|
|
77
44
|
// console.log("Response:", data);
|
|
78
45
|
});
|
|
79
46
|
}
|
|
@@ -84,10 +51,10 @@ const post_request = (payload, cb) => {
|
|
|
84
51
|
console.error(`Problem with request: ${e.message}`);
|
|
85
52
|
});
|
|
86
53
|
|
|
87
|
-
req.write(data);
|
|
54
|
+
data && req.write(data);
|
|
88
55
|
|
|
89
56
|
req.end();
|
|
90
57
|
});
|
|
91
58
|
};
|
|
92
59
|
|
|
93
|
-
export {
|
|
60
|
+
export { post_request };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import net from "net";
|
|
2
|
+
|
|
3
|
+
const socket_server = (PORT)=>{
|
|
4
|
+
// Create a TCP server
|
|
5
|
+
const server = net.createServer((socket) => {
|
|
6
|
+
console.log("Client connected");
|
|
7
|
+
|
|
8
|
+
// Handle incoming data
|
|
9
|
+
socket.on("data", (data) => {
|
|
10
|
+
console.log(`Received: ${data.toString()}`);
|
|
11
|
+
// Echo the data back to the client
|
|
12
|
+
socket.write(`Echo: ${data}`);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Handle client disconnection
|
|
16
|
+
socket.on("end", () => {
|
|
17
|
+
console.log("Client disconnected");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Handle errors
|
|
21
|
+
socket.on("error", (err) => {
|
|
22
|
+
console.error(`Socket error: ${err.message}`);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Start the server
|
|
27
|
+
server.listen(PORT, () => {
|
|
28
|
+
console.log(`...GOD Socket server running on port ${PORT}`);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return server
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export default socket_server
|