godprotocol 1.1.0 → 1.1.2

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.
Files changed (98) hide show
  1. package/Datatypes/arr.js +11 -0
  2. package/Datatypes/bool.js +11 -0
  3. package/Datatypes/callable.js +11 -0
  4. package/Datatypes/functions/storage.js +5 -0
  5. package/Datatypes/num.js +11 -0
  6. package/Datatypes/str.js +11 -0
  7. package/Datatypes/twa.js +11 -0
  8. package/Datatypes/voi.js +11 -0
  9. package/Index.js +36 -2
  10. package/Objects/Account.js +35 -322
  11. package/Objects/Block.js +7 -80
  12. package/Objects/Blockweb.js +19 -26
  13. package/Objects/Callable.js +40 -0
  14. package/Objects/Chain.js +20 -244
  15. package/Objects/GDS/Arena_classic/.config +1 -0
  16. package/Objects/GDS/Arena_classic/Accounts/lola/.config +1 -0
  17. package/Objects/Manager.js +28 -294
  18. package/Objects/Oracle.js +67 -84
  19. package/Objects/Repository.js +67 -0
  20. package/Objects/Trinity.js +24 -0
  21. package/Objects/Virtual_machine.js +16 -206
  22. package/callables/functions/assign.js +6 -0
  23. package/callables/functions/display.js +3 -0
  24. package/callables/register.js +22 -0
  25. package/package.json +24 -43
  26. package/utils/create_server.js +35 -88
  27. package/utils/functions.js +0 -70
  28. package/utils/server.cert +23 -0
  29. package/utils/server.key +28 -0
  30. package/utils/services.js +61 -21
  31. package/utils/vm_utils.js +53 -275
  32. package/Executables/callables.js +0 -131
  33. package/Executables/executables.js +0 -230
  34. package/Executables/functions/adminstrator/adm_register.js +0 -29
  35. package/Executables/functions/adminstrator/native_components.js +0 -10
  36. package/Executables/functions/adminstrator/query_selectors.js +0 -10
  37. package/Executables/functions/adminstrator/render.js +0 -24
  38. package/Executables/functions/array_register.js +0 -161
  39. package/Executables/functions/assign.js +0 -19
  40. package/Executables/functions/display.js +0 -55
  41. package/Executables/functions/folder.js +0 -95
  42. package/Executables/functions/folder_register.js +0 -87
  43. package/Executables/functions/importcheck.js +0 -13
  44. package/Executables/functions/indices.js +0 -56
  45. package/Executables/functions/len.js +0 -22
  46. package/Executables/functions/methods/array.js +0 -272
  47. package/Executables/functions/methods/string.js +0 -197
  48. package/Executables/functions/methods/twain.js +0 -148
  49. package/Executables/functions/op.js +0 -15
  50. package/Executables/functions/price_register.js +0 -30
  51. package/Executables/functions/pricing.js +0 -26
  52. package/Executables/functions/servers/account.js +0 -81
  53. package/Executables/functions/servers/account_register.js +0 -56
  54. package/Executables/functions/servers/block.js +0 -21
  55. package/Executables/functions/servers/block_register.js +0 -18
  56. package/Executables/functions/servers/chain.js +0 -42
  57. package/Executables/functions/servers/chain_register.js +0 -28
  58. package/Executables/functions/set_error_catch.js +0 -34
  59. package/Executables/functions/string_register.js +0 -130
  60. package/Executables/functions/twain_register.js +0 -56
  61. package/Executables/functions/typecast.js +0 -43
  62. package/Executables/functions/utils.js +0 -9
  63. package/Executables/stack.js +0 -53
  64. package/Loader_sequence/main.js +0 -805
  65. package/Loader_sequence/repository.js +0 -33
  66. package/Objects/Explorer.js +0 -40
  67. package/Objects/Fee.js +0 -33
  68. package/Objects/Filesystem.js +0 -216
  69. package/Objects/Frame.js +0 -54
  70. package/Objects/Opcodes.js +0 -87
  71. package/Objects/Protocol.js +0 -5
  72. package/Trinity.js +0 -20
  73. package/callables.js +0 -172
  74. package/framer.js +0 -124
  75. package/opcodes/add.js +0 -15
  76. package/opcodes/indices.js +0 -82
  77. package/opcodes/jmp.js +0 -16
  78. package/opcodes/std.js +0 -12
  79. package/opcodes.js +0 -96
  80. package/readme.md +0 -133
  81. package/starter_scripts/constants.seq +0 -11
  82. package/tsconfig.json +0 -8
  83. package/types/Account.d.ts +0 -73
  84. package/types/Block.d.ts +0 -22
  85. package/types/Blockweb.d.ts +0 -14
  86. package/types/Chain.d.ts +0 -35
  87. package/types/Explorer.d.ts +0 -9
  88. package/types/Filesystem.d.ts +0 -23
  89. package/types/Frame.d.ts +0 -14
  90. package/types/Manager.d.ts +0 -21
  91. package/types/Opcodes.d.ts +0 -11
  92. package/types/Oracle.d.ts +0 -17
  93. package/types/Virtual_machine.d.ts +0 -20
  94. package/types/index.d.ts +0 -4
  95. package/utils/hash.js +0 -13
  96. package/utils/logger.js +0 -79
  97. package/utils/privacy.js +0 -22
  98. package/utils/type_coersion.js +0 -3
