godprotocol 1.2.36 → 1.2.50
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 +1 -0
- package/Objects/Manager.js +8 -29
- package/Objects/Oracle.js +20 -16
- package/package.json +1 -1
- package/utils/services.js +29 -35
package/Objects/Account.js
CHANGED
package/Objects/Manager.js
CHANGED
|
@@ -379,10 +379,14 @@ class Manager {
|
|
|
379
379
|
this.served = true;
|
|
380
380
|
this.oracle = this.options.oracle;
|
|
381
381
|
if (this.options.init_account) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
382
|
+
console.log(
|
|
383
|
+
"Initiate manager account...",
|
|
384
|
+
this.options.init_account.name
|
|
385
|
+
);
|
|
386
|
+
// await this.add_account(this.options.init_account.name, {
|
|
387
|
+
// password: this.options.init_account.password,
|
|
388
|
+
// init: true,
|
|
389
|
+
// });
|
|
386
390
|
|
|
387
391
|
cb && cb();
|
|
388
392
|
}
|
|
@@ -406,18 +410,6 @@ class Manager {
|
|
|
406
410
|
return acc;
|
|
407
411
|
};
|
|
408
412
|
|
|
409
|
-
get_from_repo = async (address, options = {}) => {
|
|
410
|
-
let acc = this.get_acc(options);
|
|
411
|
-
|
|
412
|
-
address = `.storage/${acc}/${address}/__literal__`;
|
|
413
|
-
let content = await this.oracle.get_from_repos(address, {
|
|
414
|
-
count: 1,
|
|
415
|
-
args: options,
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
return content && JSON.parse(content);
|
|
419
|
-
};
|
|
420
|
-
|
|
421
413
|
get_acc = (options) => {
|
|
422
414
|
let acc = options.account;
|
|
423
415
|
if (!acc) {
|
|
@@ -429,19 +421,6 @@ class Manager {
|
|
|
429
421
|
return acc;
|
|
430
422
|
};
|
|
431
423
|
|
|
432
|
-
set_to_repo = async (address, content, options = {}) => {
|
|
433
|
-
let acc = this.get_acc(options);
|
|
434
|
-
|
|
435
|
-
address = `.storage/${acc}/${address}/__literal__`;
|
|
436
|
-
let response = await this.oracle.set_to_repos(
|
|
437
|
-
address,
|
|
438
|
-
JSON.stringify(content),
|
|
439
|
-
{ count: 1, args: options }
|
|
440
|
-
);
|
|
441
|
-
|
|
442
|
-
return response;
|
|
443
|
-
};
|
|
444
|
-
|
|
445
424
|
get_account = async (name) => {
|
|
446
425
|
let acc = this.accounts[name];
|
|
447
426
|
if (!acc) {
|
package/Objects/Oracle.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { post_request } from "../utils/services.js";
|
|
2
2
|
|
|
3
3
|
class Oracle_client {
|
|
4
|
-
constructor(server) {
|
|
4
|
+
constructor(server, options = {}) {
|
|
5
5
|
this.server = server;
|
|
6
|
+
this.manager_key = options.manager_key;
|
|
6
7
|
|
|
7
8
|
this.repo_cache = new Object();
|
|
8
9
|
this.repos = [];
|
|
@@ -20,38 +21,40 @@ class Oracle_client {
|
|
|
20
21
|
return repo_;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
write_local = async (path, content) => {
|
|
24
|
+
write_local = async (path, content, options) => {
|
|
24
25
|
if (this.local) {
|
|
25
|
-
await this.local.write(path, content);
|
|
26
|
+
await this.local.write(path, content, options);
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
|
|
29
|
-
read_local = async (path) => {
|
|
30
|
+
read_local = async (path, options) => {
|
|
30
31
|
if (this.local) {
|
|
31
|
-
let content = await this.local.read(path);
|
|
32
|
+
let content = await this.local.read(path, options);
|
|
32
33
|
return content;
|
|
33
34
|
}
|
|
34
35
|
return null;
|
|
35
36
|
};
|
|
36
37
|
|
|
37
|
-
write = async (path, content) => {
|
|
38
|
+
write = async (path, content, options) => {
|
|
38
39
|
await this.fetch({
|
|
39
40
|
method: Array.isArray(content) ? "write_bulk" : "write",
|
|
40
|
-
args: { path, content },
|
|
41
|
+
args: { path, content, options },
|
|
41
42
|
});
|
|
42
43
|
};
|
|
43
44
|
|
|
44
|
-
read = async (path) => {
|
|
45
|
+
read = async (path, options = {}) => {
|
|
45
46
|
let repo = this.repo_cache[path],
|
|
46
47
|
content;
|
|
47
48
|
|
|
48
49
|
if (repo) {
|
|
49
|
-
|
|
50
|
+
if (options.decrypt === true) options.decrypt = this.manager_key;
|
|
51
|
+
|
|
52
|
+
content = await repo.read(path, { decrypt: options.decrypt });
|
|
50
53
|
}
|
|
51
54
|
if (!content) {
|
|
52
55
|
let response = await this.fetch({
|
|
53
56
|
method: "read",
|
|
54
|
-
args: { path },
|
|
57
|
+
args: { path, options },
|
|
55
58
|
});
|
|
56
59
|
content = response && response.content;
|
|
57
60
|
if (content) {
|
|
@@ -131,7 +134,6 @@ class Oracle_client {
|
|
|
131
134
|
},
|
|
132
135
|
});
|
|
133
136
|
if (!auth) return;
|
|
134
|
-
console.log("Oracle authenticated:", auth);
|
|
135
137
|
|
|
136
138
|
if (auth.token) {
|
|
137
139
|
if (local) {
|
|
@@ -146,20 +148,20 @@ class Oracle_client {
|
|
|
146
148
|
get_auth_token = async () => {
|
|
147
149
|
let token = this.auth_token;
|
|
148
150
|
if (!token) {
|
|
149
|
-
token = await this.read_local(this.token_addr
|
|
151
|
+
token = await this.read_local(this.token_addr, {
|
|
152
|
+
decrypt: this.manager_key,
|
|
153
|
+
});
|
|
150
154
|
if (token && token.expired) token = null;
|
|
151
|
-
console.log("read token:", token);
|
|
152
155
|
if (token) {
|
|
153
156
|
token = JSON.parse(token);
|
|
154
157
|
this.auth_token = token.token;
|
|
155
158
|
this.client = token.client;
|
|
156
159
|
}
|
|
157
160
|
}
|
|
158
|
-
console.log("Oracle auth token:", this.auth_token);
|
|
159
161
|
return this.auth_token;
|
|
160
162
|
};
|
|
161
163
|
|
|
162
|
-
token_addr = `.
|
|
164
|
+
token_addr = `.clients/sign`;
|
|
163
165
|
|
|
164
166
|
set_auth_token = async (token) => {
|
|
165
167
|
let obj = { client: this.client, token };
|
|
@@ -168,7 +170,9 @@ class Oracle_client {
|
|
|
168
170
|
|
|
169
171
|
obj.expired = true;
|
|
170
172
|
}
|
|
171
|
-
await this.write_local(this.token_addr, JSON.stringify(obj)
|
|
173
|
+
await this.write_local(this.token_addr, JSON.stringify(obj), {
|
|
174
|
+
encrypt: this.manager_key,
|
|
175
|
+
});
|
|
172
176
|
};
|
|
173
177
|
|
|
174
178
|
cloth_repo = async (repo) => {
|
package/package.json
CHANGED
package/utils/services.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import http from
|
|
2
|
-
import https from
|
|
1
|
+
import http from "http";
|
|
2
|
+
import https from "https";
|
|
3
3
|
|
|
4
4
|
const post_request = (payload, cb) => {
|
|
5
5
|
// let options = {
|
|
@@ -13,41 +13,35 @@ const post_request = (payload, cb) => {
|
|
|
13
13
|
// },
|
|
14
14
|
// };
|
|
15
15
|
|
|
16
|
-
// console.log(payload)
|
|
17
16
|
return new Promise((resolve, reject) => {
|
|
18
|
-
let data = payload.data
|
|
19
|
-
|
|
17
|
+
let data = payload.data;
|
|
18
|
+
|
|
20
19
|
let header = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
let req = mod.request(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
resolve(data && JSON.parse(data));
|
|
47
|
-
// console.log("Response:", data);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
);
|
|
20
|
+
...payload.options,
|
|
21
|
+
method: payload.options.method || "POST",
|
|
22
|
+
headers: {
|
|
23
|
+
...payload.options.headers,
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
},
|
|
26
|
+
rejectUnauthorized: false,
|
|
27
|
+
// minVersion: "TLSv1.2",
|
|
28
|
+
};
|
|
29
|
+
if (payload.data) {
|
|
30
|
+
header["Content-Length"] = Buffer.byteLength(data);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let mod = process.env.LOCALHOST ? http : https;
|
|
34
|
+
let req = mod.request(header, (res) => {
|
|
35
|
+
let data = "";
|
|
36
|
+
|
|
37
|
+
res.on("data", (chunk) => {
|
|
38
|
+
data += chunk;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
res.on("end", () => {
|
|
42
|
+
resolve(data && JSON.parse(data));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
51
45
|
|
|
52
46
|
req.on("error", (e) => {
|
|
53
47
|
reject(e);
|