godprotocol 1.1.32 → 1.2.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.
Files changed (71) hide show
  1. package/Datatypes/arr.js +559 -254
  2. package/Datatypes/bool.js +8 -5
  3. package/Datatypes/callable.js +1 -1
  4. package/Datatypes/cls.js +193 -24
  5. package/Datatypes/conf.js +2 -2
  6. package/Datatypes/err.js +25 -0
  7. package/Datatypes/func.js +89 -13
  8. package/Datatypes/functions/storage.js +572 -12
  9. package/Datatypes/functions/wallet.js +49 -0
  10. package/Datatypes/instance.js +87 -122
  11. package/Datatypes/num.js +192 -153
  12. package/Datatypes/str.js +188 -122
  13. package/Datatypes/twa.js +346 -71
  14. package/Datatypes/voi.js +9 -4
  15. package/Index.js +1 -1
  16. package/Instances/account.js +0 -0
  17. package/Instances/event.js +0 -0
  18. package/Instances/fold.js +103 -0
  19. package/Instances/folder_queries.js +46 -0
  20. package/Instances/response.js +31 -0
  21. package/Objects/Account.js +160 -110
  22. package/Objects/Blockweb.js +6 -11
  23. package/Objects/Callable.js +223 -188
  24. package/Objects/Chain.js +127 -142
  25. package/Objects/Datatypes.js +114 -588
  26. package/Objects/Manager.js +349 -39
  27. package/Objects/Oracle.js +283 -210
  28. package/Objects/Repository.js +12 -33
  29. package/Objects/Trinity.js +9 -7
  30. package/Objects/Utils.js +8 -8
  31. package/Objects/Virtual_machine.js +320 -320
  32. package/README.md +0 -0
  33. package/callables/functions/assert.js +10 -0
  34. package/callables/functions/display.js +2 -3
  35. package/callables/functions/env.js +5 -0
  36. package/callables/functions/event.js +14 -0
  37. package/callables/functions/exit.js +3 -2
  38. package/callables/functions/folder.js +15 -0
  39. package/callables/functions/get_uid.js +6 -0
  40. package/callables/functions/hash.js +7 -0
  41. package/callables/functions/import_.js +62 -0
  42. package/callables/functions/local.js +9 -0
  43. package/callables/functions/net.js +33 -18
  44. package/callables/functions/parse.js +35 -0
  45. package/callables/functions/query.js +12 -0
  46. package/callables/functions/render.js +9 -13
  47. package/callables/functions/servers.js +10 -0
  48. package/callables/functions/spawn.js +7 -0
  49. package/callables/functions/store.js +75 -0
  50. package/callables/functions/super_.js +24 -0
  51. package/callables/functions/typeof.js +32 -0
  52. package/callables/functions/wait.js +9 -0
  53. package/callables/register.js +193 -8
  54. package/html/create.js +110 -0
  55. package/html/index.js +114 -0
  56. package/html/load.js +165 -0
  57. package/html/parse.js +171 -0
  58. package/html/run.js +151 -0
  59. package/html/util.js +5 -0
  60. package/package.json +5 -3
  61. package/repos/fs.js +114 -0
  62. package/repos/github.js +73 -0
  63. package/repos/ram.js +47 -0
  64. package/utils/create_server.js +66 -26
  65. package/utils/hash.js +3 -2
  66. package/utils/ops.js +2 -0
  67. package/utils/oracle_handlers.js +7 -0
  68. package/utils/services.js +18 -51
  69. package/utils/socket_server.js +36 -0
  70. package/utils/vm_utils.js +241 -137
  71. package/callables/functions/assign.js +0 -6
package/Objects/Chain.js CHANGED
@@ -1,208 +1,193 @@
1
- import Storage from "godprotocol/Datatypes/functions/storage";
1
+ import Datatypes from "./Datatypes.js";
2
2
 
