godprotocol 1.2.28 → 1.2.29
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/Account.js +3 -15
- package/package.json +1 -1
- package/utils/__create_server.js +0 -121
package/Objects/Account.js
CHANGED
|
@@ -24,11 +24,7 @@ class Account extends Utils {
|
|
|
24
24
|
|
|
25
25
|
if (compiler) {
|
|
26
26
|
!from_reload &&
|
|
27
|
-
(await this.manager.oracle.write(
|
|
28
|
-
account: this.physical_address,
|
|
29
|
-
prefix: ".codes",
|
|
30
|
-
address: phy,
|
|
31
|
-
}));
|
|
27
|
+
(await this.manager.oracle.write(`.codes/${phy}.air`, sequence));
|
|
32
28
|
|
|
33
29
|
sequence = await this.compiler.to_sequence(sequence, address);
|
|
34
30
|
sequence = sequence[0];
|
|
@@ -50,11 +46,7 @@ class Account extends Utils {
|
|
|
50
46
|
config = await folder.readone(_id ? { _id } : null);
|
|
51
47
|
|
|
52
48
|
if (!config) {
|
|
53
|
-
let code = await this.manager.oracle.read(
|
|
54
|
-
account: this.physical_address,
|
|
55
|
-
prefix: ".codes",
|
|
56
|
-
address: phy,
|
|
57
|
-
});
|
|
49
|
+
let code = await this.manager.oracle.read(`.codes/${phy}.air`);
|
|
58
50
|
if (code) {
|
|
59
51
|
code = await this.compiler.to_sequence(code, address);
|
|
60
52
|
code = code[0];
|
|
@@ -115,11 +107,7 @@ class Account extends Utils {
|
|
|
115
107
|
let phy = `${this.physical_address}/${address}`;
|
|
116
108
|
|
|
117
109
|
if (from === ".codes") {
|
|
118
|
-
let res = await this.manager.oracle.read(
|
|
119
|
-
account: this.physical_address,
|
|
120
|
-
address: phy,
|
|
121
|
-
prefix: from,
|
|
122
|
-
});
|
|
110
|
+
let res = await this.manager.oracle.read(`.codes/${phy}.air`);
|
|
123
111
|
if (res) {
|
|
124
112
|
return { result: res };
|
|
125
113
|
} else return { message: "Code not found" };
|
package/package.json
CHANGED
package/utils/__create_server.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
// import https from "https";
|
|
2
|
-
import http from "http";
|
|
3
|
-
import {set_page} from '../html/index.js'
|
|
4
|
-
import { generate_random_string } from "generalised-datastore/utils/functions.js";
|
|
5
|
-
|
|
6
|
-
let PORT = Number(process.env.PORT) || 1408, account_uids = new Object();
|
|
7
|
-
|
|
8
|
-
const handle_routes = async(req, res, manager, app) => {
|
|
9
|
-
let data = "";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (req.method === "OPTIONS") {
|
|
13
|
-
res.writeHead(204, {
|
|
14
|
-
"Access-Control-Allow-Origin": "*",
|
|
15
|
-
"Access-Control-Allow-Headers": "Content-Type",
|
|
16
|
-
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
|
|
17
|
-
});
|
|
18
|
-
res.end();
|
|
19
|
-
return;
|
|
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");
|
|
30
|
-
|
|
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
|
-
|
|
39
|
-
req.on("data", (chunk) => {
|
|
40
|
-
data += chunk;
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
res.writeHead(200, { "Content-type": "application/json" });
|
|
44
|
-
|
|
45
|
-
req.on("end", async () => {
|
|
46
|
-
if (!data) {
|
|
47
|
-
res.writeHead(400, { "Content-Type": "application/json" });
|
|
48
|
-
res.end(JSON.stringify({ error: "Request body cannot be empty" }));
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
data = JSON.parse(data)
|
|
52
|
-
let result;
|
|
53
|
-
|
|
54
|
-
if (req.url === '/create_account'){
|
|
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
|
-
|
|
70
|
-
res.end(JSON.stringify(result))
|
|
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]
|
|
77
|
-
|
|
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)
|
|
88
|
-
|
|
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
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
req.on("error", (e) => {
|
|
100
|
-
res.writeHead(500, { "Content-Type": "application/json" });
|
|
101
|
-
res.end(JSON.stringify({ status: "error", error_message: e.message }));
|
|
102
|
-
});
|
|
103
|
-
}else if (app){
|
|
104
|
-
return app(req, res);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const create_server = (settings) => {
|
|
110
|
-
settings = settings || {};
|
|
111
|
-
let { port, manager } = settings;
|
|
112
|
-
|
|
113
|
-
port = port || PORT;
|
|
114
|
-
|
|
115
|
-
let handler = async(req, res) => await handle_routes(req, res, manager, manager.options.app)
|
|
116
|
-
|
|
117
|
-
return handler;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export default create_server;
|
|
121
|
-
export { PORT };
|