godprotocol 1.0.7991 → 1.1.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/Executables/callables.js +131 -0
- package/Executables/executables.js +230 -0
- package/Executables/functions/adminstrator/adm_register.js +29 -0
- package/Executables/functions/adminstrator/native_components.js +10 -0
- package/Executables/functions/adminstrator/query_selectors.js +10 -0
- package/Executables/functions/adminstrator/render.js +24 -0
- package/Executables/functions/array_register.js +161 -0
- package/Executables/functions/assign.js +19 -0
- package/Executables/functions/display.js +55 -0
- package/Executables/functions/folder.js +95 -0
- package/Executables/functions/folder_register.js +87 -0
- package/Executables/functions/importcheck.js +13 -0
- package/Executables/functions/indices.js +56 -0
- package/Executables/functions/len.js +22 -0
- package/Executables/functions/methods/array.js +272 -0
- package/Executables/functions/methods/string.js +197 -0
- package/Executables/functions/methods/twain.js +148 -0
- package/Executables/functions/op.js +15 -0
- package/Executables/functions/price_register.js +30 -0
- package/Executables/functions/pricing.js +26 -0
- package/Executables/functions/servers/account.js +81 -0
- package/Executables/functions/servers/account_register.js +56 -0
- package/Executables/functions/servers/block.js +21 -0
- package/Executables/functions/servers/block_register.js +18 -0
- package/Executables/functions/servers/chain.js +42 -0
- package/Executables/functions/servers/chain_register.js +28 -0
- package/Executables/functions/set_error_catch.js +34 -0
- package/Executables/functions/string_register.js +130 -0
- package/Executables/functions/twain_register.js +56 -0
- package/Executables/functions/typecast.js +43 -0
- package/Executables/functions/utils.js +9 -0
- package/Executables/stack.js +53 -0
- package/Index.js +2 -7
- package/Loader_sequence/main.js +535 -119
- package/Loader_sequence/repository.js +33 -0
- package/Objects/Account.js +220 -54
- package/Objects/Block.js +46 -16
- package/Objects/Blockweb.js +14 -0
- package/Objects/Chain.js +163 -16
- package/Objects/Fee.js +33 -0
- package/Objects/Filesystem.js +100 -26
- package/Objects/Frame.js +10 -3
- package/Objects/Manager.js +272 -46
- package/Objects/Opcodes.js +60 -10
- package/Objects/Oracle.js +90 -5
- package/Objects/Protocol.js +5 -0
- package/Objects/Virtual_machine.js +145 -53
- package/Trinity.js +20 -0
- package/callables.js +172 -0
- package/framer.js +111 -52
- package/opcodes/add.js +6 -6
- package/opcodes/indices.js +82 -0
- package/opcodes/jmp.js +12 -11
- package/opcodes/std.js +7 -2
- package/opcodes.js +72 -14
- package/package.json +6 -5
- package/readme.md +1 -1
- package/starter_scripts/constants.seq +11 -0
- package/utils/create_server.js +34 -27
- package/utils/hash.js +2 -2
- package/utils/logger.js +79 -0
- package/utils/services.js +5 -3
- package/utils/type_coersion.js +3 -0
- package/utils/vm_utils.js +292 -0
- package/.babelrc +0 -3
- package/build/Account.js +0 -162
- package/build/Block.js +0 -65
- package/build/Blockweb.js +0 -36
- package/build/Chain.js +0 -119
- package/build/Explorer.js +0 -47
- package/build/Filesystem.js +0 -127
- package/build/Frame.js +0 -52
- package/build/Index.js +0 -15
- package/build/Manager.js +0 -99
- package/build/Opcodes.js +0 -39
- package/build/Oracle.js +0 -42
- package/build/Virtual_machine.js +0 -128
- package/build/add.js +0 -41
- package/build/create_server.js +0 -119
- package/build/framer.js +0 -57
- package/build/functions.js +0 -82
- package/build/hash.js +0 -14
- package/build/jmp.js +0 -19
- package/build/main.js +0 -283
- package/build/opcodes.js +0 -42
- package/build/privacy.js +0 -27
- package/build/services.js +0 -50
- package/build/std.js +0 -11
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class Repository {
|
|
2
|
+
constructor(main) {
|
|
3
|
+
this.main = main;
|
|
4
|
+
this.oracle = this.main.account.manager.oracle;
|
|
5
|
+
this.gds = this.oracle.gds;
|
|
6
|
+
this.programs = this.gds.folder("programs");
|
|
7
|
+
this.codes = this.gds.folder("codes");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
add_program = (config) => {
|
|
11
|
+
let codes = config.codes.filter(line=>!!line.trim())
|
|
12
|
+
let code_hash = this.oracle.hash(codes);
|
|
13
|
+
let code_exist = this.codes.readone({ hash: code_hash });
|
|
14
|
+
|
|
15
|
+
let code = this.codes.write({
|
|
16
|
+
body: codes,
|
|
17
|
+
hash: code_hash,
|
|
18
|
+
_id: code_exist && code_exist._id,
|
|
19
|
+
});
|
|
20
|
+
config.codes = code._id;
|
|
21
|
+
|
|
22
|
+
let program_hash = this.oracle.hash(JSON.stringify(config));
|
|
23
|
+
let program_exist = this.programs.readone({ hash: program_hash });
|
|
24
|
+
|
|
25
|
+
this.programs.write({
|
|
26
|
+
...config,
|
|
27
|
+
hash: program_hash,
|
|
28
|
+
_id: program_exist && program_exist._id,
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default Repository;
|
package/Objects/Account.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
|
|
1
2
|
import Loader_sequence from "../Loader_sequence/main";
|
|
2
3
|
import validate_signature from "../utils/privacy";
|
|
4
|
+
import { post_request } from "../utils/services";
|
|
3
5
|
import Filesystem from "./Filesystem";
|
|
4
6
|
import Virtual_machine from "./Virtual_machine";
|
|
5
7
|
|
|
@@ -13,6 +15,10 @@ class Account extends Filesystem {
|
|
|
13
15
|
this.private = meta.private;
|
|
14
16
|
this.manager = meta.manager;
|
|
15
17
|
this.account = this;
|
|
18
|
+
this.stdin = new Array();
|
|
19
|
+
this.stdout = new Array();
|
|
20
|
+
|
|
21
|
+
this.log_output = this.manager.logger.store_log
|
|
16
22
|
|
|
17
23
|
if (!this.manager) throw new Error("Manager instance missing.");
|
|
18
24
|
|
|
@@ -20,109 +26,257 @@ class Account extends Filesystem {
|
|
|
20
26
|
this.physical_address = `${this.base_address}/${this.name}`;
|
|
21
27
|
this.set_paths(this);
|
|
22
28
|
|
|
23
|
-
this.
|
|
29
|
+
this.assembler = new Loader_sequence(this);
|
|
24
30
|
|
|
25
31
|
this.chain = this.account_chain(this);
|
|
26
32
|
this.vm = new Virtual_machine(this.chain);
|
|
27
33
|
|
|
28
34
|
this.mine_buffer = {};
|
|
35
|
+
this.privileges = new Object();
|
|
36
|
+
|
|
37
|
+
this.events = new Object();
|
|
29
38
|
|
|
30
|
-
|
|
39
|
+
this.log_output(`Account Instance: ${this.name}`);
|
|
31
40
|
}
|
|
32
41
|
|
|
42
|
+
on = (event, handler) => {
|
|
43
|
+
let handlers = this.events[event];
|
|
44
|
+
if (!handlers) {
|
|
45
|
+
handlers = new Array();
|
|
46
|
+
this.events[event] = handlers;
|
|
47
|
+
}
|
|
48
|
+
handlers.push(handler);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
emit = (event, data) => {
|
|
52
|
+
let handlers = this.events[event];
|
|
53
|
+
Array.isArray(handlers) &&
|
|
54
|
+
handlers.map((handle) => this.run_callback(handle, data));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
propagate = (data, endpoint) => {
|
|
58
|
+
if (data.is_propagated) return;
|
|
59
|
+
|
|
60
|
+
let servers = this.privileges[endpoint];
|
|
61
|
+
|
|
62
|
+
if (data.exclusive) {
|
|
63
|
+
if (typeof data.exclusive === "boolean") return;
|
|
64
|
+
else if (Array.isArray(data.exclusive)) {
|
|
65
|
+
servers =
|
|
66
|
+
servers &&
|
|
67
|
+
servers.filter((serv) => {
|
|
68
|
+
return data.exclusive.includes(serv.domain);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
data.is_propagated = true;
|
|
74
|
+
data = JSON.stringify(data);
|
|
75
|
+
|
|
76
|
+
if (servers && servers.length) {
|
|
77
|
+
servers.map((serv) => {
|
|
78
|
+
post_request({
|
|
79
|
+
options: {
|
|
80
|
+
...serv,
|
|
81
|
+
path: `/${endpoint}`,
|
|
82
|
+
},
|
|
83
|
+
data,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
add_server = ({ server, privileges }) => {
|
|
90
|
+
if (!Array.isArray(privileges) && privileges)
|
|
91
|
+
privileges = ["load", "parse", "run", "create_account"];
|
|
92
|
+
|
|
93
|
+
privileges.map((privilege) => {
|
|
94
|
+
let priv = this.privileges[privilege];
|
|
95
|
+
if (!priv) {
|
|
96
|
+
priv = [];
|
|
97
|
+
this.privileges[privilege] = priv;
|
|
98
|
+
}
|
|
99
|
+
if (!priv.find((serv) => serv.domain === server.domain))
|
|
100
|
+
priv.push(server);
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
|
|
33
104
|
get_account = (name) => {
|
|
34
105
|
return this.manager.get_account(name) || this;
|
|
35
106
|
};
|
|
36
107
|
|
|
37
|
-
manage_buffer = (callback) => {
|
|
108
|
+
manage_buffer = (callback, real_cb) => {
|
|
38
109
|
let call_session = `${Date.now()}-${Math.random()}`;
|
|
39
|
-
this.mine_buffer[call_session] = { blocks: [], callback };
|
|
110
|
+
this.mine_buffer[call_session] = { blocks: [], callback, real_cb };
|
|
40
111
|
|
|
41
112
|
return call_session;
|
|
42
113
|
};
|
|
43
114
|
|
|
115
|
+
results = new Object()
|
|
116
|
+
|
|
44
117
|
buff = (block, pid) => {
|
|
118
|
+
if(block.ret){
|
|
119
|
+
this.results[pid] = block.ret
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
45
123
|
let buffer = this.mine_buffer[pid];
|
|
46
124
|
if (!buffer) return;
|
|
47
125
|
|
|
48
|
-
buffer.blocks.push(block.stringify());
|
|
126
|
+
block && block.stringify && buffer.blocks.push(block.stringify());
|
|
49
127
|
};
|
|
50
128
|
|
|
51
|
-
flush_buffer = (pid) => {
|
|
129
|
+
flush_buffer = (pid, payload) => {
|
|
52
130
|
let buff = this.mine_buffer[pid];
|
|
53
131
|
if (!buff) return;
|
|
54
132
|
|
|
55
|
-
|
|
133
|
+
if (buff.callback){
|
|
134
|
+
this.run_callback(buff.callback,{ payload, ret: this.results[pid] , blocks: buff.blocks});
|
|
135
|
+
} else if(buff.real_cb){
|
|
136
|
+
buff.real_cb(payload)
|
|
137
|
+
}
|
|
138
|
+
|
|
56
139
|
delete this.mine_buffer[pid];
|
|
140
|
+
delete this.results[pid]
|
|
57
141
|
};
|
|
58
142
|
|
|
59
|
-
|
|
60
|
-
let
|
|
61
|
-
|
|
143
|
+
execute =( opcode, args)=>{
|
|
144
|
+
let circ = this.vm.opcodes[opcode]
|
|
145
|
+
if (typeof circ !== 'function') {return}
|
|
62
146
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
let pid = account.manage_buffer(callback);
|
|
147
|
+
circ(args)
|
|
148
|
+
}
|
|
66
149
|
|
|
67
|
-
|
|
150
|
+
process_fee = ({fee, validator}, cb)=>{
|
|
151
|
+
let content = this.vm.read_chain(fee, {tell_callable})
|
|
152
|
+
|
|
153
|
+
if (content.callable){
|
|
154
|
+
this.vm.exec({executable: content.__address__, location:result=>{
|
|
155
|
+
this.vm.exec({executable: validator, location: result=>{
|
|
156
|
+
cb && cb(result)
|
|
157
|
+
}, arguments: {argc:1, argv: [{position: 0, static_value: result}]}})
|
|
158
|
+
} })
|
|
159
|
+
}else {
|
|
160
|
+
this.vm.exec({executable: validator, location: (result)=>{
|
|
161
|
+
cb && cb(result)
|
|
162
|
+
}, arguments: {argc:1, argv: [{position:0, address: fee}]}})
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
load = (payload) => {
|
|
167
|
+
let { program, callback, location } = payload;
|
|
168
|
+
let { instructions, assemble, forge, spawn, unshift } = program;
|
|
169
|
+
|
|
170
|
+
this.propagate(payload, "load");
|
|
171
|
+
|
|
172
|
+
if(forge){
|
|
173
|
+
let chain = this.vm.handle_chain(forge)
|
|
174
|
+
chain.forge_block({metadata:{output:this.save(instructions)}})
|
|
175
|
+
} else if (assemble) {
|
|
176
|
+
this.assembler
|
|
177
|
+
.spawn()
|
|
178
|
+
.run(instructions, { cb: callback, location, options: assemble , unshift});
|
|
179
|
+
} else {
|
|
180
|
+
let pid = this.manage_buffer(location?res=>{
|
|
181
|
+
this.vm.air_object(res, {location})
|
|
182
|
+
} : callback,location&& callback);
|
|
183
|
+
|
|
184
|
+
this.manager.push({ sequence: instructions, spawn, account: this, pid, unshift });
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if(location && callback){
|
|
188
|
+
callback({estimated_time:'-ms', callback:location})
|
|
189
|
+
}
|
|
68
190
|
};
|
|
69
191
|
|
|
70
|
-
parse = (
|
|
71
|
-
let {
|
|
72
|
-
account = this.get_account(account);
|
|
73
|
-
|
|
74
|
-
if (!account.validate(payload, signature))
|
|
75
|
-
return this.run_callback(callback, {
|
|
76
|
-
private: account.private,
|
|
77
|
-
error: true,
|
|
78
|
-
error_message: "Invalid signature",
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
let chain = account.manager.web.get(physical_address);
|
|
82
|
-
|
|
83
|
-
if (!chain)
|
|
84
|
-
return this.run_callback(callback, {
|
|
85
|
-
error: true,
|
|
86
|
-
error_message: "Address not found",
|
|
87
|
-
});
|
|
192
|
+
parse = (program) => {
|
|
193
|
+
let { payload, callback, signature } = program;
|
|
88
194
|
|
|
89
|
-
|
|
195
|
+
this.propagate(program, "parse");
|
|
90
196
|
|
|
91
|
-
this.
|
|
197
|
+
this.manager.oracle.fetch({ ...payload, signature }, (result) =>
|
|
198
|
+
this.run_callback(callback, result)
|
|
199
|
+
);
|
|
92
200
|
};
|
|
93
201
|
|
|
94
202
|
run = (request) => {
|
|
95
|
-
let { payload,
|
|
203
|
+
let { payload, callback, location} = request;
|
|
204
|
+
|
|
205
|
+
let { physical_address, query, history } = payload;
|
|
96
206
|
|
|
97
|
-
|
|
98
|
-
account = this.get_account(account);
|
|
207
|
+
history = Math.abs(Number(history)) || 0;
|
|
99
208
|
|
|
100
|
-
|
|
209
|
+
this.propagate(request, "run");
|
|
101
210
|
|
|
102
|
-
let pid =
|
|
211
|
+
let pid = this.manage_buffer(location?res=>{
|
|
212
|
+
this.vm.air_object(res, {location})
|
|
213
|
+
} : callback,location&& callback);
|
|
103
214
|
|
|
104
215
|
let context = physical_address
|
|
105
216
|
? this.manager.web.get(physical_address)
|
|
106
|
-
:
|
|
217
|
+
: this.vm.get_context();
|
|
107
218
|
|
|
108
|
-
if (!context)
|
|
219
|
+
if (!context) {
|
|
220
|
+
if (physical_address)
|
|
221
|
+
context = this.vm.handle_chain(physical_address);
|
|
222
|
+
else return this.flush_buffer(pid);
|
|
223
|
+
}
|
|
224
|
+
if(!context)throw new Error()
|
|
109
225
|
|
|
110
226
|
let blk = query ? context.explore(query) : context.get_latest_block();
|
|
111
227
|
|
|
228
|
+
// console.log(context.stringify())
|
|
229
|
+
// console.log(blk)
|
|
230
|
+
|
|
231
|
+
if (!query) {
|
|
232
|
+
let index = context.height;
|
|
233
|
+
index -= 1;
|
|
234
|
+
|
|
235
|
+
const historic = (blk) => {
|
|
236
|
+
if (blk && blk.metadata.program) {
|
|
237
|
+
if (history) {
|
|
238
|
+
history--;
|
|
239
|
+
blk = null;
|
|
240
|
+
}
|
|
241
|
+
} else blk = null;
|
|
242
|
+
|
|
243
|
+
return blk;
|
|
244
|
+
};
|
|
245
|
+
blk = historic(blk);
|
|
246
|
+
|
|
247
|
+
while (!blk && index >= 0) {
|
|
248
|
+
index--;
|
|
249
|
+
blk = context.get_block(index);
|
|
250
|
+
|
|
251
|
+
blk = historic(blk);
|
|
252
|
+
// console.log(blk)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// console.log(blk)
|
|
257
|
+
|
|
112
258
|
if (blk && blk.metadata && blk.metadata.program) {
|
|
113
259
|
let program = this.read(blk.metadata.program);
|
|
114
260
|
|
|
115
|
-
|
|
116
|
-
|
|
261
|
+
if (Array.isArray(program) && program.length) {
|
|
262
|
+
this.vm.push_context(context);
|
|
263
|
+
program = [...program, 'pop']
|
|
264
|
+
|
|
265
|
+
// console.log(program)
|
|
117
266
|
|
|
118
|
-
Array.isArray(program) &&
|
|
119
|
-
program.length &&
|
|
120
267
|
this.manager.push({
|
|
121
268
|
sequence: program,
|
|
122
|
-
account,
|
|
269
|
+
account: this,
|
|
270
|
+
payload,
|
|
271
|
+
error_stack: JSON.stringify(this.vm.error_manager),
|
|
123
272
|
pid,
|
|
124
273
|
});
|
|
125
|
-
|
|
274
|
+
}
|
|
275
|
+
} else this.flush_buffer(pid,{error:true, error_message: "Program is not set!"});
|
|
276
|
+
|
|
277
|
+
if(location && callback){
|
|
278
|
+
callback({estimated_time:'-ms', callback:location})
|
|
279
|
+
}
|
|
126
280
|
};
|
|
127
281
|
|
|
128
282
|
run_callback = (callback, payload) => {
|
|
@@ -133,10 +287,26 @@ class Account extends Filesystem {
|
|
|
133
287
|
|
|
134
288
|
callback.payload &&
|
|
135
289
|
callback.payload.physical_address &&
|
|
136
|
-
this.vm.stdin(payload,
|
|
290
|
+
this.vm.stdin(payload, callback);
|
|
137
291
|
}, 0);
|
|
138
292
|
};
|
|
139
293
|
|
|
294
|
+
flush_stdout = (block) => {
|
|
295
|
+
if (
|
|
296
|
+
block.chain.physical_address === `${this.physical_address}/Opcodes/stdout`
|
|
297
|
+
)
|
|
298
|
+
return;
|
|
299
|
+
|
|
300
|
+
for (let s = 0; s < this.stdout.length; s++) {
|
|
301
|
+
let out = this.stdout[s];
|
|
302
|
+
if (out.pid === this.vm.track.pid) {
|
|
303
|
+
block.metadata.stdout.push(out.data);
|
|
304
|
+
this.stdout[s] = null;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
this.stdout = this.stdout.filter((out) => !!out);
|
|
308
|
+
};
|
|
309
|
+
|
|
140
310
|
validate = (payload, signature, callback) => {
|
|
141
311
|
if (!this.private) return true;
|
|
142
312
|
|
|
@@ -145,7 +315,7 @@ class Account extends Filesystem {
|
|
|
145
315
|
JSON.stringify(payload),
|
|
146
316
|
signature
|
|
147
317
|
);
|
|
148
|
-
if (!valid)
|
|
318
|
+
if (!valid && callback)
|
|
149
319
|
this.run_callback(callback, {
|
|
150
320
|
private: this.private,
|
|
151
321
|
error: true,
|
|
@@ -169,15 +339,11 @@ class Account extends Filesystem {
|
|
|
169
339
|
};
|
|
170
340
|
|
|
171
341
|
create_account = (payload) => {
|
|
342
|
+
this.propagate(payload, "create_account");
|
|
172
343
|
let { name, meta } = payload;
|
|
173
344
|
|
|
174
345
|
return this.manager.add_account(name, meta);
|
|
175
346
|
};
|
|
176
|
-
|
|
177
|
-
endpoint = (endpoint, payload) => {
|
|
178
|
-
let method = this[endpoint];
|
|
179
|
-
typeof method === "function" && method(payload);
|
|
180
|
-
};
|
|
181
347
|
}
|
|
182
348
|
|
|
183
349
|
export default Account;
|
package/Objects/Block.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { hash } from "../utils/hash";
|
|
2
|
+
import { _id } from "generalised-datastore/utils/functions";
|
|
2
3
|
|
|
3
4
|
class Block {
|
|
4
5
|
constructor(chain) {
|
|
@@ -6,13 +7,12 @@ class Block {
|
|
|
6
7
|
this.data = this.chain.txs;
|
|
7
8
|
this.metadata = {};
|
|
8
9
|
this.children = new Array();
|
|
9
|
-
this.index = this.chain.
|
|
10
|
+
this.index = this.chain.height;
|
|
11
|
+
this._id = _id(this.chain.hash);
|
|
12
|
+
this.previous_hash = this.chain.recent_block && this.chain.recent_block._id
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
generate_hash = () => {
|
|
13
|
-
this.previous_hash = this.chain.get_latest_block();
|
|
14
|
-
if (this.previous_hash) this.previous_hash = this.previous_hash.hash;
|
|
15
|
-
|
|
16
16
|
this.hash = hash(JSON.stringify(this.data));
|
|
17
17
|
};
|
|
18
18
|
|
|
@@ -21,19 +21,32 @@ class Block {
|
|
|
21
21
|
if (!no_curs) this.cursor = this.chain.cursors.splice(-1)[0];
|
|
22
22
|
if (!content) return;
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
if (this.data.length<=1 && this.chain.account.is_datatype(this.chain)){
|
|
25
|
+
content = this.chain.account.stringify_type(this.chain)
|
|
26
|
+
}else {
|
|
27
|
+
let cursors = Object.keys(content).filter(
|
|
28
|
+
(c) => c.startsWith("{") && c.endsWith("}")
|
|
29
|
+
);
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
for (let c = 0; c < cursors.length; c++) {
|
|
32
|
+
let curs = cursors[c];
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
this.metadata[curs.slice(1, -1)] = content[curs];
|
|
35
|
+
delete content[curs];
|
|
36
|
+
}
|
|
33
37
|
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
this.metadata.stdout = new Array();
|
|
41
|
+
this.chain.account.flush_stdout(this);
|
|
34
42
|
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
if(!this.chain.datapath){
|
|
44
|
+
let datapath = this.chain.account.save(content, this.chain);
|
|
45
|
+
this.datapath = datapath
|
|
46
|
+
}else {
|
|
47
|
+
this.chain.account.save(content)
|
|
48
|
+
this.datapath = this.chain.datapath
|
|
49
|
+
}
|
|
37
50
|
};
|
|
38
51
|
|
|
39
52
|
stringify = (str) => {
|
|
@@ -44,10 +57,10 @@ class Block {
|
|
|
44
57
|
obj.timelapse = this.timelapse;
|
|
45
58
|
obj.index = this.index;
|
|
46
59
|
obj.hash = this.hash;
|
|
60
|
+
obj.previous_hash = this.previous_hash;
|
|
47
61
|
obj.data = this.data;
|
|
48
|
-
obj.
|
|
49
|
-
|
|
50
|
-
);
|
|
62
|
+
obj._id = this._id;
|
|
63
|
+
obj.children = this.children.map((ch) => ch && ch._id);
|
|
51
64
|
obj.chain = {
|
|
52
65
|
hash: this.chain.hash,
|
|
53
66
|
physical_address: this.chain.physical_address,
|
|
@@ -55,6 +68,23 @@ class Block {
|
|
|
55
68
|
|
|
56
69
|
return str ? JSON.stringify(obj) : obj;
|
|
57
70
|
};
|
|
71
|
+
|
|
72
|
+
static build = (data, chain) => {
|
|
73
|
+
let blck = new Block(chain);
|
|
74
|
+
blck.chain = chain;
|
|
75
|
+
blck.metadata = data.metadata;
|
|
76
|
+
blck.datapath = data.datapath;
|
|
77
|
+
blck.timelapse = data.timelapse;
|
|
78
|
+
blck.index = data.index;
|
|
79
|
+
blck.previous_hash = data.previous_hash;
|
|
80
|
+
blck.hash = data.hash;
|
|
81
|
+
blck.data = data.data;
|
|
82
|
+
blck.children = data.children || [];
|
|
83
|
+
|
|
84
|
+
blck._id = data._id;
|
|
85
|
+
|
|
86
|
+
return blck;
|
|
87
|
+
};
|
|
58
88
|
}
|
|
59
89
|
|
|
60
90
|
export default Block;
|
package/Objects/Blockweb.js
CHANGED
|
@@ -15,7 +15,21 @@ class Blockweb {
|
|
|
15
15
|
return chain;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
split_set = (physical_address) => {
|
|
19
|
+
let spli = physical_address.split("/");
|
|
20
|
+
|
|
21
|
+
let chain = this.get(physical_address);
|
|
22
|
+
if (!chain && spli.length >1) {
|
|
23
|
+
chain = this.set(spli.slice(0, -1).join("/"), spli.slice(-1)[0]);
|
|
24
|
+
}
|
|
25
|
+
return chain;
|
|
26
|
+
};
|
|
27
|
+
|
|
18
28
|
set = (parent, name) => {
|
|
29
|
+
if (typeof parent === "string") {
|
|
30
|
+
parent = this.get(parent) || this.split_set(parent);
|
|
31
|
+
}
|
|
32
|
+
|
|
19
33
|
let chain = new Chain(parent, name);
|
|
20
34
|
this.chains[chain.hash] = chain;
|
|
21
35
|
|