3
- class Folder extends Storage{
4
- constructor(address, parent) {
5
- super(parent && parent.account.manager)
3
+ class Chain extends Datatypes{
4
+ constructor(address, account){
5
+ super()
6
6
 
7
- this.account = parent.account;
8
- this.physical_address = address
9
- this.path = ${this.account.manager.path}/${this.physical_address}
10
- this.parent = parent;
7
+ this.address = address
8
+ this.account = account;
11
9
  }
12
10
 
13
- sync = async()=>{}
11
+ chain = async(address)=>{
12
+ let chain = new Chain(address, this.account)
13
+ return chain;
14
+ }
14
15
 
15
- birth = async physical_address =>{
16
- let folder = new Folder(physical_address, this);
17
- await folder.sync()
16
+ folder = async (path)=>{
17
+ let fold = await this.account.ds.folder(this.address)
18
+ let folder = path ? await fold.folder(path) : fold
18
19
 
19
20
  return folder
20
21
  }
21
22
 
22
- chain = async(address)=>{
23
- if (!address.includes('/'))address = ${this.physical_address}/${address}
24
-
25
- let chain = await this.account.manager.web.set(address, this)
26
- return chain;
23
+ read = async()=>{
24
+ let folder = await this.folder()
25
+ return await folder.readone()
27
26
  }
28
27
 
29
- write = async (content, options)=>{
30
- let res;
31
- if (content && content.type === 'address' && options.hash) {
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) || {}
37
- let obj = {content, type: 'reference', previous: p_conf.current, sibling: conf.sibling}
38
- let hsh = await oracle.hash(obj)
39
- res = ${pth}/${hsh};
40
-
41
- await oracle.fs.write(res, JSON.stringify(obj))
42
- p_conf.current = res
43
- await oracle.fs.write(${pth}/.config, JSON.stringify(p_conf))
44
-
45
- conf.sibling = res;
46
- await oracle.fs.write(${this.path}/.config, JSON.stringify(conf))
47
- }else {
48
- res = await this.persist(content, {...options })
49
- }
50
- return res
28
+ write = async(data)=>{
29
+ let folder = await this.folder()
30
+ return await folder.write(data)
51
31
  }
52
32
 
53
- read =async (options={})=>{
54
- let res = await this.retrieve(options)
55
-
56
- return res;
57
- }
33
+ write_config = async(config, options={})=>{
34
+ let folder = await this.folder('.configs')
58
35
 
59
- write_config = async (config, options={})=>{
60
- return await this.persist(config, {...options, config: true, })
36
+ let res = await folder.write(
37
+ {...config, _id: options._id || config._id},
38
+ {replace: !!config._id || options.replace}
39
+ )
40
+ return res.datapath
61
41
  }
62
42
 
63
- add_config = async (config, options={})=>{
43
+ add_config = async(config, options)=>{
64
44
  let result;
65
45
 
66
46
  switch(config.type){
67
47
  case 'module':
68
48
  for (let b=0; b < config.body.length; b++){
69
49
  let line = config.body[b]
70
-
71
50
  config.body[b] = await this.add_config(line)
72
51
  }
73
- result = await this.write_config(config)
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;
83
- case 'class':
84
- let class_chain = await this.chain(config.name)
85
- for (let name in config.methods){
86
- config.methods[name] = await class_chain.add_config(config.methods[name])
87
- }
88
-
89
- result = await class_chain.write_config(config)
52
+ result = await this.write_config(config, options)
90
53
  break;
91
54
  case 'function':
92
- let fn_chain = await this.chain(config.name)
93
- for (let p=0; p< config.parameters.length; p++){
55
+ let fn_chain = await this.chain(config.address)
56
+ for (let p=0; p < config.parameters.length; p++){
94
57
  config.parameters[p] = await fn_chain.add_config(config.parameters[p])
95
58
  }
96
- for (let b=0; b< config.body.length; b++){
97
-
59
+ for (let b=0; b < config.body.length; b++){
98
60
  config.body[b] = await fn_chain.add_config(config.body[b])
99
61
  }
100
62
  result = await fn_chain.write_config(config)
101
63
  break;
102
- case 'return':
103
- config.output = await this.add_config(config.output)
104
- result = config
105
- break;
106
- case 'raise':
107
- config.object = await this.add_config(config.object)
108
- result = config
109
- break;
110
- case 'trycatch':
111
- let try_chain = await this.chain(config.location);
112
- for (let t=0;t< config.try_body.length; t++){
113
- config.try_body[t] = await this.add_config(config.try_body[t])
64
+ case 'class':
65
+ let cls_chain = await this.chain(config.address);
66
+ for (let name in config.methods){
67
+ let met = config.methods[name]
68
+ let res = await cls_chain.add_config(config.methods[name])
69
+
70
+ config.methods[name] = `${met.address}/${met._id}`
114
71
  }
115
- for (let t=0;t< config.catch_body.length; t++){
116
- config.catch_body[t] = await this.add_config(config.catch_body[t])
72
+ for (let name in config.properties){
73
+ let met = config.properties[name]
74
+ let res = await cls_chain.add_config(config.properties[name])
75
+ config.properties[name] = res
117
76
  }
118
- if (config.alias){
119
- config.alias = await this.add_config({type:'assignment', identifier: config.alias.value, value: {type:'void', value:'void'}})
77
+
78
+ for (let name in config.class_.properties){
79
+ let met = config.class_.properties[name]
80
+ let res = await cls_chain.add_config(config.class_.properties[name])
81
+ config.class_.properties[name] = res
120
82
  }
121
- result = await try_chain.write_config(config)
122
- break;
83
+
84
+ for (let name in config.class_.methods){
85
+ let met = config.class_.methods[name]
86
+ let res = await cls_chain.add_config(config.class_.methods[name])
87
+ config.class_.methods[name] = `${met.address}/${met._id}`
88
+ }
89
+ result = await cls_chain.write_config(config)
90
+ break
123
91
  case 'condition':
124
92
  let cond_chain = await this.chain(config.location)
125
- for(let b= 0; b< config.blocks.length; b++){
126
- let block= config.blocks[b]
127
- block.predicate = await cond_chain.add_config(block.predicate)
128
- for (let i=0; i< block.body.length; i++){
129
- block.body[i] = await cond_chain.add_config(block.body[i])
93
+ for (let b=0; b< config.blocks.length; b++){
94
+ let blk = config.blocks[b]
95
+ blk.predicate = await this.add_config(blk.predicate)
96
+ for (let d = 0; d <blk.body.length; d++){
97
+ blk.body[d] = await this.add_config(blk.body[d])
130
98
  }
131
99
  }
132
100
  result = await cond_chain.write_config(config)
133
101
  break;
134
- case 'assignment':
135
- let ass_chain = await this.chain(config.identifier)
136
-
137
- config.value = await ass_chain.add_config(config.value);
138
-
139
- result = await ass_chain.write_config(config)
140
- break;
141
102
  case 'loop':
142
103
  let loop_chain = await this.chain(config.location)
143
- config.condition = await this.add_config(config.condition)
144
- if(config.loop_type === 'for'){
145
- config.iterator = await this.add_config(config.iterator)
104
+ if (config.loop_type === 'for'){
146
105
  config.update = await this.add_config(config.update)
106
+ config.iterator = await this.add_config(config.iterator)
147
107
  }
108
+ config.condition = await this.add_config(config.condition)
148
109
 
149
110
  for (let b=0; b< config.body.length; b++){
150
111
  config.body[b] = await this.add_config(config.body[b])
151
112
  }
152
113
  result = await loop_chain.write_config(config)
153
114
  break;
115
+ case 'assignment':
116
+ config.value = await this.add_config(config.value)
117
+ result = await (await this.chain(`${this.address}/${config.identifier}`)).write_config(config)
118
+ break;
119
+ case 'nest':
120
+ let n_chain = await this.chain(config.location)
121
+ for (let n=0; n < config.nests.length; n++){
122
+ config.nests[n] = await n_chain.add_config(config.nests[n])
123
+ }
124
+ result = await n_chain.write_config(config)
125
+ break;
126
+ case 'return':
127
+ config.output = await this.add_config(config.output)
128
+ result = config;
129
+ break;
154
130
  case 'call':
155
- if(config.identifier.type === 'nest'){
156
- let addr = await this.add_config(config.identifier)
157
- config.identifier = {address: addr, type: 'nest'}
131
+ let call_chn = await this.chain(config.location)
132
+ if (config.identifier.type === 'nest'){
133
+ config.identifier = await (await this.chain(config.identifier.location)).write_config(config.identifier)
158
134
  }
159
- let call_chain = await this.chain(config.location)
160
- for(let a=0; a< config.arguments.length; a++){
161
- config.arguments[a] = await call_chain.add_config(config.arguments[a])
135
+ for (let a=0; a < config.arguments.length; a++){
136
+ let arg = config.arguments[a]
137
+ let chn = await this.chain(arg.location)
138
+ config.arguments[a] = await chn.add_config(arg)
162
139
  }
163
- result = await call_chain.write_config(config)
140
+ result = await call_chn.write_config(config)
141
+ break
142
+ case 'adm':
143
+ console.log(config)
144
+ let adm_chain = await this.chain(config.location)
145
+ result = await adm_chain.write_config(config)
164
146
  break;
165
- case 'nest':
166
- let nest_chain = await this.chain(config.location)
167
- for (let n=0; n< config.nests.length; n++){
168
- config.nests[n] = await nest_chain.add_config(config.nests[n])
147
+ case 'trycatch':
148
+ let try_chain = await this.chain(config.location)
149
+
150
+ for (let i=0; i < config.try_body.length; i++){
151
+ let tbd = config.try_body[i]
152
+ config.try_body[i] = await try_chain.add_config(tbd)
169
153
  }
170
- if(config.assignment)
171
- config.assignment = await nest_chain.add_config(config.assignment)
172
-
173
- result = await nest_chain.write_config(config)
154
+ for (let i=0; i < config.catch_body.length; i++){
155
+ let tbd = config.catch_body[i]
156
+ config.catch_body[i] = await try_chain.add_config(tbd)
157
+ }
158
+ result = await try_chain.write_config(config)
174
159
  break;
175
- default:
176
- if (['number', 'string', 'boolean'].includes(config.type)){
177
- result = await (await this.chain(config.location)).write_config(config)
178
- }else if(['variable', 'address', 'reference'].includes(config.type)){
179
- result = config;
180
- }else if (config.type === 'void'){
160
+ case 'raise':
161
+ let raise_chain = await this.chain(config.location)
162
+ config.object = await raise_chain.add_config(config.object)
163
+ result = raise_chain.write_config(config)
164
+ break
165
+ default:
166
+ if (config.type === 'void'){
181
167
  result = config
182
- }else if(config.type === 'twain'){
183
- let c_chain = await this.chain(config.location)
184
- for (let p in config.value){
185
- let pair = config.value[p]
186
- pair[0] = await this.add_config(pair[0])
187
- pair[1] = await this.add_config(pair[1])
188
- }
189
- result = await c_chain.write_config(config)
190
- } else if(config.type === 'array'){
191
- let c_chain = await this.chain(config.location)
192
- for (let i=0; i< config.value.length; i++){
193
- let item = config.value[i]
194
- config.value[i] = await this.add_config(item)
168
+ }else if (this.account.vm.datatypes.includes(config.type)){
169
+ if (config.type === 'array'){
170
+ for (let i=0; i< config.value.length; i++){
171
+ config.value[i] = await this.add_config(config.value[i])
172
+ }
173
+ } else if (config.type === 'twain'){
174
+ for (let key in config.value){
175
+ let pair = config.value[key]
176
+ pair[0] = await this.add_config(pair[0])
177
+ pair[1] = await this.add_config(pair[1])
178
+ }
195
179
  }
196
- result = await c_chain.write_config(config)
197
- }else if (['break', 'continue'].includes(config.type)){
198
- result = config;
180
+ let d_chain = await this.chain(config.location)
181
+ result = await d_chain.write_config(config)
182
+ } else if (['variable', 'reference'].includes(config.type)) {
183
+ result = config
184
+ } else if (['continue', 'break'].includes(config.type)) {
185
+ result = config
199
186
  }
200
-
201
187
  }
202
188
 
203
189
  return result;
204
190
  }
205
-
206
191
  }
207
192
 
208
- export default Folder;
193
+ export default Chain;