godprotocol 1.1.32 → 1.2.1
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 +287 -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/Objects/Oracle.js
CHANGED
|
@@ -1,268 +1,345 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import Fs from "godprotocol/repos/fs.js";
|
|
2
|
+
import Github from "godprotocol/repos/github.js";
|
|
3
|
+
import Handlers from "godprotocol/utils/oracle_handlers.js";
|
|
4
|
+
import { post_request } from "godprotocol/utils/services.js";
|
|
5
|
+
|
|
6
|
+
class Oracle extends Handlers{
|
|
7
|
+
constructor(server, mirror) {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.server = server
|
|
11
|
+
this.mirror = mirror;
|
|
12
|
+
this.repos = new Array()
|
|
13
|
+
this.remotes = new Array()
|
|
14
|
+
}
|
|
4
15
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.
|
|
16
|
+
add_repo = async (repository)=>{
|
|
17
|
+
let {filter, repo} = repository
|
|
18
|
+
if (await this.get_repo(repo.type, repo.options.name))
|
|
19
|
+
return;
|
|
8
20
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
21
|
+
switch(repo.type){
|
|
22
|
+
case 'fs':
|
|
23
|
+
repo = new Fs(repo.options)
|
|
24
|
+
break
|
|
25
|
+
case 'github':
|
|
26
|
+
repo = new Github(repo.options)
|
|
27
|
+
break
|
|
28
|
+
}
|
|
29
|
+
this.repos.push({filter, repo})
|
|
12
30
|
|
|
13
|
-
|
|
14
|
-
if(
|
|
31
|
+
if(!this.manager) return;
|
|
32
|
+
if (this.server_match(this.manager.server, this.server)){
|
|
33
|
+
for (let r=0; r< this.remotes.length; r++){
|
|
34
|
+
let remote = this.remotes[r]
|
|
15
35
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
36
|
+
await this.fetch({
|
|
37
|
+
method: 'add_repo',
|
|
38
|
+
arg: {...repo}
|
|
39
|
+
}, remote)
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
await this.fetch({
|
|
43
|
+
method: 'add_repo',
|
|
44
|
+
arg: {...repo}
|
|
45
|
+
}, this.server)
|
|
22
46
|
}
|
|
23
47
|
}
|
|
24
48
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
49
|
+
call = async(payload)=>{
|
|
50
|
+
let {method, arg} = payload, result = {};
|
|
51
|
+
|
|
52
|
+
switch(method){
|
|
53
|
+
case 'update_servers':
|
|
54
|
+
let addr = `.oracle/${arg.account}/.configs`
|
|
55
|
+
let servers = await this.get_from_repos(addr)
|
|
56
|
+
if (servers){
|
|
57
|
+
servers = JSON.parse(servers)
|
|
58
|
+
if (servers.find(s=>this.server_match(s, arg.server))){
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
servers.push(arg.server)
|
|
62
|
+
}else servers = [arg.server]
|
|
63
|
+
|
|
64
|
+
await this.set_to_repos(addr, JSON.stringify(servers))
|
|
65
|
+
break;
|
|
66
|
+
case 'update_accounts':
|
|
67
|
+
let a_addr = `.oracle/${arg.address}/.configs`
|
|
68
|
+
let accs = await this.get_from_repos(a_addr)
|
|
69
|
+
if (accs){
|
|
70
|
+
accs = JSON.parse(accs)
|
|
71
|
+
if (accs.includes(arg.account)){
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
accs.push(arg.account)
|
|
75
|
+
}else accs = [arg.account]
|
|
76
|
+
|
|
77
|
+
await this.set_to_repos(a_addr, JSON.stringify(accs))
|
|
78
|
+
break
|
|
79
|
+
case 'get_accounts':
|
|
80
|
+
result = this.get_accounts(arg.address, true)
|
|
81
|
+
break
|
|
82
|
+
case 'get_servers':
|
|
83
|
+
result = this.get_servers(arg.account, true)
|
|
84
|
+
break
|
|
85
|
+
case 'write':
|
|
86
|
+
await this.set_to_repos(`${arg.prefix}/${arg.path}`, arg.content)
|
|
87
|
+
break;
|
|
88
|
+
case 'read':
|
|
89
|
+
let res = await this.get_from_repos(`${arg.prefix}/${arg.path}`)
|
|
90
|
+
result = {content: res}
|
|
91
|
+
break;
|
|
92
|
+
case 'fs':
|
|
93
|
+
let repo = await this.get_repo('fs', arg.name)
|
|
94
|
+
result = await repo.call(arg.payload)
|
|
95
|
+
break
|
|
96
|
+
case 'sync':
|
|
97
|
+
let repos = this.string_repos()
|
|
98
|
+
await this.push_remote(arg.manager_server)
|
|
99
|
+
result = {repos}
|
|
100
|
+
break
|
|
101
|
+
case 'add_repo':
|
|
102
|
+
await this.add_repo(arg)
|
|
103
|
+
break
|
|
104
|
+
}
|
|
31
105
|
|
|
32
|
-
|
|
33
|
-
}
|
|
106
|
+
return result
|
|
107
|
+
}
|
|
34
108
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
try{
|
|
38
|
-
content = this.fs.readFileSync(`${this.base}/${path}`, {encoding:'utf-8'})
|
|
39
|
-
content = JSON.parse(content)
|
|
40
|
-
}catch(e){}
|
|
109
|
+
push_remote = async(remote)=>{
|
|
110
|
+
if (this.remotes.find(rem=>this.server_match(rem, remote))) return;
|
|
41
111
|
|
|
42
|
-
|
|
112
|
+
this.remotes.push(remote)
|
|
43
113
|
}
|
|
44
114
|
|
|
45
|
-
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
config = await this.read(`${path}/.config`) || {};
|
|
51
|
-
|
|
52
|
-
if (!config.current) {
|
|
53
|
-
if (options.config){
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (options.sibling){
|
|
60
|
-
if (config.sibling){
|
|
61
|
-
let res = await this.read(`${config.sibling}`)
|
|
62
|
-
result = res.content
|
|
63
|
-
}
|
|
64
|
-
}else{
|
|
65
|
-
if (config.current){
|
|
66
|
-
let res = await this.read(`${config.current}/.config`)
|
|
67
|
-
|
|
68
|
-
let value = await this.read(`${config.current}/${res.index-1}`)
|
|
69
|
-
if(!value && res.current && !res.current.includes('/')){
|
|
70
|
-
value = await this.read(`${config.current}/${res.current}`)
|
|
71
|
-
}
|
|
72
|
-
if(options.config){
|
|
73
|
-
result = typeof value.content === 'string'? JSON.parse(value.content): value.content;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
115
|
+
string_repos = ()=>{
|
|
116
|
+
let repos = new Array();
|
|
117
|
+
for(let r=0; r< this.repos.length; r++){
|
|
118
|
+
let {filter, repo} = this.repos[r];
|
|
119
|
+
repos.push({filter, repo:{type: repo.type, options: repo.objectify()}})
|
|
76
120
|
}
|
|
121
|
+
return repos;
|
|
122
|
+
}
|
|
77
123
|
|
|
78
|
-
|
|
124
|
+
get_repo = async(type, name) => {
|
|
125
|
+
for (let r=0; r< this.repos.length; r++){
|
|
126
|
+
let {repo} = this.repos[r]
|
|
127
|
+
|
|
128
|
+
if (repo.type === type && repo.name === name)
|
|
129
|
+
return repo
|
|
130
|
+
}
|
|
79
131
|
}
|
|
80
132
|
|
|
81
|
-
|
|
82
|
-
let
|
|
83
|
-
|
|
84
|
-
await
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
await this.mkdir(current)
|
|
95
|
-
let current_conff = `${current}/.config`
|
|
96
|
-
let conff = await this.read(current_conff) || {index: 0}
|
|
97
|
-
await this.write(`${current}/${conff.index}`, JSON.stringify(obj))
|
|
98
|
-
conff.index++
|
|
99
|
-
|
|
100
|
-
await this.write(current_conff, JSON.stringify(conff))
|
|
101
|
-
addr = current
|
|
102
|
-
}else {
|
|
103
|
-
this.fs.writeFileSync(`${this.base}/${path}`, content)
|
|
104
|
-
addr = path;
|
|
133
|
+
fetch = async(payload, server)=>{
|
|
134
|
+
let res;
|
|
135
|
+
try{
|
|
136
|
+
res = await post_request({
|
|
137
|
+
options: {
|
|
138
|
+
...server,
|
|
139
|
+
path: '/oracle'
|
|
140
|
+
},
|
|
141
|
+
data: JSON.stringify(payload)
|
|
142
|
+
})
|
|
143
|
+
}catch(e){
|
|
144
|
+
console.log(e)
|
|
105
145
|
}
|
|
106
146
|
|
|
107
|
-
return
|
|
147
|
+
return res;
|
|
108
148
|
}
|
|
109
149
|
|
|
110
|
-
|
|
111
|
-
|
|
150
|
+
set_to_repos = async(address, content)=>{
|
|
151
|
+
for (let r=0; r< this.repos.length; r++){
|
|
152
|
+
let repo = this.repos[r]
|
|
112
153
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
await this.mkdir(arr_path)
|
|
154
|
+
if (!repo.filter || address.match(repo.filter)){
|
|
155
|
+
await repo.repo.write_file(address, content)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
119
159
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
160
|
+
get_from_repos = async(address)=>{
|
|
161
|
+
for (let r=0; r< this.repos.length; r++){
|
|
162
|
+
let repo = this.repos[r]
|
|
163
|
+
|
|
164
|
+
if (!repo.filter || address.match(repo.filter)){
|
|
165
|
+
let content = await repo.repo.read_file(address)
|
|
166
|
+
if (content) return content;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
123
170
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
171
|
+
read = async(path, options={})=>{
|
|
172
|
+
let {address, account, prefix} = options;
|
|
173
|
+
prefix = prefix || '.storage'
|
|
127
174
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
175
|
+
let has = (await this.get_accounts(address)).includes(account)
|
|
176
|
+
|
|
177
|
+
if(!has) return;
|
|
178
|
+
|
|
179
|
+
let servers = await this.get_servers(account)
|
|
180
|
+
for (let s=0; s< servers.length; s++){
|
|
181
|
+
let server = servers[s]
|
|
182
|
+
if (this.server_match(server, this.server)){
|
|
183
|
+
let res = await this.fetch({
|
|
184
|
+
method: 'read',
|
|
185
|
+
arg: {path, prefix}
|
|
186
|
+
}, server)
|
|
187
|
+
|
|
188
|
+
if(res && res.content){
|
|
189
|
+
return res.content
|
|
190
|
+
}else break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
for (let s=0; s< servers.length; s++){
|
|
194
|
+
let server = servers[s]
|
|
195
|
+
if (this.server_match(server, this.server)){
|
|
196
|
+
continue
|
|
197
|
+
}
|
|
131
198
|
|
|
132
|
-
|
|
133
|
-
|
|
199
|
+
let res = await this.fetch({
|
|
200
|
+
method: 'read',
|
|
201
|
+
arg: {path, prefix}
|
|
202
|
+
}, server)
|
|
203
|
+
if(res && res.content){
|
|
204
|
+
return res.content
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
134
208
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
let arr_hash = await this.oracle.hash(arr)
|
|
139
|
-
let arr_conf = await this.read(`${arr_path}/.config`) || {index: 0}
|
|
140
|
-
await this.write(`${arr_path}/${arr_hash}`, JSON.stringify({content:arr, type: is_instance? 'instance': type, previous: arr_conf.current, indice: aconf.indice}))
|
|
141
|
-
arr_conf.current = arr_hash
|
|
142
|
-
arr_conf.sibling = aconf.current;
|
|
209
|
+
write = async(path, content, options={})=>{
|
|
210
|
+
let {account, address, prefix} = options
|
|
211
|
+
prefix = prefix || '.storage'
|
|
143
212
|
|
|
144
|
-
|
|
213
|
+
await this.update_accounts(address, account)
|
|
214
|
+
let servers = await this.get_servers(account)
|
|
145
215
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
result = arr_path
|
|
216
|
+
for (let s=0; s< servers.length; s++){
|
|
217
|
+
let server = servers[s]
|
|
150
218
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
let twa = {}
|
|
158
|
-
for (let prop in content){
|
|
159
|
-
let value = content[prop];
|
|
160
|
-
let p_hash = await this.oracle.hash(prop)
|
|
161
|
-
let pair_path = `${twa_path}/${p_hash}`
|
|
162
|
-
await this.mkdir(pair_path)
|
|
163
|
-
let p_addr = await this.store(prop, {path: pair_path})
|
|
164
|
-
let val_addr = await this.store(value, {path: pair_path})
|
|
165
|
-
|
|
166
|
-
let pair = [p_addr, val_addr]
|
|
167
|
-
|
|
168
|
-
let conf = await this.read(`${pair_path}/.config`)
|
|
169
|
-
if (!conf){
|
|
170
|
-
conf = {index: 0}
|
|
171
|
-
}else if (!Object.keys(conf).includes('index'))conf.index = 0
|
|
172
|
-
else {
|
|
173
|
-
conf.index++
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
await this.write(`${pair_path}/${conf.index}`, JSON.stringify(pair))
|
|
219
|
+
await this.fetch({
|
|
220
|
+
method: 'write',
|
|
221
|
+
arg: {path, content, prefix}
|
|
222
|
+
}, server)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
177
225
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
226
|
+
get_servers = async(account, mirroring)=>{
|
|
227
|
+
let addr = `.oracle/${account}/.configs`
|
|
228
|
+
let servers = await this.get_from_repos(addr)
|
|
229
|
+
servers = servers ? JSON.parse(servers) : []
|
|
230
|
+
|
|
231
|
+
if(!mirroring && !servers.length && this.mirror){
|
|
232
|
+
servers = await this.fetch({
|
|
233
|
+
method: 'get_servers',
|
|
234
|
+
arg: {account}
|
|
235
|
+
}, this.mirror)
|
|
236
|
+
if (servers.length){
|
|
237
|
+
await this.set_to_repos(addr, JSON.stringify(servers))
|
|
238
|
+
await this.update_servers(account, [...servers])
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return servers
|
|
242
|
+
}
|
|
183
243
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
244
|
+
update_servers = async(account, servers)=>{
|
|
245
|
+
servers = servers || await this.get_servers(account)
|
|
246
|
+
|
|
247
|
+
if (servers.find(s=>this.server_match(s, this.server))){
|
|
248
|
+
return
|
|
249
|
+
}
|
|
189
250
|
|
|
190
|
-
|
|
251
|
+
servers.push(this.server)
|
|
252
|
+
for (let s=0; s< servers.length; s++){
|
|
253
|
+
let server = servers[s]
|
|
191
254
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
break;
|
|
197
|
-
case 'string':
|
|
198
|
-
hash = await this.oracle.hash(content)
|
|
199
|
-
result = await this.write(`${path}/${hash}`, content)
|
|
200
|
-
break
|
|
201
|
-
case 'number':
|
|
202
|
-
hash = await this.oracle.hash(`0${content}`)
|
|
203
|
-
result = await this.write(`${path}/${hash}`, JSON.stringify(content))
|
|
204
|
-
break
|
|
205
|
-
case 'boolean':
|
|
206
|
-
hash = await this.oracle.hash(`0${content}`)
|
|
207
|
-
result = await this.write(`${path}/${hash}`, JSON.stringify(content))
|
|
208
|
-
break
|
|
255
|
+
await this.fetch({
|
|
256
|
+
method: 'update_servers',
|
|
257
|
+
arg: {account, server: this.server},
|
|
258
|
+
}, server)
|
|
209
259
|
}
|
|
210
260
|
|
|
211
|
-
return
|
|
261
|
+
return servers
|
|
212
262
|
}
|
|
213
|
-
}
|
|
214
263
|
|
|
215
|
-
|
|
216
|
-
|
|
264
|
+
get_accounts = async(address, mirroring)=>{
|
|
265
|
+
let addr = `.oracle/${address}/.configs`
|
|
266
|
+
let accounts = await this.get_from_repos(addr)
|
|
267
|
+
|
|
268
|
+
accounts = accounts ? JSON.parse(accounts) : []
|
|
217
269
|
|
|
218
|
-
|
|
270
|
+
if (!mirroring && !accounts.length && this.mirror){
|
|
271
|
+
accounts = await this.fetch({
|
|
272
|
+
method: 'get_accounts',
|
|
273
|
+
arg: {address}
|
|
274
|
+
}, this.mirror)
|
|
275
|
+
}
|
|
219
276
|
|
|
220
|
-
|
|
277
|
+
return accounts
|
|
221
278
|
}
|
|
222
279
|
|
|
223
|
-
|
|
224
|
-
let
|
|
280
|
+
update_accounts = async(address, account)=>{
|
|
281
|
+
let accounts = await this.get_accounts(address)
|
|
282
|
+
|
|
283
|
+
if (accounts.includes(account)){
|
|
284
|
+
return
|
|
285
|
+
}
|
|
225
286
|
|
|
226
|
-
|
|
227
|
-
}
|
|
287
|
+
accounts.push(account)
|
|
228
288
|
|
|
229
|
-
|
|
230
|
-
|
|
289
|
+
let servers = await this.get_servers_from_address(address, accounts)
|
|
290
|
+
|
|
291
|
+
for (let s=0; s< servers.length; s++){
|
|
292
|
+
let server = servers[s]
|
|
231
293
|
|
|
232
|
-
|
|
233
|
-
|
|
294
|
+
await this.fetch({
|
|
295
|
+
method: 'update_accounts',
|
|
296
|
+
arg: {address, account},
|
|
297
|
+
}, server)
|
|
234
298
|
}
|
|
235
299
|
|
|
236
|
-
|
|
300
|
+
return accounts
|
|
301
|
+
}
|
|
237
302
|
|
|
238
|
-
|
|
303
|
+
get_servers_from_address = async(address, accounts)=>{
|
|
304
|
+
accounts = accounts || await this.get_accounts(address)
|
|
305
|
+
|
|
306
|
+
let servers = []
|
|
307
|
+
for (let a=0; a< accounts.length; a++){
|
|
308
|
+
let acc = accounts[a]
|
|
309
|
+
let servers_ = await this.get_servers(acc)
|
|
310
|
+
servers_.map(serv=>{
|
|
311
|
+
if(!servers.find(s=>this.server_match(s, serv)))
|
|
312
|
+
servers.push(serv)
|
|
313
|
+
})
|
|
314
|
+
}
|
|
239
315
|
|
|
240
|
-
return
|
|
316
|
+
return servers
|
|
241
317
|
}
|
|
242
318
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return hash(value, alg)
|
|
319
|
+
server_match = (s1, s2)=>{
|
|
320
|
+
return s1.hostname === s2.hostname && s1.port === s2.port
|
|
247
321
|
}
|
|
248
322
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
await this.fs.mkdir(this.manager.path)
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
get_type = (content)=>{
|
|
255
|
-
let type = typeof content;
|
|
323
|
+
set_manager = async(manager)=>{
|
|
324
|
+
console.log(`Manager:${manager.name} Oracle running at ${this.server.hostname}:${this.server.port}`)
|
|
256
325
|
|
|
257
|
-
if (
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
326
|
+
if (!this.server_match(this.server, manager.server)){
|
|
327
|
+
let response = await this.fetch({
|
|
328
|
+
method: 'sync',
|
|
329
|
+
arg: {manager_server: manager.server}
|
|
330
|
+
}, this.server)
|
|
331
|
+
|
|
332
|
+
for (let r=0; r< response.repos.length; r++){
|
|
333
|
+
let repository = response.repos[r]
|
|
334
|
+
|
|
335
|
+
await this.add_repo(repository)
|
|
336
|
+
}
|
|
263
337
|
}
|
|
264
|
-
return type;
|
|
265
338
|
}
|
|
339
|
+
|
|
340
|
+
sync = async () => {
|
|
341
|
+
|
|
342
|
+
};
|
|
266
343
|
}
|
|
267
344
|
|
|
268
345
|
export default Oracle;
|
package/Objects/Repository.js
CHANGED
|
@@ -1,38 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class Repository {
|
|
4
|
-
constructor(manager) {
|
|
5
|
-
this.manager = manager;
|
|
6
|
-
|
|
7
|
-
this.gds = this.manager.oracle.gds;
|
|
1
|
+
class Repository{
|
|
2
|
+
constructor(){
|
|
8
3
|
}
|
|
9
4
|
|
|
10
|
-
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return content;
|
|
18
|
-
};
|
|
5
|
+
objectify = ()=>{
|
|
6
|
+
let obj = {}
|
|
7
|
+
if (this.type === 'fs'){
|
|
8
|
+
obj.name = this.name;
|
|
9
|
+
obj.remote = this.remote
|
|
10
|
+
obj.__dirname = this.__dirname
|
|
11
|
+
}
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
create_or_update_file = async (path, content, message, sha) => {
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
get_file_sha = async (path) => {
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
write_file = async (path, content, message = "") => {
|
|
32
|
-
await this.manager.oracle.fs.write_file(path, content)
|
|
33
|
-
|
|
34
|
-
return path
|
|
35
|
-
};
|
|
13
|
+
return obj
|
|
14
|
+
}
|
|
36
15
|
}
|
|
37
16
|
|
|
38
|
-
export default Repository;
|
|
17
|
+
export default Repository;
|
package/Objects/Trinity.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Manager from "./Manager";
|
|
1
|
+
import Manager from "./Manager.js";
|
|
2
2
|
|
|
3
3
|
class Trinity {
|
|
4
4
|
constructor(game) {
|
|
@@ -7,18 +7,20 @@ class Trinity {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
add_manager = async (name, options) => {
|
|
10
|
+
let mgr = this.managers[name];
|
|
11
|
+
if(mgr) return manager
|
|
12
|
+
|
|
10
13
|
let manager = new Manager(name, {...options, trinity: this});
|
|
11
|
-
let mgrs = this.managers[name];
|
|
12
|
-
if (!mgrs) {
|
|
13
|
-
mgrs = new Array();
|
|
14
|
-
this.managers[name] = mgrs;
|
|
15
|
-
}
|
|
16
14
|
await manager.sync();
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
this.managers[name] = manager;
|
|
19
17
|
|
|
20
18
|
return manager;
|
|
21
19
|
};
|
|
20
|
+
|
|
21
|
+
get_manager = (name)=>{
|
|
22
|
+
return this.managers[name]
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export default Trinity;
|
package/Objects/Utils.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
class Utils{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!addr)return addr;
|
|
2
|
+
on = async(event_name, filter, handler) => {
|
|
3
|
+
|
|
4
|
+
}
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
6
|
+
reload = async(payload)=>{
|
|
7
|
+
let {address} = payload;
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
let res = await this.manager.oracle.read(`${address}/air`, {address, prefix: '.codes', account: this.physical_address})
|
|
10
|
+
|
|
11
|
+
await this.load({address: address.slice(this.physical_address.length+1), sequence: res, compiler: true, from_reload: true})
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|