godprotocol 1.1.3 → 1.1.32

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.
@@ -2,67 +2,119 @@ import Utils from "./Utils";
2
2
  import register from "../callables/register";
3
3
  import Chain from "./Chain";
4
4
  import Virtual_machine from "./Virtual_machine";
5
- import Compiler from "../../../compiler/compiler";
6
5
 
7
6
  class Account extends Utils {
8
7
  constructor(name, options) {
9
- super()
8
+ super();
10
9
 
11
10
  this.name = name;
12
11
 
13
12
  this.manager = options.manager;
14
- this.parent = options.parent || this
13
+ this.parent = options.parent || this;
15
14
  this.repository = this.manager.repository;
16
- this.account = this
15
+ this.account = this;
17
16
 
18
17
  this.physical_address = `Accounts/${name}`;
19
- this.buffs = new Array()
18
+ this.buffs = new Array();
20
19
 
21
20
  this.chain = new Chain(this.physical_address, this.parent);
22
- this.path = this.chain.path
21
+ this.path = this.chain.path;
22
+
23
+ console.log(`Account Created: ${this.name}`);
23
24
  }
24
25
 
25
26
  load = async (payload) => {
26
- let { sequence: codes, physical_address } = payload;
27
-
28
- physical_address = `${this.physical_address}/${physical_address}`
29
-
30
- let chain = await this.chain.chain(physical_address, {root:true})
31
-
32
- return {value: await chain.add_config(codes), type:'address'}
27
+ let { sequence: codes, account, physical_address, options } = payload;
28
+
29
+ console.log(payload);
30
+ if (account && account !== this.name) {
31
+ account = await this.manager.get_account(account);
32
+ if (account) {
33
+ return await account.load(payload);
34
+ } else return { error: true, message: "Account not found!" };
35
+ }
36
+
37
+ if (typeof codes === "string") {
38
+ codes = await this.compiler.to_sequence(codes, physical_address);
39
+ if (options) {
40
+ codes = codes[0].body[options.line];
41
+ }
42
+ }
43
+ if (Array.isArray(codes)) {
44
+ codes = codes[0];
45
+ }
46
+
47
+ physical_address = `${this.physical_address}/${physical_address}`;
48
+
49
+ let chain = await this.chain.chain(physical_address);
50
+
51
+ let res = { value: await chain.add_config(codes), type: "address" };
52
+
53
+ console.log(res, codes, chain.physical_address);
54
+ return res;
33
55
  };
34
56
 
35
57
  run = async (payload) => {
36
- let { physical_address, account } = payload;
37
-
38
- let acc = await this.manager.get_account(account) || this;
39
- let chain = await acc.chain.chain(`${acc.physical_address}/${physical_address}`)
40
-
41
- let config = await chain.read({config: true})
42
- return await this.vm.execute(config, {chain, main:true})
58
+ let { physical_address, account, options } = payload;
59
+
60
+ let acc = (await this.manager.get_account(account)) || this;
61
+ let chain = await acc.chain.chain(
62
+ `${acc.physical_address}/${physical_address}`
63
+ );
64
+
65
+ console.log(chain.physical_address);
66
+ let config = await chain.read({ config: true });
67
+
68
+ if (options.env) {
69
+ let res = await this.load({
70
+ sequence: `env = ${JSON.stringify(options.env)}`,
71
+ physical_address: `${physical_address}`,
72
+ options: { line: 0 },
73
+ });
74
+ await this.vm.execute(res.value, { chain });
75
+ }
76
+
77
+ let res = await this.vm.execute(config, { chain, main: true });
78
+ if (options && options.literal) {
79
+ if (res.type === "address") {
80
+ let conf = await this.vm.resolve_address(res.value);
81
+ res = {
82
+ address: res,
83
+ literal: await (await this.vm.cloth_content(conf)).literal(),
84
+ };
85
+ }
86
+ }
87
+
88
+ return res;
43
89
  };
44
90
 
45
- parse = async(payload)=>{
46
- let {account, physical_address, depth, history, query} = payload;
91
+ parse = async (payload) => {
92
+ let { account, physical_address, depth, history, query } = payload;
47
93
 
48
- let acc = await this.manager.get_account(account) || this;
49
- let chain = await acc.chain.chain(`${acc.physical_address}/${physical_address}`)
94
+ let acc = (await this.manager.get_account(account)) || this;
95
+ let chain = await acc.chain.chain(
96
+ `${acc.physical_address}/${physical_address}`
97
+ );
50
98
 
51
- let config = await chain.read({query, depth, history});
99
+ let config = await chain.read({ query, depth, history });
52
100
  return config;
53
- }
101
+ };
54
102
 
55
- add_account = async(name, options)=>{
56
- let acc = new Account(name, {...options, manager: this.manager, parent: this})
57
- await acc.sync()
103
+ add_account = async (name, options) => {
104
+ let acc = new Account(name, {
105
+ ...options,
106
+ manager: this.manager,
107
+ parent: this,
108
+ });
109
+ await acc.sync();
58
110
 
59
- return acc
60
- }
111
+ return acc;
112
+ };
61
113
 
62
114
  sync = async () => {
63
115
  this.servers = new Array();
64
116
  this.vm = new Virtual_machine(this);
65
- this.aircode = new Compiler(this)
117
+ this.compiler = new this.manager.compiler(this);
66
118
 
67
119
  await this.chain.sync();
68
120
  await this.vm.sync();
@@ -70,9 +122,14 @@ class Account extends Utils {
70
122
  await register(this);
71
123
  };
72
124
 
73
- stringify = ()=>{
74
- return {physical_address: this.physical_address, path: this.path, name: this.name, private: this.private}
75
- }
125
+ stringify = () => {
126
+ return {
127
+ physical_address: this.physical_address,
128
+ path: this.path,
129
+ name: this.name,
130
+ private: this.private,
131
+ };
132
+ };
76
133
  }
77
134
 
78
135
  export default Account;
@@ -7,184 +7,230 @@ class Callable extends Vm_utils {
7
7
  this.objects = new Object();
8
8
  }
9
9
 
10
- parse_aircode = async(result, {config, chain})=>{
11
- if (result == null)result = 'void';
10
+ parse_aircode = async (result, { config, chain }) => {
11
+ if (result == null) result = "void";
12
12
 
13
- let res = await this.account.aircode.to_sequence(JSON.stringify(result), config.location.split('/').slice(2).join('/'))[0].body[0]
13
+ let res = await this.account.compiler.to_sequence(
14
+ JSON.stringify(result),
15
+ config.location.split("/").slice(2).join("/")
16
+ )[0].body[0];
14
17
 
15
- await chain.add_config(res)
16
- result = await this.execute(res, {chain})
18
+ await chain.add_config(res);
19
+ result = await this.execute(res, { chain });
17
20
 
18
- return result
19
- }
21
+ return result;
22
+ };
20
23
 
21
- resolve_address = async (path, chain)=>{
22
- let oracle = this.account.manager.oracle,
24
+ resolve_address = async (path, chain) => {
25
+ let oracle = this.account.manager.oracle,
23
26
  fs = oracle.fs;
24
27
 
25
- if (typeof path !== 'string'){
26
- return path
28
+ if (typeof path !== "string") {
29
+ return path;
27
30
  }
28
31
 
29
- if(path == 'g')throw new Error()
30
- let conf = await fs.read(`${path}/.config`), value;
31
- if (!conf.current){
32
- value = await fs.read(`${path}/${conf.index-1}`)
33
- value = JSON.parse(value.content)
34
- }else value = await fs.read(`${path}/${conf.current}`)
35
- value.path = path
36
-
32
+ if (path == "g") throw new Error();
33
+ let conf = await fs.read(`${path}/.config`),
34
+ value;
35
+ if (!conf.current) {
36
+ value = await fs.read(`${path}/${conf.index - 1}`);
37
+ value = JSON.parse(value.content);
38
+ } else value = await fs.read(`${path}/${conf.current}`);
39
+ value.path = path;
40
+
37
41
  return value;
38
- }
42
+ };
39
43
 
40
- instantiate = async(config, {chain, hash, pure})=>{
41
- let instance_chain = await chain.chain(config.type === 'void'? config.value : config.location);
42
- let uid = this.gen_uid()
43
-
44
- if (config.type === 'twain'){
45
- if (!pure){
46
- for (let p in config.value){
47
- let pair = config.value[p]
48
-
49
- pair[0] = (await this.execute(pair[0], {chain})).value
50
- pair[1] = (await this.execute(pair[1], {chain})).value
44
+ instantiate = async (config, { chain, hash, pure }) => {
45
+ let instance_chain = await chain.chain(
46
+ config.type === "void" ? config.value : config.location
47
+ );
48
+ let uid = this.gen_uid();
49
+
50
+ if (config.type === "twain") {
51
+ if (!pure) {
52
+ for (let p in config.value) {
53
+ let pair = config.value[p];
54
+
55
+ pair[0] = (await this.execute(pair[0], { chain })).value;
56
+ pair[1] = (await this.execute(pair[1], { chain })).value;
51
57
  }
52
58
  }
53
-
54
- config.value = JSON.stringify(config.value)
55
- }else if(config.type === 'array'){
56
- if (!pure){
57
- for (let i=0; i< config.value.length; i++){
58
- let item = config.value[i]
59
- config.value[i] = (await this.execute(item, {chain})).value
59
+
60
+ config.value = JSON.stringify(config.value);
61
+ } else if (config.type === "array") {
62
+ if (!pure) {
63
+ for (let i = 0; i < config.value.length; i++) {
64
+ let item = config.value[i];
65
+ config.value[i] = (await this.execute(item, { chain })).value;
60
66
  }
61
67
  }
62
- config.value = JSON.stringify(config.value)
68
+ config.value = JSON.stringify(config.value);
63
69
  }
64
70
 
65
- let res = await instance_chain.write({content: config.value, __classifier__: config.type, uid}, {hash, is_instance: true})
71
+ let res = await instance_chain.write(
72
+ { content: config.value, __classifier__: config.type, uid },
73
+ { hash, is_instance: true }
74
+ );
66
75
  return res;
67
- }
76
+ };
68
77
 
69
- operate_result = async (value, call_config, chain)=>{
78
+ operate_result = async (value, call_config, chain) => {
70
79
  let result;
71
- if (value && value.error){
72
- result = value
73
- }else if(value && value.type === 'address'){
74
- result = value
75
- } else result = await this.parse_aircode(value, {config: call_config, chain})
80
+ if (value && value.error) {
81
+ result = value;
82
+ } else if (value && value.type === "address") {
83
+ result = value;
84
+ } else
85
+ result = await this.parse_aircode(value, { config: call_config, chain });
76
86
 
77
- return result
78
- }
87
+ return result;
88
+ };
79
89
 
80
- object_identifier = async (call_config, chain)=>{
81
- let {identifier, }= call_config, result, oracle = this.account.manager.oracle;
82
- let conf = await oracle.fs.read(`${identifier.object}/.config`)
90
+ object_identifier = async (call_config, chain) => {
91
+ let { identifier } = call_config,
92
+ result,
93
+ oracle = this.account.manager.oracle;
94
+ let conf = await oracle.fs.read(`${identifier.object}/.config`);
83
95
  let obj = await oracle.fs.read(`${identifier.object}/${conf.current}`);
84
96
 
85
- let res = await this.cloth_content({...obj, path: identifier.object})
86
- let classifier = await res.get('__classifier__')
87
-
88
- if (this.datatypes.includes(classifier)){
89
- for (let a=0; a < call_config.arguments.length; a++)
90
- call_config.arguments[a] = await this.execute(call_config.arguments[a], {chain, cloth: true})
91
-
92
- let value = await res.operate(identifier.value, call_config.arguments, {classifier, config: call_config, chain})
93
- result = await this.operate_result(value, call_config, chain)
94
- }else {
95
- let conf = await oracle.fs.read(`${identifier.value}/.config`)
96
- conf = await oracle.fs.read(`${identifier.value}/${conf.index-1}`)
97
- let content = JSON.parse(conf.content)
98
-
99
- let val = await this.execute(content, {chain, call_config: {...call_config, object: {type:'address', value: identifier.object}}})
100
-
101
- result = val
97
+ let res = await this.cloth_content({ ...obj, path: identifier.object });
98
+ let classifier = await res.get("__classifier__");
99
+
100
+ if (this.datatypes.includes(classifier)) {
101
+ for (let a = 0; a < call_config.arguments.length; a++)
102
+ call_config.arguments[a] = await this.execute(
103
+ call_config.arguments[a],
104
+ { chain, cloth: true }
105
+ );
106
+
107
+ let value = await res.operate(identifier.value, call_config.arguments, {
108
+ classifier,
109
+ config: call_config,
110
+ chain,
111
+ });
112
+ result = await this.operate_result(value, call_config, chain);
113
+ } else {
114
+ let conf = await oracle.fs.read(`${identifier.value}/.config`);
115
+ conf = await oracle.fs.read(`${identifier.value}/${conf.index - 1}`);
116
+ let content = JSON.parse(conf.content);
117
+
118
+ let val = await this.execute(content, {
119
+ chain,
120
+ call_config: {
121
+ ...call_config,
122
+ object: { type: "address", value: identifier.object },
123
+ },
124
+ });
125
+
126
+ result = val;
102
127
  }
103
128
 
104
- return result
105
- }
129
+ return result;
130
+ };
106
131
 
107
- execute_call = async(call_config, {chain, obj})=>{
108
- let {identifier, arguments: args} = call_config, result;
109
-
110
- if(typeof identifier !== 'string'){
111
- if (identifier.object){
112
- result = await this.object_identifier(call_config, chain)
113
- }else {
114
- let conf = await this.read_config(identifier.value)
115
- if(!['function', 'class'].includes(conf.type)){
116
- conf = await obj.get(identifier.prev_name, {obj:identifier.prev_name})
117
- conf = await this.resolve_address(conf.value)
132
+ execute_call = async (call_config, { chain, obj }) => {
133
+ let { identifier, arguments: args } = call_config,
134
+ result;
135
+
136
+ if (typeof identifier !== "string") {
137
+ if (identifier.object) {
138
+ result = await this.object_identifier(call_config, chain);
139
+ } else {
140
+ let conf = await this.read_config(identifier.value);
141
+ if (!["function", "class"].includes(conf.type)) {
142
+ conf = await obj.get(identifier.prev_name, {
143
+ obj: identifier.prev_name,
144
+ });
145
+ conf = await this.resolve_address(conf.value);
118
146
  }
119
- result = await this.execute(conf, {call_config, chain})
147
+ result = await this.execute(conf, { call_config, chain });
120
148
  }
121
- } else if (identifier.includes('/')){
149
+ } else if (identifier.includes("/")) {
122
150
  let oracle = this.account.manager.oracle;
123
- let i_chain = identifier.startsWith(this.account.manager.path)? {path: identifier} : await chain.chain(identifier)
124
- let conf = await oracle.fs.read(`${i_chain.path}/.config`)
125
-
126
- if(conf.sibling){
127
- let config = await oracle.fs.read(conf.sibling)
128
-
129
- if (config.content.type === 'address'){
130
- if (config.content.object){
131
- result = await this.object_identifier({...call_config, identifier: config.content}, chain)
132
- }else {
151
+ let i_chain = identifier.startsWith(this.account.manager.path)
152
+ ? { path: identifier }
153
+ : await chain.chain(identifier);
154
+ let conf = await oracle.fs.read(`${i_chain.path}/.config`);
155
+
156
+ if (conf.sibling) {
157
+ let config = await oracle.fs.read(conf.sibling);
158
+
159
+ if (config.content.type === "address") {
160
+ if (config.content.object) {
161
+ result = await this.object_identifier(
162
+ { ...call_config, identifier: config.content },
163
+ chain
164
+ );
165
+ } else {
133
166
  let iconf = await oracle.fs.read(`${config.content.value}/.config`);
134
- let configg = await oracle.fs.read(`${config.content.value}/${iconf.index-1}`)
135
-
136
- result = await this.execute(JSON.parse(configg.content), {call_config, chain})
137
- }
167
+ let configg = await oracle.fs.read(
168
+ `${config.content.value}/${iconf.index - 1}`
169
+ );
170
+
171
+ result = await this.execute(JSON.parse(configg.content), {
172
+ call_config,
173
+ chain,
174
+ });
175
+ }
138
176
  }
139
- }else if(conf.current) {
177
+ } else if (conf.current) {
140
178
  let iconf = await oracle.fs.read(`${conf.current}/.config`);
141
- let config = await oracle.fs.read(`${conf.current}/${iconf.index-1}`)
142
-
143
- result = await this.execute(JSON.parse(config.content), {call_config, chain})
144
- }else {
145
- let config = await oracle.fs.read(`${call_config.identifier}/${conf.index-1}`)
146
- result = await this.execute(JSON.parse(config.content), {call_config, chain})
179
+ let config = await oracle.fs.read(`${conf.current}/${iconf.index - 1}`);
180
+
181
+ result = await this.execute(JSON.parse(config.content), {
182
+ call_config,
183
+ chain,
184
+ });
185
+ } else {
186
+ let config = await oracle.fs.read(
187
+ `${call_config.identifier}/${conf.index - 1}`
188
+ );
189
+ result = await this.execute(JSON.parse(config.content), {
190
+ call_config,
191
+ chain,
192
+ });
147
193
  }
148
- }
149
- else {
150
- if (this.datatypes.includes(identifier)){}
151
- else {
152
- let {callable, config} = await this.callable(identifier)
153
- let data = {}
154
-
155
- for (let a=0; a< args.length; a++){
156
- let param;
157
- let arg = args[a]
158
- if(arg.identifier){
194
+ } else {
195
+ if (this.datatypes.includes(identifier)) {
196
+ } else {
197
+ let { callable, config } = await this.callable(identifier);
198
+ let data = {};
159
199
 
160
- }else {
161
- param = config.parameters[arg.position]
162
- if (!param){
163
- let lst_param = config.parameters.slice(-1)[0]
200
+ for (let a = 0; a < args.length; a++) {
201
+ let param;
202
+ let arg = args[a];
203
+ if (arg.identifier) {
204
+ } else {
205
+ param = config.parameters[arg.position];
206
+ if (!param) {
207
+ let lst_param = config.parameters.slice(-1)[0];
164
208
  if (lst_param.spread) param = lst_param;
165
209
  }
166
210
  }
167
- let res = await this.execute(arg, {chain, cloth: true})
168
- if (param.spread){
169
- let arr = data[param.name]
170
- if (!arr){
211
+ let res = await this.execute(arg, { chain, cloth: true });
212
+ if (param.spread) {
213
+ let arr = data[param.name];
214
+ if (!arr) {
171
215
  arr = new Array();
172
216
  data[param.name] = arr;
173
217
  }
174
- arr.push(res)
175
- }else data[param.name] = res;
218
+ arr.push(res);
219
+ } else data[param.name] = res;
176
220
  }
177
-
178
- result = await callable(data)
179
- if (identifier === 'exit' || identifier === 'Twain'){
180
-
181
- }else result = await this.parse_aircode(result, {config: call_config, chain})
221
+
222
+ result = await callable(data, { vm: this, config, chain });
223
+ if (["Twain", "exit", "render"].includes(identifier)) {
224
+ } else
225
+ result = await this.parse_aircode(result, {
226
+ config: call_config,
227
+ chain,
228
+ });
182
229
  }
183
230
  }
184
231
 
185
- return result
186
- }
187
-
232
+ return result;
233
+ };
188
234
 
189
235
  callable = async (name) => {
190
236
  let object = this.objects[name];
@@ -195,6 +241,25 @@ class Callable extends Vm_utils {
195
241
  set = (name, config) => {
196
242
  this.objects[name] = config;
197
243
  };
244
+
245
+ native_components = async (config, chain) => {
246
+ let props = await this.execute(config.props, { chain, cloth: true });
247
+ let children = new Array();
248
+ for (let c = 0; c < config.children.length; c++) {
249
+ let child = config.children[c];
250
+
251
+ let res = await this.execute(child, { chain, cloth: true });
252
+ children.push(await res.literal());
253
+ }
254
+
255
+ let obj = {
256
+ name: config.name,
257
+ props: await props.literal(),
258
+ children,
259
+ };
260
+
261
+ return obj;
262
+ };
198
263
  }
199
264
 
200
265
  export default Callable;
package/Objects/Chain.js CHANGED
@@ -6,7 +6,7 @@ class Folder extends Storage{
6
6
 
7
7
  this.account = parent.account;
8
8
  this.physical_address = address
9
- this.path = `${this.account.manager.path}/${this.physical_address}`
9
+ this.path = ${this.account.manager.path}/${this.physical_address}
10
10
  this.parent = parent;
11
11
  }
12
12
 
@@ -20,8 +20,8 @@ class Folder extends Storage{
20
20
  }
21
21
 
22
22
  chain = async(address)=>{
23
- if (!address.includes('/'))address = `${this.physical_address}/${address}`
24
-
23
+ if (!address.includes('/'))address = ${this.physical_address}/${address}
24
+
25
25
  let chain = await this.account.manager.web.set(address, this)
26
26
  return chain;
27
27
  }
@@ -30,20 +30,20 @@ class Folder extends Storage{
30
30
  let res;
31
31
  if (content && content.type === 'address' && options.hash) {
32
32
  let oracle = this.account.manager.oracle;
33
- let conf = await oracle.fs.read(`${this.path}/.config`) || {}
34
-
35
- let pth = `${this.path}/${options.hash}`
36
- let p_conf = await oracle.fs.read(`${pth}/.config`) || {}
33
+ let conf = await oracle.fs.read(${this.path}/.config) || {}
34
+
35
+ let pth = ${this.path}/${options.hash}
36
+ let p_conf = await oracle.fs.read(${pth}/.config) || {}
37
37
  let obj = {content, type: 'reference', previous: p_conf.current, sibling: conf.sibling}
38
38
  let hsh = await oracle.hash(obj)
39
- res = `${pth}/${hsh}`;
39
+ res = ${pth}/${hsh};
40
40
 
41
41
  await oracle.fs.write(res, JSON.stringify(obj))
42
42
  p_conf.current = res
43
- await oracle.fs.write(`${pth}/.config`, JSON.stringify(p_conf))
44
-
43
+ await oracle.fs.write(${pth}/.config, JSON.stringify(p_conf))
44
+
45
45
  conf.sibling = res;
46
- await oracle.fs.write(`${this.path}/.config`, JSON.stringify(conf))
46
+ await oracle.fs.write(${this.path}/.config, JSON.stringify(conf))
47
47
  }else {
48
48
  res = await this.persist(content, {...options })
49
49
  }
@@ -52,14 +52,14 @@ class Folder extends Storage{
52
52
 
53
53
  read =async (options={})=>{
54
54
  let res = await this.retrieve(options)
55
-
55
+
56
56
  return res;
57
57
  }
58
58
 
59
59
  write_config = async (config, options={})=>{
60
60
  return await this.persist(config, {...options, config: true, })
61
61
  }
62
-
62
+
63
63
  add_config = async (config, options={})=>{
64
64
  let result;
65
65
 
@@ -72,6 +72,14 @@ class Folder extends Storage{
72
72
  }
73
73
  result = await this.write_config(config)
74
74
  break;
75
+ case 'adm':
76
+ let adm_chain = await this.chain(config.location)
77
+ config.props = await this.add_config(config.props)
78
+ for (let c=0; c< config.children.length; c++){
79
+ config.children[c] = await this.add_config(config.children[c])
80
+ }
81
+ result = await adm_chain.write_config(config)
82
+ break;
75
83
  case 'class':
76
84
  let class_chain = await this.chain(config.name)
77
85
  for (let name in config.methods){
@@ -86,7 +94,7 @@ class Folder extends Storage{
86
94
  config.parameters[p] = await fn_chain.add_config(config.parameters[p])
87
95
  }
88
96
  for (let b=0; b< config.body.length; b++){
89
-
97
+
90
98
  config.body[b] = await fn_chain.add_config(config.body[b])
91
99
  }
92
100
  result = await fn_chain.write_config(config)
@@ -125,7 +133,7 @@ class Folder extends Storage{
125
133
  break;
126
134
  case 'assignment':
127
135
  let ass_chain = await this.chain(config.identifier)
128
-
136
+
129
137
  config.value = await ass_chain.add_config(config.value);
130
138
 
131
139
  result = await ass_chain.write_config(config)
@@ -137,7 +145,7 @@ class Folder extends Storage{
137
145
  config.iterator = await this.add_config(config.iterator)
138
146
  config.update = await this.add_config(config.update)
139
147
  }
140
-
148
+
141
149
  for (let b=0; b< config.body.length; b++){
142
150
  config.body[b] = await this.add_config(config.body[b])
143
151
  }
@@ -161,7 +169,7 @@ class Folder extends Storage{
161
169
  }
162
170
  if(config.assignment)
163
171
  config.assignment = await nest_chain.add_config(config.assignment)
164
-
172
+
165
173
  result = await nest_chain.write_config(config)
166
174
  break;
167
175
  default:
@@ -189,7 +197,7 @@ class Folder extends Storage{
189
197
  }else if (['break', 'continue'].includes(config.type)){
190
198
  result = config;
191
199
  }
192
-
200
+
193
201
  }
194
202
 
195
203
  return result;
@@ -10,6 +10,7 @@ class Manager {
10
10
  this.name = name;
11
11
  this.options = options || {};
12
12
 
13
+ this.compiler = options.compiler;
13
14
  this.trinity = options.trinity;
14
15
  this.sync_server = options.sync_server;
15
16
  if (this.sync_server && !this.sync_server.domain) {
@@ -33,7 +34,7 @@ class Manager {
33
34
 
34
35
  this.post_request = post_request;
35
36
 
36
- await this.oracle.sync()
37
+ await this.oracle.sync();
37
38
  await this.repository.sync(this.name);
38
39
  };
39
40
 
@@ -50,9 +51,9 @@ class Manager {
50
51
  return account;
51
52
  };
52
53
 
53
- get_account = name=>{
54
- return this.accounts[name]
55
- }
54
+ get_account = (name) => {
55
+ return this.accounts[name];
56
+ };
56
57
  }
57
58
 
58
59
  export default Manager;
@@ -45,8 +45,8 @@ class Virtual_machine extends Callable {
45
45
 
46
46
  if(line){
47
47
  if (line.type === 'instance'){
48
- let classifier = await line.get('__classifier__')
49
-
48
+ let classifier = await line.get('_classifier_')
49
+
50
50
  caught = err === classifier
51
51
  if (config.alias){
52
52
  let conf = await this.read_config(config.alias);
@@ -54,7 +54,7 @@ class Virtual_machine extends Callable {
54
54
  await this.execute({...conf, value: {type: 'address', value: line.value.path}}, {chain, hash})
55
55
  }
56
56
 
57
-
57
+
58
58
  }else if(!line.type){
59
59
  caught = err.endsWith(line.value.name)
60
60
  }
@@ -89,7 +89,7 @@ class Virtual_machine extends Callable {
89
89
  }else if (line.error){
90
90
  if (config.type === 'trycatch'){
91
91
  let res = !config.caught && await this.handle_error(line, {chain, config})
92
-
92
+
93
93
  if(!res){
94
94
  result = line
95
95
  }
@@ -117,15 +117,15 @@ class Virtual_machine extends Callable {
117
117
 
118
118
  switch (config.type) {
119
119
  case "module":
120
- await this.execute_body(config.body, {chain, config})
121
-
120
+ result = await this.execute_body(config.body, {chain, config})
121
+
122
122
  break;
123
123
  case "class":
124
124
  if (call_config) {
125
125
  let instance_chain = await chain.chain(call_config.location);
126
126
  let object = {
127
- content: `[${config.name}]`,
128
- __classifier__: config.address,
127
+ content: [${config.name}],
128
+ _classifier_: config.address,
129
129
  uid: this.gen_uid(),
130
130
  };
131
131
  for (let name in config.methods) {
@@ -135,14 +135,28 @@ class Virtual_machine extends Callable {
135
135
  let res = await instance_chain.write(object, { is_instance: true });
136
136
  result = { type: "address", value: res };
137
137
 
138
- if (object.__init__) {
138
+ if (object._init_) {
139
139
  await this.execute(
140
- { ...call_config, object: result, identifier: object.__init__ },
140
+ { ...call_config, object: result, identifier: object._init_ },
141
141
  { chain }
142
142
  );
143
143
  }
144
144
  }
145
145
  break;
146
+ case 'adm':
147
+ let props = await this.execute(config.props, {chain})
148
+ if(config.name.includes('/')){
149
+ result = await this.execute({
150
+ type:'call',
151
+ identifier: config.name,
152
+ arguments: [{...props, position: 0}],
153
+ location: config.location
154
+ }, {chain})
155
+ }else {
156
+ result = await this.native_components(config, chain)
157
+ result = await this.parse_aircode(result, {config, chain})
158
+ }
159
+ break
146
160
  case "function":
147
161
  if (call_config) {
148
162
  let fn_chain = await chain.chain(config.address);
@@ -201,7 +215,7 @@ class Virtual_machine extends Callable {
201
215
  value = { type: "address", value };
202
216
  result = await ass_chain.write(value, { hash });
203
217
  }
204
-
218
+
205
219
  break;
206
220
  case "call":
207
221
  if (config.identifier.type === "nest") {
@@ -237,7 +251,7 @@ class Virtual_machine extends Callable {
237
251
  let cond = await this.execute(config.condition, {chain , cloth: true})
238
252
  while(await cond.literal()){
239
253
  result = await this.execute_body(config.body, {config, chain})
240
-
254
+
241
255
  if (result && result.interrupt_loop){
242
256
  if (result.interrupt_loop === 'break'){
243
257
  result = null
@@ -251,7 +265,7 @@ class Virtual_machine extends Callable {
251
265
  }
252
266
  cond = await this.execute(config.condition, {chain , cloth: true})
253
267
  }
254
-
268
+
255
269
  break
256
270
  case 'trycatch':
257
271
  result = await this.execute_body(config.try_body, {chain, config})
@@ -268,7 +282,7 @@ class Virtual_machine extends Callable {
268
282
  });
269
283
  if (await pred.literal()) {
270
284
  result = await this.execute_body(block.body, {chain, config})
271
-
285
+
272
286
  break;
273
287
  }
274
288
  }
@@ -300,6 +314,11 @@ class Virtual_machine extends Callable {
300
314
  } else {
301
315
  let res = await this.execute(nst, { chain, cloth: true });
302
316
  let prop = await res.literal();
317
+
318
+ if(prev.type === 'address'){
319
+ let conf = await this.resolve_address(prev.value)
320
+ prev = await this.cloth_content(conf)
321
+ }
303
322
  prev = await prev.get(prop, {obj: res, config: nst, chain});
304
323
  }
305
324
  }
@@ -332,7 +351,7 @@ class Virtual_machine extends Callable {
332
351
  let res = await var_chain.read({ sibling: true });
333
352
  if (!res) {
334
353
  res = await this.account.manager.oracle.fs.read(
335
- `${var_chain.path}/.config`
354
+ ${var_chain.path}/.config
336
355
  );
337
356
  res = { type: "address", value: res.current };
338
357
  }
@@ -340,7 +359,7 @@ class Virtual_machine extends Callable {
340
359
  } else if (config.type === "reference") {
341
360
  let oracle = this.account.manager.oracle;
342
361
  let i_chain = await chain.chain(config.value);
343
- let conf = await oracle.fs.read(`${i_chain.path}/.config`);
362
+ let conf = await oracle.fs.read(${i_chain.path}/.config);
344
363
  result = { type: "address", value: conf.current };
345
364
  }else if (['continue', 'break'].includes(config.type)){
346
365
  result = {interrupt_loop: config.type}
@@ -0,0 +1,24 @@
1
+ const render = async (args, { vm, config, chain }) => {
2
+ let { object } = args;
3
+
4
+ let res = await object.get("render");
5
+ if (!res) return null;
6
+
7
+ let result = await vm.execute(
8
+ {
9
+ type: "call",
10
+ identifier: {
11
+ type: "address",
12
+ value: res,
13
+ object: object.value.path,
14
+ },
15
+ arguments: [],
16
+ location: config.location,
17
+ },
18
+ { chain }
19
+ );
20
+
21
+ return result;
22
+ };
23
+
24
+ export default render;
@@ -2,6 +2,7 @@ import twain from "./functions/twain";
2
2
  import display from "./functions/display";
3
3
  import net from "godprotocol/callables/functions/net";
4
4
  import quit from "godprotocol/callables/functions/exit";
5
+ import render from "./functions/render";
5
6
 
6
7
  const register = async (account) => {
7
8
  let set = account.vm.set;
@@ -23,7 +24,11 @@ const register = async (account) => {
23
24
  set("net", {
24
25
  callable: net,
25
26
  config: {
26
- parameters: [{ name: "server", position: 0 }, { name: "path", position: 0 }, { name: "payload", position: 0 }],
27
+ parameters: [
28
+ { name: "server", position: 0 },
29
+ { name: "path", position: 0 },
30
+ { name: "payload", position: 0 },
31
+ ],
27
32
  },
28
33
  });
29
34
 
@@ -33,6 +38,13 @@ const register = async (account) => {
33
38
  parameters: [{ name: "code", position: 0 }],
34
39
  },
35
40
  });
41
+
42
+ set("render", {
43
+ callable: render,
44
+ config: {
45
+ parameters: [{ name: "object", position: 0 }],
46
+ },
47
+ });
36
48
  };
37
49
 
38
50
  export default register;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "godprotocol",
3
- "version": "1.1.3",
3
+ "version": "1.1.32",
4
4
  "description": "A distributed computing environment",
5
5
  "main": "Index.js",
6
6
  "scripts": {
@@ -1,44 +1,68 @@
1
1
  import https from "https";
2
- import fs from "fs";
2
+ import http from "http";
3
3
 
4
4
  let PORT = Number(process.env.PORT) || 1408;
5
5
 
6
6
  const handle_routes = (req, res, manager, app) => {
7
7
  let data = "";
8
+ res.setHeader("Access-Control-Allow-Origin", "*");
9
+ res.setHeader("Access-Control-Allow-Headers", "Content-Type");
8
10
 
11
+ if (req.method === "OPTIONS") {
12
+ res.writeHead(204, {
13
+ "Access-Control-Allow-Origin": "*",
14
+ "Access-Control-Allow-Headers": "Content-Type",
15
+ "Access-Control-Allow-Methods": "POST, GET, OPTIONS",
16
+ });
17
+ res.end();
18
+ return;
19
+ }
20
+
21
+ if (['/create_account', '/load', '/run', '/parse'].includes(req.url)){
22
+ req.on("data", (chunk) => {
23
+ data += chunk;
24
+ });
9
25
 
10
- req.on("data", (chunk) => {
11
- data += chunk;
12
- });
26
+ req.on("end", async () => {
27
+ if (!data) {
28
+ res.writeHead(400, { "Content-Type": "application/json" });
29
+ res.end(JSON.stringify({ error: "Request body cannot be empty" }));
30
+ return;
31
+ }
13
32
 
14
- req.on("end", async () => {
15
- data = JSON.parse(data)
16
- let result;
17
- if (req.url === '/create_account'){
18
- result = await manager.add_account(data.name, data.options)
19
- res.end(JSON.stringify(result.stringify()))
20
- }else if(req.url === '/load'){
21
- let account = await manager.get_account(data.account);
22
- result = await account.load(data)
23
- res.end(JSON.stringify(result))
24
- }else if(req.url === '/run'){
25
- let account = await manager.get_account(data.account);
26
- result = await account.run(data)
27
-
28
- res.end(result? JSON.stringify(result): JSON.stringify({done: true}))
29
- }else if(req.url === '/parse'){
30
- let account = await manager.get_account(data.account);
31
- result = await account.parse(data)
32
-
33
- res.end(result? JSON.stringify(result): JSON.stringify({done: true}))
34
- }
35
- });
33
+ data = JSON.parse(data)
34
+ let result;
36
35
 
37
- req.on("error", (e) => {
38
- console.log('hm')
39
- // res.writeHead(500, { "Content-Type": "application/json" });
40
- res.end(JSON.stringify({ status: "error", error_message: e.message }));
41
- });
36
+ if (req.url === '/create_account'){
37
+ result = await manager.add_account(data.name, data.options)
38
+ res.end(JSON.stringify(result.stringify()))
39
+ }else if(req.url === '/load'){
40
+ let account = await manager.get_account(data.account);
41
+ result = await account.load(data)
42
+ res.end(JSON.stringify(result))
43
+ }else if(req.url === '/run'){
44
+ let account = await manager.get_account(data.account);
45
+ result = await account.run(data)
46
+
47
+ res.writeHead(200, { "Content-type": "application/json" });
48
+
49
+ res.end(result? JSON.stringify(result): JSON.stringify({done: true}))
50
+ }else if(req.url === '/parse'){
51
+ let account = await manager.get_account(data.account);
52
+ result = await account.parse(data)
53
+
54
+ res.end(result? JSON.stringify(result): JSON.stringify({done: true}))
55
+ }
56
+ });
57
+
58
+ req.on("error", (e) => {
59
+ res.writeHead(500, { "Content-Type": "application/json" });
60
+ res.end(JSON.stringify({ status: "error", error_message: e.message }));
61
+ });
62
+ }else if (app){
63
+ app(req, res);
64
+ }
65
+
42
66
  };
43
67
 
44
68
  const create_server = async (settings) => {
@@ -48,11 +72,12 @@ const create_server = async (settings) => {
48
72
 
49
73
  port = port || PORT;
50
74
 
51
- let server = https.createServer(
52
- {
53
- key: fs.readFileSync(`${__dirname}/server.key`),
54
- cert: fs.readFileSync(`${__dirname}/server.cert`),
55
- },
75
+ // console.log(__dirname)
76
+ let server = http.createServer(
77
+ // {
78
+ // key: fs.readFileSync(`${__dirname}/server.key`),
79
+ // cert: fs.readFileSync(`${__dirname}/server.cert`),
80
+ // },
56
81
  (req, res) => handle_routes(req, res, manager, app)
57
82
  );
58
83
 
package/utils/vm_utils.js CHANGED
@@ -9,95 +9,203 @@ import Bool from "../Datatypes/bool";
9
9
  import Instance from "../Datatypes/instance";
10
10
  import Func from "../Datatypes/func";
11
11
  import Cls from "../Datatypes/cls";
12
+ import { ops } from "./ops";
12
13
 
13
14
  class Vm_utils {
14
15
  constructor() {
16
+ this.ops = ops;
15
17
  this.literal_methods = {
16
- number: ['add','sub','div','mul', 'exp', 'floordiv', 'eq', "ne", "lt", 'gt', 'gte', 'lte', 'neg', 'abs', 'and', 'or', 'xor', 'lshift', 'rshift', 'invert'].map(i=>`__${i}__`).concat(['to_int', 'to_float', 'to_string', 'sqrt', 'log', 'sin', 'sinh', 'tanh', 'cosh', 'atanh', 'acosh', 'asinh', 'atan', 'acos', 'asin', 'cos', 'tan', 'round', 'factorial', 'ceil', 'floor', 'is_prime', 'is_even', 'is_odd', 'is_perfect_square', 'to_degrees', 'to_radians']),
17
- string: ['upper','lower','title','slice', 'concat', 'find', 'includes', 'index', 'trim', 'split', 'padstart', 'padend', 'repeat', 'replace', 'startswith', 'endswith', 'count', 'length', 'reverse', 'is_numeric', 'is_empty', 'is_blank', 'charcode'],
18
- array:[
19
- 'push', 'pop', 'length', 'run', 'copy', 'deepcopy', 'extend', 'slice', 'index', 'includes', 'replace', 'map', 'find', 'filter', 'padstart', 'padend', 'clear', 'to_string', 'reverse', 'repeat', 'join', 'splice'
18
+ number: [
19
+ "add",
20
+ "sub",
21
+ "div",
22
+ "mul",
23
+ "exp",
24
+ "floordiv",
25
+ "eq",
26
+ "ne",
27
+ "lt",
28
+ "gt",
29
+ "gte",
30
+ "lte",
31
+ "neg",
32
+ "abs",
33
+ "and",
34
+ "or",
35
+ "xor",
36
+ "lshift",
37
+ "rshift",
38
+ "invert",
39
+ ]
40
+ .map((i) => `__${i}__`)
41
+ .concat([
42
+ "to_int",
43
+ "to_float",
44
+ "to_string",
45
+ "sqrt",
46
+ "log",
47
+ "sin",
48
+ "sinh",
49
+ "tanh",
50
+ "cosh",
51
+ "atanh",
52
+ "acosh",
53
+ "asinh",
54
+ "atan",
55
+ "acos",
56
+ "asin",
57
+ "cos",
58
+ "tan",
59
+ "round",
60
+ "factorial",
61
+ "ceil",
62
+ "floor",
63
+ "is_prime",
64
+ "is_even",
65
+ "is_odd",
66
+ "is_perfect_square",
67
+ "to_degrees",
68
+ "to_radians",
69
+ ]),
70
+ string: [
71
+ "upper",
72
+ "lower",
73
+ "title",
74
+ "slice",
75
+ "concat",
76
+ "find",
77
+ "includes",
78
+ "index",
79
+ "trim",
80
+ "split",
81
+ "padstart",
82
+ "padend",
83
+ "repeat",
84
+ "replace",
85
+ "startswith",
86
+ "endswith",
87
+ "count",
88
+ "length",
89
+ "reverse",
90
+ "is_numeric",
91
+ "is_empty",
92
+ "is_blank",
93
+ "charcode",
94
+ ],
95
+ array: [
96
+ "push",
97
+ "pop",
98
+ "length",
99
+ "run",
100
+ "copy",
101
+ "deepcopy",
102
+ "extend",
103
+ "slice",
104
+ "index",
105
+ "includes",
106
+ "replace",
107
+ "map",
108
+ "find",
109
+ "filter",
110
+ "padstart",
111
+ "padend",
112
+ "clear",
113
+ "to_string",
114
+ "reverse",
115
+ "repeat",
116
+ "join",
117
+ "splice",
20
118
  ],
21
119
  twain: [
22
- 'entries', 'get', 'set', 'keys', 'clear', 'is_empty', 'values', 'copy', 'deepcopy', 'remove'
23
- ]
24
- }
120
+ "entries",
121
+ "get",
122
+ "set",
123
+ "keys",
124
+ "clear",
125
+ "is_empty",
126
+ "values",
127
+ "copy",
128
+ "deepcopy",
129
+ "remove",
130
+ ],
131
+ };
25
132
 
26
- this.datatypes = ['string', 'number', 'void', 'boolean', 'array', 'twain']
133
+ this.datatypes = ["string", "number", "void", "boolean", "array", "twain"];
27
134
  }
28
135
 
29
- gen_uid = ()=>{
30
- return `_${Math.random().toString().replace('.', '')}_${Date.now()}`
31
- }
136
+ gen_uid = () => {
137
+ return `_${Math.random().toString().replace(".", "")}_${Date.now()}`;
138
+ };
32
139
 
33
- parse_dynamic = async(literal, options={})=>{
34
- let {chain, config} = options;
140
+ parse_dynamic = async (literal, options = {}) => {
141
+ let { chain, config } = options;
35
142
 
36
143
  let aircode = this.account.aircode;
37
- let sequence = aircode.to_sequence(JSON.stringify(literal), chain.physical_address)
144
+ let sequence = aircode.to_sequence(
145
+ JSON.stringify(literal),
146
+ chain.physical_address
147
+ );
38
148
 
39
149
  let res = await chain.add_config(sequence[0].body[0]);
40
- let address = await this.execute(res, {chain})
150
+ let address = await this.execute(res, { chain });
41
151
 
42
152
  return address;
43
- }
153
+ };
44
154
 
45
- resolve_addr = (addr)=>{
46
- if (!addr)return addr
155
+ resolve_addr = (addr) => {
156
+ if (!addr) return addr;
47
157
 
48
- if (addr.startsWith('@')){
49
- addr = `${this.account.physical_address}/${addr.slice(2)}`
158
+ if (addr.startsWith("@")) {
159
+ addr = `${this.account.physical_address}/${addr.slice(2)}`;
50
160
  }
51
161
 
52
162
  return addr;
53
- }
163
+ };
54
164
 
55
- cloth_object = async addr=>{
56
-
57
- }
165
+ cloth_object = async (addr) => {};
58
166
 
59
- cloth_content = async(content, options)=>{
167
+ cloth_content = async (content, options) => {
60
168
  let obj;
61
169
 
62
- if (content instanceof Instance)return content;
63
-
64
- switch(content.type){
65
- case 'number':
66
- obj = new Num(content, this.account)
170
+ if (content instanceof Instance) return content;
171
+
172
+ switch (content.type) {
173
+ case "number":
174
+ obj = new Num(content, this.account);
175
+ break;
176
+ case "string":
177
+ obj = new Str(content, this.account);
67
178
  break;
68
- case 'string':
69
- obj = new Str(content, this.account)
179
+ case "boolean":
180
+ obj = new Bool(content, this.account);
70
181
  break;
71
- case 'boolean':
72
- obj = new Bool(content, this.account)
182
+ case "void":
183
+ obj = new Voi(content, this.account);
73
184
  break;
74
- case 'void':
75
- obj = new Voi(content, this.account)
185
+ case "array":
186
+ obj = new Arr(content, this.account);
76
187
  break;
77
- case 'array':
78
- obj = new Arr(content, this.account)
79
- break
80
- case 'twain':
81
- obj = new Twa(content, this.account)
188
+ case "twain":
189
+ obj = new Twa(content, this.account);
82
190
  break;
83
- case 'instance':
84
- obj = new Instance(content, this.account)
191
+ case "instance":
192
+ obj = new Instance(content, this.account);
85
193
  break;
86
- case 'function':
87
- obj = new Func(content, this.account)
194
+ case "function":
195
+ obj = new Func(content, this.account);
88
196
  break;
89
- case 'class':
90
- obj = new Cls(content, this.account)
197
+ case "class":
198
+ obj = new Cls(content, this.account);
91
199
  break;
92
200
  default:
93
- if (content.type === 'address'){
94
- obj = new Func(content, this.account)
95
- }else obj = content
96
- // console.log(content, 'uh')
201
+ if (content.type === "address") {
202
+ obj = new Func(content, this.account);
203
+ } else obj = content;
204
+ // console.log(content, 'uh')
97
205
  }
98
206
 
99
- return await obj.sync(options)
100
- }
207
+ return await obj.sync(options);
208
+ };
101
209
  }
102
210
 
103
211
  export default Vm_utils;