godprotocol 1.0.842 → 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 -55
- package/Loader_sequence/main.js +371 -124
- package/Loader_sequence/repository.js +1 -1
- package/Objects/Account.js +101 -34
- package/Objects/Block.js +24 -18
- package/Objects/Blockweb.js +1 -1
- package/Objects/Chain.js +127 -29
- package/Objects/Explorer.js +3 -17
- package/Objects/Fee.js +33 -0
- package/Objects/Filesystem.js +98 -25
- package/Objects/Frame.js +10 -3
- package/Objects/Manager.js +193 -23
- package/Objects/Opcodes.js +48 -10
- package/Objects/Oracle.js +11 -8
- package/Objects/Protocol.js +5 -0
- package/Objects/Virtual_machine.js +130 -59
- package/Trinity.js +20 -0
- package/callables.js +172 -0
- package/framer.js +65 -12
- package/opcodes/add.js +6 -1
- package/opcodes/indices.js +60 -6
- package/opcodes/jmp.js +2 -0
- package/opcodes/std.js +5 -2
- package/opcodes.js +56 -18
- package/package.json +2 -2
- package/starter_scripts/constants.seq +11 -0
- package/utils/create_server.js +15 -7
- 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
|
@@ -8,7 +8,7 @@ class Repository {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
add_program = (config) => {
|
|
11
|
-
let codes = config.codes.filter(
|
|
11
|
+
let codes = config.codes.filter(line=>!!line.trim())
|
|
12
12
|
let code_hash = this.oracle.hash(codes);
|
|
13
13
|
let code_exist = this.codes.readone({ hash: code_hash });
|
|
14
14
|
|
package/Objects/Account.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
import Loader_sequence from "../Loader_sequence/main";
|
|
2
3
|
import validate_signature from "../utils/privacy";
|
|
3
4
|
import { post_request } from "../utils/services";
|
|
@@ -17,6 +18,8 @@ class Account extends Filesystem {
|
|
|
17
18
|
this.stdin = new Array();
|
|
18
19
|
this.stdout = new Array();
|
|
19
20
|
|
|
21
|
+
this.log_output = this.manager.logger.store_log
|
|
22
|
+
|
|
20
23
|
if (!this.manager) throw new Error("Manager instance missing.");
|
|
21
24
|
|
|
22
25
|
this.name_hash();
|
|
@@ -33,7 +36,7 @@ class Account extends Filesystem {
|
|
|
33
36
|
|
|
34
37
|
this.events = new Object();
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
this.log_output(`Account Instance: ${this.name}`);
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
on = (event, handler) => {
|
|
@@ -102,40 +105,87 @@ class Account extends Filesystem {
|
|
|
102
105
|
return this.manager.get_account(name) || this;
|
|
103
106
|
};
|
|
104
107
|
|
|
105
|
-
manage_buffer = (callback) => {
|
|
108
|
+
manage_buffer = (callback, real_cb) => {
|
|
106
109
|
let call_session = `${Date.now()}-${Math.random()}`;
|
|
107
|
-
this.mine_buffer[call_session] = { blocks: [], callback };
|
|
110
|
+
this.mine_buffer[call_session] = { blocks: [], callback, real_cb };
|
|
108
111
|
|
|
109
112
|
return call_session;
|
|
110
113
|
};
|
|
111
114
|
|
|
115
|
+
results = new Object()
|
|
116
|
+
|
|
112
117
|
buff = (block, pid) => {
|
|
118
|
+
if(block.ret){
|
|
119
|
+
this.results[pid] = block.ret
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
113
123
|
let buffer = this.mine_buffer[pid];
|
|
114
124
|
if (!buffer) return;
|
|
115
125
|
|
|
116
|
-
buffer.blocks.push(block.stringify());
|
|
126
|
+
block && block.stringify && buffer.blocks.push(block.stringify());
|
|
117
127
|
};
|
|
118
128
|
|
|
119
129
|
flush_buffer = (pid, payload) => {
|
|
120
130
|
let buff = this.mine_buffer[pid];
|
|
121
131
|
if (!buff) return;
|
|
122
132
|
|
|
123
|
-
|
|
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
|
+
|
|
124
139
|
delete this.mine_buffer[pid];
|
|
140
|
+
delete this.results[pid]
|
|
125
141
|
};
|
|
126
142
|
|
|
143
|
+
execute =( opcode, args)=>{
|
|
144
|
+
let circ = this.vm.opcodes[opcode]
|
|
145
|
+
if (typeof circ !== 'function') {return}
|
|
146
|
+
|
|
147
|
+
circ(args)
|
|
148
|
+
}
|
|
149
|
+
|
|
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
|
+
|
|
127
166
|
load = (payload) => {
|
|
128
|
-
let { program, callback } = payload;
|
|
129
|
-
let { instructions, assemble } = program;
|
|
167
|
+
let { program, callback, location } = payload;
|
|
168
|
+
let { instructions, assemble, forge, spawn, unshift } = program;
|
|
130
169
|
|
|
131
170
|
this.propagate(payload, "load");
|
|
132
|
-
|
|
133
|
-
if
|
|
134
|
-
this.
|
|
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});
|
|
135
179
|
} else {
|
|
136
|
-
let pid = this.manage_buffer(
|
|
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
|
+
}
|
|
137
186
|
|
|
138
|
-
|
|
187
|
+
if(location && callback){
|
|
188
|
+
callback({estimated_time:'-ms', callback:location})
|
|
139
189
|
}
|
|
140
190
|
};
|
|
141
191
|
|
|
@@ -150,7 +200,7 @@ class Account extends Filesystem {
|
|
|
150
200
|
};
|
|
151
201
|
|
|
152
202
|
run = (request) => {
|
|
153
|
-
let { payload, callback } = request;
|
|
203
|
+
let { payload, callback, location} = request;
|
|
154
204
|
|
|
155
205
|
let { physical_address, query, history } = payload;
|
|
156
206
|
|
|
@@ -158,7 +208,9 @@ class Account extends Filesystem {
|
|
|
158
208
|
|
|
159
209
|
this.propagate(request, "run");
|
|
160
210
|
|
|
161
|
-
let pid = this.manage_buffer(
|
|
211
|
+
let pid = this.manage_buffer(location?res=>{
|
|
212
|
+
this.vm.air_object(res, {location})
|
|
213
|
+
} : callback,location&& callback);
|
|
162
214
|
|
|
163
215
|
let context = physical_address
|
|
164
216
|
? this.manager.web.get(physical_address)
|
|
@@ -166,50 +218,65 @@ class Account extends Filesystem {
|
|
|
166
218
|
|
|
167
219
|
if (!context) {
|
|
168
220
|
if (physical_address)
|
|
169
|
-
context = this.
|
|
221
|
+
context = this.vm.handle_chain(physical_address);
|
|
170
222
|
else return this.flush_buffer(pid);
|
|
171
223
|
}
|
|
224
|
+
if(!context)throw new Error()
|
|
172
225
|
|
|
173
226
|
let blk = query ? context.explore(query) : context.get_latest_block();
|
|
174
227
|
|
|
228
|
+
// console.log(context.stringify())
|
|
229
|
+
// console.log(blk)
|
|
230
|
+
|
|
175
231
|
if (!query) {
|
|
176
232
|
let index = context.height;
|
|
177
|
-
index -=
|
|
178
|
-
|
|
179
|
-
if (blk && blk.metadata.program) {
|
|
180
|
-
if (history) {
|
|
181
|
-
history--;
|
|
182
|
-
blk = null;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
while (!blk && index >= 0) {
|
|
187
|
-
index--;
|
|
188
|
-
blk = context.get_block(index);
|
|
233
|
+
index -= 1;
|
|
189
234
|
|
|
235
|
+
const historic = (blk) => {
|
|
190
236
|
if (blk && blk.metadata.program) {
|
|
191
237
|
if (history) {
|
|
192
238
|
history--;
|
|
193
239
|
blk = null;
|
|
194
240
|
}
|
|
195
|
-
}
|
|
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)
|
|
196
253
|
}
|
|
197
254
|
}
|
|
198
255
|
|
|
256
|
+
// console.log(blk)
|
|
257
|
+
|
|
199
258
|
if (blk && blk.metadata && blk.metadata.program) {
|
|
200
259
|
let program = this.read(blk.metadata.program);
|
|
201
260
|
|
|
202
|
-
|
|
203
|
-
|
|
261
|
+
if (Array.isArray(program) && program.length) {
|
|
262
|
+
this.vm.push_context(context);
|
|
263
|
+
program = [...program, 'pop']
|
|
264
|
+
|
|
265
|
+
// console.log(program)
|
|
204
266
|
|
|
205
|
-
Array.isArray(program) &&
|
|
206
|
-
program.length &&
|
|
207
267
|
this.manager.push({
|
|
208
268
|
sequence: program,
|
|
209
269
|
account: this,
|
|
270
|
+
payload,
|
|
271
|
+
error_stack: JSON.stringify(this.vm.error_manager),
|
|
210
272
|
pid,
|
|
211
273
|
});
|
|
212
|
-
|
|
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
|
+
}
|
|
213
280
|
};
|
|
214
281
|
|
|
215
282
|
run_callback = (callback, payload) => {
|
|
@@ -220,7 +287,7 @@ class Account extends Filesystem {
|
|
|
220
287
|
|
|
221
288
|
callback.payload &&
|
|
222
289
|
callback.payload.physical_address &&
|
|
223
|
-
this.vm.stdin(payload,
|
|
290
|
+
this.vm.stdin(payload, callback);
|
|
224
291
|
}, 0);
|
|
225
292
|
};
|
|
226
293
|
|
package/Objects/Block.js
CHANGED
|
@@ -7,18 +7,12 @@ class Block {
|
|
|
7
7
|
this.data = this.chain.txs;
|
|
8
8
|
this.metadata = {};
|
|
9
9
|
this.children = new Array();
|
|
10
|
-
this.index = this.chain.
|
|
10
|
+
this.index = this.chain.height;
|
|
11
11
|
this._id = _id(this.chain.hash);
|
|
12
|
-
|
|
13
|
-
this.blocks_folder = this.chain.account.manager.oracle.gds.folder(
|
|
14
|
-
process.env.BLOCKS_FOLDER || "blocks"
|
|
15
|
-
);
|
|
12
|
+
this.previous_hash = this.chain.recent_block && this.chain.recent_block._id
|
|
16
13
|
}
|
|
17
14
|
|
|
18
15
|
generate_hash = () => {
|
|
19
|
-
this.previous_hash = this.chain.get_latest_block();
|
|
20
|
-
if (this.previous_hash) this.previous_hash = this.previous_hash.hash;
|
|
21
|
-
|
|
22
16
|
this.hash = hash(JSON.stringify(this.data));
|
|
23
17
|
};
|
|
24
18
|
|
|
@@ -27,21 +21,32 @@ class Block {
|
|
|
27
21
|
if (!no_curs) this.cursor = this.chain.cursors.splice(-1)[0];
|
|
28
22
|
if (!content) return;
|
|
29
23
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
);
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
for (let c = 0; c < cursors.length; c++) {
|
|
32
|
+
let curs = cursors[c];
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
this.metadata[curs.slice(1, -1)] = content[curs];
|
|
35
|
+
delete content[curs];
|
|
36
|
+
}
|
|
39
37
|
}
|
|
38
|
+
|
|
39
|
+
|
|
40
40
|
this.metadata.stdout = new Array();
|
|
41
41
|
this.chain.account.flush_stdout(this);
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
}
|
|
45
50
|
};
|
|
46
51
|
|
|
47
52
|
stringify = (str) => {
|
|
@@ -55,7 +60,7 @@ class Block {
|
|
|
55
60
|
obj.previous_hash = this.previous_hash;
|
|
56
61
|
obj.data = this.data;
|
|
57
62
|
obj._id = this._id;
|
|
58
|
-
obj.children = this.children.map((ch) => ch._id);
|
|
63
|
+
obj.children = this.children.map((ch) => ch && ch._id);
|
|
59
64
|
obj.chain = {
|
|
60
65
|
hash: this.chain.hash,
|
|
61
66
|
physical_address: this.chain.physical_address,
|
|
@@ -71,6 +76,7 @@ class Block {
|
|
|
71
76
|
blck.datapath = data.datapath;
|
|
72
77
|
blck.timelapse = data.timelapse;
|
|
73
78
|
blck.index = data.index;
|
|
79
|
+
blck.previous_hash = data.previous_hash;
|
|
74
80
|
blck.hash = data.hash;
|
|
75
81
|
blck.data = data.data;
|
|
76
82
|
blck.children = data.children || [];
|
package/Objects/Blockweb.js
CHANGED
package/Objects/Chain.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _id } from "generalised-datastore/utils/functions";
|
|
1
2
|
import { hash } from "../utils/hash";
|
|
2
3
|
import Block from "./Block";
|
|
3
4
|
import Explorer from "./Explorer";
|
|
@@ -9,6 +10,7 @@ class Chain extends Explorer {
|
|
|
9
10
|
this.parent = parent;
|
|
10
11
|
this.account = this.parent.account;
|
|
11
12
|
this.name = name || this.parent.name;
|
|
13
|
+
|
|
12
14
|
this.physical_address =
|
|
13
15
|
this.parent.manager || !name
|
|
14
16
|
? this.parent.physical_address
|
|
@@ -16,8 +18,7 @@ class Chain extends Explorer {
|
|
|
16
18
|
|
|
17
19
|
this.pending_children = new Array();
|
|
18
20
|
this.connections = new Array();
|
|
19
|
-
|
|
20
|
-
this.blocks = new Array();
|
|
21
|
+
|
|
21
22
|
this.txs = new Array();
|
|
22
23
|
|
|
23
24
|
this.height = 0;
|
|
@@ -28,24 +29,53 @@ class Chain extends Explorer {
|
|
|
28
29
|
this.generate_hash();
|
|
29
30
|
|
|
30
31
|
this.folder = this.account.manager.oracle.gds.folder(this.hash);
|
|
31
|
-
this.height = this.folder.config.stats.
|
|
32
|
-
this.
|
|
32
|
+
this.height = this.folder.config.stats.files;
|
|
33
|
+
this.blocks = new Array(this.height);
|
|
34
|
+
|
|
35
|
+
if (this.folder.config.stats.chain)
|
|
36
|
+
this.datapath = this.folder.config.stats.chain.datapath
|
|
37
|
+
|
|
38
|
+
// console.log(this.folder.config)
|
|
33
39
|
|
|
34
40
|
this.account.set_paths(this);
|
|
35
41
|
|
|
36
42
|
this.manage_config(true);
|
|
43
|
+
|
|
44
|
+
if (this.folder.config.stats.recent_file){
|
|
45
|
+
this.recent_block = this.build_block(this.folder.config.stats.recent_file);
|
|
46
|
+
this.blocks[this.recent_block.index] = this.recent_block
|
|
47
|
+
}
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
manage_config = (init) => {
|
|
40
51
|
if (init) {
|
|
41
|
-
let dir = this.account.manager.oracle.fs.readdirSync(this.folder.path);
|
|
42
|
-
this.blocks = dir.filter((d) => d !== ".config");
|
|
43
|
-
this.height = this.blocks.length;
|
|
44
52
|
}
|
|
45
53
|
|
|
46
|
-
this.folder.config.add_entry("
|
|
54
|
+
this.folder.config.add_entry("chain", this.stringify());
|
|
47
55
|
};
|
|
48
56
|
|
|
57
|
+
set_fee = ({purpose, fee, validator})=>{
|
|
58
|
+
this.fees.set({purpose, fee, validator})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get_fee = purpose =>{
|
|
62
|
+
return this.fees.get(purpose)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
pay = (purpose, payer, cb) =>{
|
|
66
|
+
let account = this.account.manager.get_account(payer)
|
|
67
|
+
let token = this.get_fee(purpose)
|
|
68
|
+
|
|
69
|
+
account.process_fee(token, cb)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
set_obj_config = config=>{
|
|
73
|
+
let addr = typeof config === 'string'? config: this.account.save(config)
|
|
74
|
+
|
|
75
|
+
this.datapath = addr;
|
|
76
|
+
this.manage_config()
|
|
77
|
+
}
|
|
78
|
+
|
|
49
79
|
append_buffer = () => {
|
|
50
80
|
this.buffs.push({});
|
|
51
81
|
this.cursors.push(this.cursor);
|
|
@@ -66,18 +96,45 @@ class Chain extends Explorer {
|
|
|
66
96
|
this.hash = hash(this.physical_address);
|
|
67
97
|
};
|
|
68
98
|
|
|
69
|
-
build_block = (blk) => {
|
|
99
|
+
build_block = (blk, forge) => {
|
|
70
100
|
if (typeof blk === "string") {
|
|
71
101
|
let blk_data = this.folder.readone(blk, { depth: 1 });
|
|
72
102
|
|
|
73
|
-
|
|
103
|
+
if (blk_data){
|
|
104
|
+
blk = Block.build(blk_data, this);
|
|
105
|
+
}
|
|
106
|
+
}else if (forge){
|
|
107
|
+
if(!blk.hash) blk.hash = hash(JSON.stringify(blk))
|
|
108
|
+
blk = Block.build(blk, this)
|
|
109
|
+
}
|
|
110
|
+
return blk;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
traverse_blocks = (stop) => {
|
|
114
|
+
let blk = this.blocks.slice(stop).find(b=>b && b._id);
|
|
115
|
+
|
|
116
|
+
while (blk&& blk.index !== stop) {
|
|
117
|
+
blk = this.build_block(blk.previous_hash);
|
|
118
|
+
|
|
74
119
|
}
|
|
75
120
|
return blk;
|
|
76
121
|
};
|
|
77
122
|
|
|
78
123
|
get_block = (index) => {
|
|
124
|
+
index = index == null ? this.height -1 : index
|
|
79
125
|
let blk = this.blocks[index];
|
|
80
|
-
|
|
126
|
+
|
|
127
|
+
if(blk) blk = this.build_block(blk);
|
|
128
|
+
|
|
129
|
+
if (!blk||(blk&& blk.index !== index)) {
|
|
130
|
+
console.log("Twisted chain", index,blk&& blk.index, this.physical_address);
|
|
131
|
+
if (index < this.height) {
|
|
132
|
+
blk = this.traverse_blocks(index);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if(blk&& !isNaN(Number(blk.index)))this.blocks[blk.index] = blk
|
|
136
|
+
|
|
137
|
+
return blk;
|
|
81
138
|
};
|
|
82
139
|
|
|
83
140
|
add_tx = (instruction) => {
|
|
@@ -86,29 +143,55 @@ class Chain extends Explorer {
|
|
|
86
143
|
this.txs.push(instruction);
|
|
87
144
|
};
|
|
88
145
|
|
|
146
|
+
fabricate_datapath_block=()=>{
|
|
147
|
+
if(!this.datapath)return this.stderr({"name":"Chain_error",'message':'Cannot fabricate datapath block of no-call chain'})
|
|
148
|
+
|
|
149
|
+
return this.build_block({metadata:{output:this.datapath}, index:0, _id: _id(this.hash)}, true)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
forge_block = (obj)=>{
|
|
153
|
+
obj.index = this.height
|
|
154
|
+
obj._id = _id(this.hash)
|
|
155
|
+
obj.previous_hash = this.recent_block && this.recent_block._id
|
|
156
|
+
|
|
157
|
+
let blk = this.build_block(obj, true)
|
|
158
|
+
|
|
159
|
+
this.add_block(blk)
|
|
160
|
+
|
|
161
|
+
return blk
|
|
162
|
+
}
|
|
163
|
+
|
|
89
164
|
mine = (vm, no_curs) => {
|
|
165
|
+
|
|
166
|
+
if (this.physical_address === `${this.account.physical_address}/Datatypes/Void` && this.height){
|
|
167
|
+
let blk = this.get_latest_block()
|
|
168
|
+
vm.connect_block(blk)
|
|
169
|
+
|
|
170
|
+
return blk
|
|
171
|
+
}
|
|
172
|
+
|
|
90
173
|
let block = new Block(this);
|
|
91
174
|
|
|
92
175
|
block.generate_hash();
|
|
93
|
-
this.add_block(block);
|
|
94
|
-
|
|
95
176
|
block.store(no_curs);
|
|
96
177
|
|
|
97
178
|
block.children = this.pending_children;
|
|
98
179
|
this.pending_children = new Array();
|
|
99
180
|
|
|
100
|
-
|
|
101
|
-
if (prev_context) {
|
|
102
|
-
prev_context.pending_children.push(block);
|
|
103
|
-
prev_context.connections.push(block);
|
|
104
|
-
}
|
|
181
|
+
block.timelapse = Date.now() - this.start_time;
|
|
105
182
|
|
|
106
|
-
this.
|
|
183
|
+
this.add_block(block);
|
|
107
184
|
|
|
108
|
-
|
|
185
|
+
vm.connect_block(block)
|
|
186
|
+
|
|
187
|
+
this.txs = new Array();
|
|
109
188
|
|
|
110
189
|
this.manage_config();
|
|
111
190
|
|
|
191
|
+
return block;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
persist = block=>{
|
|
112
195
|
let data = block.stringify();
|
|
113
196
|
|
|
114
197
|
data = this.account.manager.oracle.handle_compression({
|
|
@@ -117,22 +200,36 @@ class Chain extends Explorer {
|
|
|
117
200
|
no_string: true,
|
|
118
201
|
});
|
|
119
202
|
|
|
203
|
+
if(!data.previous_hash &&data.index!==0){
|
|
204
|
+
console.log(data)
|
|
205
|
+
return this.account.vm.stderr({name:"Chain_error", message:"chain corruption, as a non index 0 block is without a previous_hash"})
|
|
206
|
+
}
|
|
207
|
+
|
|
120
208
|
this.folder.write(data);
|
|
121
|
-
|
|
122
|
-
};
|
|
209
|
+
}
|
|
123
210
|
|
|
124
211
|
add_block = (block) => {
|
|
125
|
-
let recent_blk = this.get_latest_block();
|
|
126
|
-
block.previous_hash = recent_blk && recent_blk._id;
|
|
127
212
|
this.blocks.push(block);
|
|
128
|
-
this.height
|
|
213
|
+
this.height++;
|
|
214
|
+
|
|
215
|
+
if (!this.physical_address.startsWith(`${this.account.physical_address}/Opcodes`) && Array.from(Object.keys(block.metadata)).length){
|
|
216
|
+
this.persist(block)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
this.recent_block = block;
|
|
220
|
+
|
|
221
|
+
if (this.account.initiated){
|
|
222
|
+
let parent_addr = this.parent.physical_address
|
|
223
|
+
if (this.account.vm.stack.has_stack(parent_addr)){
|
|
224
|
+
this.account.vm.stack.push(parent_addr, block);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
129
227
|
};
|
|
130
228
|
|
|
131
229
|
get_latest_block = () => {
|
|
132
|
-
let blk = this.
|
|
133
|
-
blk = this.build_block(blk);
|
|
230
|
+
let blk = this.recent_block;
|
|
134
231
|
|
|
135
|
-
return blk;
|
|
232
|
+
return this.build_block(blk);
|
|
136
233
|
};
|
|
137
234
|
|
|
138
235
|
stringify = (str) => {
|
|
@@ -143,6 +240,7 @@ class Chain extends Explorer {
|
|
|
143
240
|
obj.parent = this.parent.path;
|
|
144
241
|
obj.account = this.parent.account.name;
|
|
145
242
|
obj.name = this.name;
|
|
243
|
+
obj.datapath = this.datapath
|
|
146
244
|
obj.connections = this.connections.map((b) =>
|
|
147
245
|
b.stringify
|
|
148
246
|
? new Object({
|
|
@@ -152,7 +250,7 @@ class Chain extends Explorer {
|
|
|
152
250
|
: b
|
|
153
251
|
);
|
|
154
252
|
obj.hash = this.hash;
|
|
155
|
-
obj.blocks = this.blocks.map((blk) => blk.hash || blk);
|
|
253
|
+
// obj.blocks = this.blocks.map((blk) => blk.hash || blk);
|
|
156
254
|
|
|
157
255
|
return str ? JSON.stringify(obj) : obj;
|
|
158
256
|
};
|
package/Objects/Explorer.js
CHANGED
|
@@ -18,25 +18,11 @@ class Explorer {
|
|
|
18
18
|
|
|
19
19
|
let obj;
|
|
20
20
|
if (isNaN(q2)) {
|
|
21
|
-
|
|
22
|
-
for (let b = 0; b < arr.length; b++) {
|
|
23
|
-
let blk = this.build_block(arr[b]);
|
|
24
|
-
if (blk.hash === query[1]) {
|
|
25
|
-
obj = blk;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
21
|
+
obj = this[prop || "connections"].find((c) => c.hash === query[1]);
|
|
29
22
|
} else if (q2 >= 0) {
|
|
30
|
-
|
|
31
|
-
for (let b = 0; b < arr.length; b++) {
|
|
32
|
-
let blk = this.build_block(arr[b]);
|
|
33
|
-
if (blk.index === q2) {
|
|
34
|
-
obj = blk;
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
23
|
+
obj = this[prop || "connections"].find((q) => q.index === q2);
|
|
38
24
|
} else {
|
|
39
|
-
obj = this
|
|
25
|
+
obj = this[prop || "connections"].slice(q2)[0];
|
|
40
26
|
}
|
|
41
27
|
|
|
42
28
|
if (!prop)
|
package/Objects/Fee.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class Fee {
|
|
2
|
+
constructor(chain){
|
|
3
|
+
this.chain = chain;
|
|
4
|
+
|
|
5
|
+
this.fees = new Object()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
set = ({purpose, fee, validator})=>{
|
|
9
|
+
let fees= this.fees[purpose]
|
|
10
|
+
if (!fees){
|
|
11
|
+
fees = new Array();
|
|
12
|
+
this.fees[purpose] = fees;
|
|
13
|
+
}
|
|
14
|
+
fees.push({fee, validator})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get = (purpose)=>{
|
|
18
|
+
let fees = this.fees[purpose]
|
|
19
|
+
if (!fees)return
|
|
20
|
+
|
|
21
|
+
return fees.slice(-1)[0]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Fee is a physical_address
|
|
26
|
+
// Validator is also a physical_address
|
|
27
|
+
// If fee address is a callable/executable
|
|
28
|
+
// validator runs itself using the result from the address using the payload as argument 0
|
|
29
|
+
// Else if fee is a datastructure,
|
|
30
|
+
// validator runs itself using data as argument.
|
|
31
|
+
// Validator must return a true, to pass.
|
|
32
|
+
|
|
33
|
+
// A chain can have multiple price purposes.
|