package/utils/vm_utils.js CHANGED
@@ -1,292 +1,70 @@
1
- import { generate_random_string } from "generalised-datastore/utils/functions";
2
- import Executables from "../Executables/executables";
1
+ import Arr from "../Datatypes/arr";
2
+ import Callable from "../Datatypes/callable";
3
+ import Num from "../Datatypes/num";
4
+ import Str from "../Datatypes/str";
5
+ import Twa from "../Datatypes/twa";
6
+ import Voi from "../Datatypes/voi";
3
7
 
4
- class Vm_utils extends Executables{
5
- constructor(){
6
- super()
8
+ class Vm_utils {
9
+ constructor() {}
7
10
 
8
- setTimeout(() => {
9
- this. air_object_paths = new Array(
10
- `${this.account.physical_address}/language/natives/datatypes/string/String`,
11
- `${this.account.physical_address}/language/natives/datatypes/number/Number`,
12
- `${this.account.physical_address}/language/natives/datatypes/twain/Twain`,
13
- `${this.account.physical_address}/language/natives/datatypes/array/Array`,
14
- `${this.account.physical_address}/language/natives/datatypes/boolean/Boolean`,
15
- `${this.account.physical_address}/language/natives/datatypes/void/Void`,
16
- `${this.account.physical_address}/language/natives/server/chain/Chain`,
17
- `${this.account.physical_address}/language/natives/server/block/Block`,
18
- `${this.account.physical_address}/language/natives/server/chain/Chain`,
19
- )
20
- }, 0);
11
+ handle_chain = async (address) => {
12
+ let chain = await this.account.manager.web.spli_get(address);
21
13
 
22
- this.error_instance_address = "Accounts/initiator/language/natives/errors"
23
-
24
- this.air_types = new Array('boolean', 'string', 'twain', 'array', 'number', 'void')
25
- }
26
-
27
- set_config = (config)=>{
28
- config = config.op0;
29
- let chain = this.handle_chain(config.__address__);
30
- chain.set_obj_config(config)
31
- }
32
-
33
- get_context = (index) => {
34
- return this.contexts.slice(index == null ? -1 : index)[0];
14
+ return chain;
35
15
  };
36
16
 
37
- parse_arg = (arg, opcode) => {
38
- let context = this.get_context();
39
-
40
- let args = arg.split("/"),
41
- i = 0;
42
-
43
- while (args[0] === "..") {
44
- i++;
45
-
46
- args.splice(0, 1);
47
- }
48
-
49
- i = (i + 1) * -1;
50
- context = i ? this.get_context(i) : context;
51
-
52
- arg = args.join("/");
17
+ get_type = (object) => {
18
+ let type = typeof object;
53
19
 
54
- while (arg.includes("^")) {
55
- let blk = context.connections.slice(-1)[0];
56
- if (!blk) break;
57
- context = blk.chain;
58
- let i = arg.indexOf("^");
59
- arg = `${arg.slice(0, i)}${arg.slice(i + 1)}`;
20
+ if (type == "object") {
21
+ if (Array.isArray(object)) type = "array";
22
+ else if (!type) type = "void";
23
+ else type = "twain";
60
24
  }
61
-
62
- let is_cursor = opcode === 'cursor'
63
- if (arg.startsWith("{*") && is_cursor) {
64
- arg = context.explore(arg.slice(2, -1));
65
- } else if (arg.startsWith("{") && !is_cursor) {
66
- arg = context.explore(arg.slice(1, -1));
67
- if (['chain', 'link'].includes(opcode) && arg.includes('/')){
68
- arg = this.account.read(arg)
69
- }
70
- }
71
-
72
- return arg;
25
+ return type;
73
26
  };
74
27
 
75
- split_instruction = (instruction) => {
76
- let split = instruction.split(" ");
77
- let opcode = split[0],
78
- args = split.slice(1).join(" ");
79
-
80
- return { opcode, args };
81
- };
82
-
83
- handle_chain = (args, context)=>{
84
- if (!args) return
85
- if(!context) context = this.account.chain
86
-
87
- let web = context.account.manager.web, chain;
88
-
89
- if (args.includes('/')){
90
- chain = web.get(args)||web.split_set(args);
91
- } else chain = context.account.add_chain(args, context);
92
-
93
- return chain
94
- }
95
-
96
- read_chain = (addr, options)=>{
97
- options = options || {}
98
- let {no_callable, tell_callable, index} = options, callable;
99
-
100
- if(!addr) return this.stderr(`Physical address cannot be undefined`)
101
- let chn = addr.physical_address? addr: this.handle_chain(addr)
102
-
103
- if (!chn)return this.stderr(`Address chain:${addr.physical_address ||addr} not found`)
104
-
105
- let output;
106
- if (chn.datapath && !no_callable){
107
- output = chn.datapath
108
- callable = true;
109
- }else {
110
- callable = false
111
- if (!chn.height) return no_callable?null: this.stderr(`Chain has no height - ${addr.physical_address || addr}`)
112
-
113
- let recent = chn.get_block(index)
114
-
115
- output = recent.metadata.output;
116
-
117
- if (!output)return;
118
- }
119
- output = this.account.read(output)
120
-
121
- return tell_callable? {output, callable} :output;
122
- }
123
-
124
- connect_block = block=>{
125
- if(!block){
126
- console.log(`Checkengine`)
127
- return;
28
+ parse_content = async (object, options) => {
29
+ let { type } = options || {};
30
+ if (!type) type = this.get_type(object);
31
+
32
+ let instance;
33
+ switch (type) {
34
+ case "number":
35
+ instance = new Num(object);
36
+ break;
37
+ case "string":
38
+ instance = new Str(object);
39
+ break;
40
+ case "array":
41
+ instance = new Arr(object);
42
+ break;
43
+ case "twain":
44
+ instance = new Twa(object);
45
+ break;
46
+ case "function":
47
+ instance = new Callable(object);
48
+ break;
49
+ case "class":
50
+ instance = new Callable(object);
51
+ break;
52
+ default:
53
+ instance = new Voi();
128
54
  }
129
- let prev_context = this.get_context(-2);
130
- if (prev_context) {
131
- if(block.chain.datapath){
132
- block.metadata.output = block.datapath
133
- }
134
- prev_context.pending_children.push(block);
135
- prev_context.connections.push(block);
136
- }
137
- }
138
55
 
139
- get_type_address =type=>{
140
- return this.air_object_paths.find(p=>p.includes(type))
141
- }
56
+ return instance;
57
+ };
142
58
 
143
- parse_composite_content = (content, options)=>{
144
- let {item_type, location} = options;
59
+ read_chain = async (address) => {
60
+ let chain = await this.handle_chain(address);
145
61
 
146
- if (item_type === 'static_object'){
147
- for (let c = 0; c< content.length; c++){
148
- let cont = content[c]
149
- let cont_addr = `${location}_${c}`
150
- this.write_chain(cont, cont_addr)
151
- content[c] = cont_addr;
152
- }
153
- }
62
+ let content = await chain.read();
63
+ content =
64
+ (content && (await content.parse())) || (await this.parse_content(null));
154
65
 
155
66
  return content;
156
- }
157
-
158
- air_object = (content, options)=>{
159
- let {location, callback, local_address, metadata} = options;
160
-
161
- if (Array.isArray(content)){
162
- content= this.parse_composite_content(content, options)
163
- }
164
-
165
- let static_location = `${local_address || location}_${generate_random_string(8, 'alnum')}`
166
-
167
- let statc = this.static_cast(content, static_location)
168
- let type = typeof statc === 'string' ? 'void' : statc.type
169
-
170
- this.stdin(statc,()=> this.exec({
171
- executable: this.get_type_address(type),
172
- location,
173
- metadata:{callback, ...metadata},
174
- arguments: {
175
- argc:1,
176
- argv:[{position: 0, address: static_location, name:'value'}]
177
- }}),
178
- {address: static_location}
179
- )
180
- }
181
-
182
- id_hash = (data)=>{
183
- let res = this.account.manager.oracle.hash(data, 'sha-1')
184
- if (!isNaN(Number(res[0]))){
185
- res = `_${res}`
186
- }
187
-
188
- return res;
189
- }
190
-
191
- get_voided_block = ()=>{
192
- if(!this.account.initiated)return
193
-
194
- let Void = this.account.get_datatype_chain(`Void`)
195
- this.flags.void = true;
196
- return Void && Void.get_latest_block()
197
- }
198
-
199
- modify_twain = (twa, chain, config)=>{
200
-
201
- if (twa.__index__){
202
- if (typeof twa.__index__ === 'number') twa.__index__ = chain.height
203
- else twa.__index__[config.name] = chain.height
204
- }
205
- return twa
206
- }
207
-
208
- slice_trace = (s)=>{
209
- let s_length = this.stacktrace.length;
210
- for(let i=0; i < s_length - s; i++ ) this.pop_context()
211
- }
212
-
213
- push_context = context => {
214
- this.contexts.push(context)
215
- this.stacktrace.push(context.physical_address)
216
- // console.log(`>> Current Stack - ${context.physical_address}`)
217
- }
218
-
219
- pop_context = () => {
220
- let context = this.contexts.pop()
221
- let addr = this.stacktrace.pop()
222
-
223
- // console.log(`> Current Stack - ${this.contexts.slice(-1)[0].physical_address}`)
224
-
225
- if(context && context.physical_address !== addr)
226
- this.stderr(`Stack missalignment - ${context.physical_address} : ${addr}`)
227
- }
228
-
229
-
230
- run_opcode = (arg_arr, opcode)=>{
231
- let circ = this.opcodes[opcode]
232
-
233
- if (!circ)return this.stderr(`Opcode:${opcode} not set`)
234
-
235
- let arg = {}
236
- arg_arr.map((a,i)=>{
237
- arg[`op${i.toString()}`] = a
238
- })
239
-
240
- return circ(arg, this)
241
- }
242
-
243
- static_cast = (content, addr)=>{
244
- let res_obj = {}
245
- let type = typeof content;
246
- if(type === 'object' || type === 'undefined'){
247
- if(content == null){
248
- res_obj = "{'type':'void','static_value':Void,'__address__':'Accounts/initiator/Datatypes/Void'}"
249
- }else if (Array.isArray(content)){
250
- res_obj = {type:'array', static_value: content}
251
- }else res_obj = {type:'twain', static_value: content}
252
- }else {
253
- res_obj = {type, static_value: content}
254
- }
255
-
256
- if (addr && typeof res_obj !== 'string') {
257
- res_obj.__address__ = addr
258
- }
259
-
260
- return res_obj
261
- }
262
-
263
- is_readonly = (args)=>{
264
- if (args.op1.startsWith('__') && args.op1.endsWith('__') && args.op1 !== '__'){
265
- let val = args.op0[args.op1]
266
- let chn = this.handle_chain(`${val}/.config`)
267
- let recent = chn.get_latest_block()
268
- let value;
269
- if(recent){
270
- value = recent.metadata.output;
271
- value = this.account.read(value)
272
- if (value && !['function', 'class'].includes(value.type)){
273
- return this.stderr('Cannot delete `readonly` property')
274
- }
275
- }
276
- }
277
- }
278
-
279
- static_value = (value, blow)=>{
280
- if (value && value.__print__){
281
- if(this.air_object_paths.includes(value.__classifier__)){
282
- value = this.read_chain(value.value)
283
- }else if (blow){
284
- return
285
- }
286
- }
287
-
288
- return value
289
- }
67
+ };
290
68
  }
291
69
 
292
- export default Vm_utils
70
+ export default Vm_utils;
@@ -1,131 +0,0 @@
1
- class Callables{
2
- constructor(){
3
- this.callables = new Object()
4
- }
5
-
6
- prepare_callable_args = (config, payload)=>{
7
-
8
- let {arguments:args} = payload;
9
- let {argv} = args;
10
-
11
- let arg_obj = {}, spreading;
12
-
13
- for (let a=0;a< argv.length;a++){
14
- let arg = argv[a]
15
-
16
- let param, content = arg.static_value || this.read_chain(arg.address)
17
- if(spreading){
18
- arg_obj[spreading].push(content)
19
- } else {
20
- if (arg.name){
21
- arg_obj[arg.name] = content;
22
- param = config.parameters.find(p=>p.name === arg.name)
23
- }else {
24
- param = config.parameters[arg.position]
25
- if(!param)continue
26
- arg_obj[param.name] = content
27
- }
28
-
29
- if (param.spread){
30
- spreading = param.name;
31
- arg_obj[spreading] = [arg_obj[spreading]]
32
- }
33
- }
34
- }
35
-
36
- return arg_obj
37
- }
38
-
39
- callable = (payload)=>{
40
- let {executable, metadata, location} = payload;
41
- if (!metadata)metadata = {}
42
-
43
- let call = this.callables[executable];
44
- if(!call)return this.stderr(`Callable:${executable} is not set`)
45
-
46
- let callable = call.callable;
47
- let config = call.config
48
-
49
- if (typeof callable !== 'function') return this.stderr(`Callable:${executable} must be a callable type.`)
50
-
51
-
52
- let args;
53
- if (config) {
54
- args = this.prepare_callable_args(config, payload)
55
- }
56
-
57
- let result = callable(args, this, {...payload, location})
58
- if (!metadata.raw )
59
- result && this.write_chain(result.result,result.address|| location, {is_callable: result.is_callable})
60
-
61
- return metadata.raw ? result : {
62
- estimated_time: '-ms',
63
- callback: location
64
- }
65
- }
66
-
67
- write_chain = (result, location, options)=>{
68
- if (result==null)return
69
- let {is_callable}=options || {};
70
-
71
- let loc_chain = this.handle_chain(location)
72
-
73
- if(is_callable){
74
- loc_chain.set_obj_config(result)
75
- }else {
76
- loc_chain.forge_block({metadata: {output: this.account.save(result)}})
77
- }
78
- }
79
-
80
- add_callable = (name, callable_config)=>{
81
- this.callables[name] = callable_config
82
- }
83
-
84
- composite_depth = 3
85
-
86
- display = (values, options )=>{
87
- let {buff, depth, include_address} = options || {}, value;
88
- if (!buff) buff = new Object()
89
-
90
- if (!values)return values
91
-
92
- if (values.__print__ ){
93
- let stat = this.static_value(values, true)
94
- if(!stat)return values;
95
- value = stat
96
- }else value = values
97
-
98
- let hash = this.account.manager.oracle.hash(value);
99
- if (buff[hash]) return buff[hash]
100
-
101
- if(value.type === 'array'){
102
- let arr = []
103
- for (let a=0; a< value.static_value.length; a++){
104
- arr.push(this.display(this.read_chain(value.static_value[a]), {buff}))
105
- }
106
- value = arr;
107
- }else if (value.type === 'twain'){
108
- let keys = Object.keys(value.static_value)
109
- let obj = {}
110
- for (let s=0; s< keys.length; s++){
111
- let key = keys[s]
112
- let pair = value.static_value[key]
113
-
114
- let prop = this.display(this.read_chain(pair[0]), {buff})
115
-
116
- obj[prop] = this.display(this.read_chain(pair[1]), {buff})
117
- }
118
- value = obj
119
- }else if (['string', 'number', 'boolean'].includes(value.type)){
120
- value = value.static_value
121
- }else value = (value && value.__address__) || value
122
-
123
- buff[hash] = value;
124
-
125
- if (depth == null){
126
- return value;
127
- }
128
- }
129
- }
130
-
131
- export default Callables
@@ -1,230 +0,0 @@
1
- import { generate_random_string } from "generalised-datastore/utils/functions";
2
- import Callables from "./callables";
3
- import Stack from "./stack";
4
- import { post_request } from "godprotocol/utils/services";
5
-
6
-
7
- class Executables extends Callables{
8
- constructor(){
9
- super()
10
-
11
- this.stack = new Stack(this)
12
- }
13
-
14
- exec = (request)=>{
15
- let payload = request.op0 || request;
16
-
17
- let {executable, url_callback, location} = payload;
18
- console.log(request)
19
-
20
- if (!executable && request.op1) executable = request.op1.static_value
21
-
22
- if(typeof executable !== 'string' && executable){
23
- executable = executable.static_value || executable.__address__
24
- }
25
- if(!executable)return this.stderr({name: 'Call_error', message:"Executable cannot be undefined"})
26
-
27
- if (!executable.includes('/')){
28
- let result = this.callable(payload)
29
- if (url_callback) post_request({options:url_callback, data: result})
30
- return result
31
- }
32
-
33
- if(executable.includes('undefined')){
34
- console.log(executable)
35
- let err_obj = {name:'Type_error', message: `executable cannot have an undefined config`}
36
- return this.stderr(err_obj)
37
- }
38
-
39
- // console.log(payload)
40
- let config = this.get_config(executable)
41
- if (!config){
42
- return this.stderr({name:'Name_error', message:'Callable config not existing'})
43
- }
44
-
45
- switch(config.type){
46
- case "class":
47
- this.execute_class(config, payload)
48
- break;
49
- case "function":
50
- this.execute_function(config, payload)
51
- break;
52
- case "module":
53
- this.execute_module(config, payload)
54
- break;
55
- default:
56
- this.stderr(`Unknown call type`)
57
- ;
58
- }
59
-
60
- return {
61
- estimated_time: `-ms`,
62
- callback: location,
63
- }
64
- }
65
-
66
- execute_class = (config, payload)=>{
67
- let {methods, base_classes} = config;
68
- let {location, local_address, url_callback, executable} = payload;
69
-
70
- let object = {__classifier__:executable, __type__: `${this.account.physical_address}/CONSTANTS/types/instance`}
71
- let object_id = generate_random_string(12, 'alnum')
72
- object.__id__ = object_id
73
-
74
- let real_path = `${local_address || location}_${object_id}`
75
- let object_chain = this.handle_chain(real_path)
76
-
77
- let location_height = object_chain.height;
78
-
79
- for (let b=0; b< base_classes.length; b++){
80
- let cls = base_classes[b]
81
- let cls_config = this.get_config(cls);
82
-
83
- if(!cls_config || (cls_config && cls_config.type !== 'class')){
84
- return this.stderr(`Base must be a 'class' type`)
85
- }
86
-
87
- let {methods: b_methods} = cls_config;
88
- for(let name in b_methods){
89
- let method_addr = b_methods[name]
90
-
91
- this.handle_method_config({name, method_addr, object, location: real_path, location_height})
92
- }
93
- }
94
- for(let name in methods){
95
- let method_addr = methods[name]
96
-
97
- this.handle_method_config({name, method_addr, object, location: real_path, location_height})
98
- }
99
-
100
- object.__address__ = real_path;
101
-
102
- object_chain.forge_block({metadata:{output: this.account.save(object)}})
103
-
104
- if (object.__init__){
105
- this.execute_function(this.get_config(object.__init__), {...payload, executable: object.__init__})
106
- }else {
107
- if (url_callback) post_request({options:url_callback, data: object})
108
- }
109
- }
110
-
111
- execute_function = (config, payload)=>{
112
- let {arguments: args, location, url_callback, executable, metadata}=payload;
113
- let {argv, argc} = args ||{};
114
- argv = argv || []
115
- let {parameters, object, __address__, method_address} = config;
116
-
117
- let exec_address = method_address || __address__
118
-
119
- this.stack.initiate(exec_address)
120
-
121
- let arg_object = {}
122
- parameters.map((p, i)=>{
123
- arg_object[p.name] = {address: p.address, name: p.name, position: p.position || i}
124
- })
125
-
126
- for (let a =0; a< (argc || argv.length); a++){
127
- let arg = argv[a]
128
- let param;
129
- if (arg.name) {
130
- param = parameters.find(p=>p.name === arg.name)
131
- } else {
132
- param = parameters[arg.position]
133
- arg.name = param.name
134
- }
135
-
136
- arg_object[arg.name].address = arg.address
137
- }
138
-
139
- if(object){
140
- arg_object.this = {
141
- position:-1,
142
- address: object,
143
- name:'this'
144
- }
145
- }
146
-
147
- for (let a in arg_object) {
148
- let arg = arg_object[a]
149
- let param_addr = `${exec_address}/${a}`
150
- let param_chain = this.handle_chain(param_addr);
151
-
152
- let arg_chain = this.handle_chain(arg.address)
153
-
154
- if(arg_chain.datapath){
155
- param_chain.set_obj_config(arg_chain.datapath)
156
- }else {
157
- let val = this.read_chain(arg_chain)
158
- param_chain.forge_block({metadata: {output: this.account.save(val)}})
159
- }
160
- }
161
-
162
- this.account.run({payload: {physical_address: method_address || __address__}, callback: ({ret})=>{
163
- this.stack.pop(exec_address)
164
- this.pop_context()
165
-
166
- let res;
167
-
168
- if (typeof location === 'function'){
169
- res = this.read_chain(ret)
170
- if(metadata && metadata.loop){
171
-
172
- if (!metadata.loop.conditioner(res, metadata) && (metadata.loop.index+1) < metadata.loop.array.length){
173
- metadata.loop.index ++
174
-
175
- this.exec({executable, location, metadata, arguments: {argv: [{
176
- address: metadata.loop.array[metadata.loop.index],
177
- position: 0
178
- }], argc: 1}})
179
-
180
- return metadata.callback && metadata.callback(res)
181
- }
182
- }
183
- location(res, metadata)
184
-
185
- }else if(ret){
186
- let chain = this.handle_chain(ret)
187
- let loc_chain = this.handle_chain(location)
188
-
189
- if(chain.datapath){
190
- res = chain.datapath;
191
- loc_chain.set_obj_config(res)
192
- }else {
193
- res = this.read_chain(chain)
194
- if (url_callback) post_request({options:url_callback, data: res})
195
-
196
- loc_chain.forge_block({metadata: {output: this.account.save(res)}})
197
- loc_chain.set_obj_config('')
198
- }
199
- }
200
-
201
- if(metadata && metadata.callback){
202
- metadata.callback(res)
203
- }
204
- }})
205
- }
206
-
207
- handle_method_config = ({name, method_addr, location, object})=>{
208
- let conf = this.get_config(method_addr);
209
-
210
- let obj_method_addr = `${location}/${name}`
211
- let chain = this.handle_chain(obj_method_addr)
212
-
213
- conf.method_address = conf.__address__
214
- conf.__address__ = obj_method_addr
215
- conf.object = location;
216
- chain.set_obj_config(conf)
217
-
218
- object[name] = obj_method_addr;
219
- }
220
-
221
- get_config = exe =>{
222
- let chn = this.handle_chain(exe);
223
-
224
- if (!chn || (chn&& !chn.datapath))return this.stderr(`Executable:${exe} is not callable`)
225
-
226
- return this.account.read(chn.datapath)
227
- }
228
- }
229
-
230
- export default Executables