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
@@ -1,135 +1,185 @@
1
- import Utils from "./Utils";
2
- import register from "../callables/register";
3
- import Chain from "./Chain";
4
- import Virtual_machine from "./Virtual_machine";
1
+ import Utils from "./Utils.js";
2
+ import Compiler from "aircode4";
3
+ import Chain from "./Chain.js";
4
+ import Virtual_machine from "./Virtual_machine.js";
5
+ import register from "godprotocol/callables/register.js";
6
+ import { hash } from "godprotocol/utils/hash.js";
7
+
8
+ class Account extends Utils{
9
+ constructor(name, options){
10
+ super()
11
+
12
+ this.name = name
13
+ this.options = options
14
+ this.manager = options.manager
15
+ this.vm = new Virtual_machine(this)
16
+ this.compiler = new Compiler(this)
17
+ }
18
+
19
+ load = async(payload, options)=>{
20
+ let {address, sequence, compiler, from_reload, _id} = payload
5
21
 
6
- class Account extends Utils {
7
- constructor(name, options) {
8
- super();
22
+ let phy = `${this.physical_address}/${address}`
23
+ let chain = await this.chain.chain(phy)
9
24
 
10
- this.name = name;
25
+ if (compiler){
26
+ !from_reload && await this.manager.oracle.write(`${phy}/air`, sequence, {account: this.physical_address, prefix: '.codes', address: phy})
27
+
28
+ sequence = await this.compiler.to_sequence(sequence, address)
29
+ sequence = sequence[0]
30
+ }
31
+
32
+ let res = await chain.add_config(sequence, {...options, _id})
11
33
 
12
- this.manager = options.manager;
13
- this.parent = options.parent || this;
14
- this.repository = this.manager.repository;
15
- this.account = this;
34
+ return res;
35
+ }
16
36
 
17
- this.physical_address = `Accounts/${name}`;
18
- this.buffs = new Array();
37
+ run = async(payload, socket)=>{
38
+ let {address, _id, env, config, thread, callback}= payload;
19
39
 
20
- this.chain = new Chain(this.physical_address, this.parent);
21
- this.path = this.chain.path;
40
+ if(!config){
41
+ let phy = `${this.physical_address}/${address}`
42
+ let chain = await this.chain.chain(phy)
22
43
 
23
- console.log(`Account Created: ${this.name}`);
24
- }
44
+ let folder = await chain.folder('.configs')
45
+ config = await folder.readone(_id? {_id}: null)
25
46
 
26
- load = async (payload) => {
27
- let { sequence: codes, account, physical_address, options } = payload;
47
+ if (!config){
48
+ let code = await this.manager.oracle.read(`${phy}/air`, {account: this.physical_address, prefix: '.codes', address: phy})
49
+ if (code){
50
+ code = await this.compiler.to_sequence(code, address)
51
+ code = code[0]
28
52
 
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
- }
53
+ config = code;
36
54
 
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];
55
+ await this.load({address, sequence: config, _id})
56
+ }
41
57
  }
42
58
  }
43
- if (Array.isArray(codes)) {
44
- codes = codes[0];
59
+
60
+ if (!config){
61
+ return {message: 'Code not found!'}
45
62
  }
46
63
 
47
- physical_address = `${this.physical_address}/${physical_address}`;
64
+ let result = await this.vm.nodelist(config)
65
+
66
+ let thread_id = await this.manager.load(result, this, {spawn: thread && thread._id, pointer: thread && thread.pointer, callback: async res=>{
67
+ if (typeof callback === 'string'){
68
+ if (callback === 'store' && !Array.isArray(res)){
69
+ let store_fn = await this.vm.callable('store');
70
+ await store_fn.callable({object: await this.vm.cloth(res)}, {vm: this.vm, chain: this.chain})
71
+ callback = res.value
72
+ }else {
73
+ let folder = await this.ds.folder(callback)
74
+ await folder.write(res, {replace: true})
75
+ }
76
+ }else if (typeof callback === 'function'){
77
+ await callback(res)
78
+ }
79
+ if (socket){
80
+ // handle socket
81
+ }
82
+ }})
48
83
 
49
- let chain = await this.chain.chain(physical_address);
84
+ if (env){
85
+ this.vm.envs[thread_id] = env
86
+ }
50
87
 
51
- let res = { value: await chain.add_config(codes), type: "address" };
88
+ return {thread_id, callback}
89
+ }
90
+
91
+ parse = async (payload)=>{
92
+ let {address, query, retrieve, from} = payload
52
93
 
53
- console.log(res, codes, chain.physical_address);
54
- return res;
55
- };
56
-
57
- run = async (payload) => {
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 });
94
+ if (!address){
95
+ return {
96
+ message: 'Invalid payload.'
97
+ }
75
98
  }
99
+ let phy = `${this.physical_address}/${address}`
76
100
 
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
- };
101
+ if (from === '.codes'){
102
+ let res = await this.manager.oracle.read(`${phy}/air`, {account: this.physical_address, address: phy, prefix: from})
103
+ if (res){
104
+ return {result: res}
105
+ }else return {message: 'Code not found'}
106
+ }
107
+ else if (from === 'thread'){
108
+ // is thread_id;
109
+ let thread_info = this.manager.accounts_pairs[this.name]
110
+ let thread = thread_info.threads[address]
111
+
112
+ return thread ? {
113
+ _id: thread._id,
114
+ status: thread.status,
115
+ spawn: thread.spawn,
116
+ callback: thread.callback,
117
+ pointer: thread.pointer,
118
+ total: thread.bullets.length
119
+ } : {}
120
+ }
121
+
122
+ let folder = await this.ds.folder(phy, from === 'ram' ? null : {account: this.physical_address})
123
+
124
+ let result = await folder.readone(query.query, {...query.options})
125
+ if (!result) return result;
126
+
127
+ if (from !== 'ram'){
128
+ if (this.vm.datatypes.includes(result.type)){
129
+ let obj = await this.vm.retrieve(result, true)
130
+ if (retrieve){
131
+ result = await obj.to_address()
132
+ } else result.literal = await (obj).literal()
133
+ }else if (retrieve){
134
+ result = await this.vm.retrieve(result)
135
+ }
136
+ } else {
137
+ if (this.vm.datatypes.includes(result.type)){
138
+ if (retrieve){
139
+ result = await (await this.vm.cloth_content(result)).to_address()
140
+ }else result.literal = await (await this.vm.cloth_content(result)).literal()
141
+ }else if (retrieve){
142
+ result = await this.vm.cloth_content(result)
85
143
  }
86
144
  }
87
145
 
146
+ return result
147
+ }
148
+
149
+ verify = async(password)=>{
150
+ let servers = await this.manager.oracle.get_servers(this.physical_address)
151
+
152
+ if(!servers.length) servers = await this.manager.oracle.update_servers(this.physical_address)
153
+
154
+ let passes = await this.ds.folder(`${this.physical_address}/__passwords`, {account: this.physical_address})
155
+
156
+ let pass = await passes.readone()
157
+
158
+ if (pass){
159
+ let passed = pass && pass.key === hash(password)
160
+
161
+ passed && await this.manager.oracle.update_servers(this.physical_address)
162
+ return passed
163
+ }else await passes.write({key: hash(password)})
164
+
165
+ return true;
166
+ }
167
+
168
+ sync = async()=>{
169
+ this.physical_address = `${"Accounts"}/${this.name}`
170
+ this.chain = new Chain(`${this.physical_address}`, this)
171
+ this.ds = this.manager.ds
172
+
173
+ let pass = this.options.password, res = true
174
+
175
+ if (pass) {
176
+ res = await this.verify(pass)
177
+ }
178
+
179
+ await register(this)
180
+
88
181
  return res;
89
- };
90
-
91
- parse = async (payload) => {
92
- let { account, physical_address, depth, history, query } = payload;
93
-
94
- let acc = (await this.manager.get_account(account)) || this;
95
- let chain = await acc.chain.chain(
96
- `${acc.physical_address}/${physical_address}`
97
- );
98
-
99
- let config = await chain.read({ query, depth, history });
100
- return config;
101
- };
102
-
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();
110
-
111
- return acc;
112
- };
113
-
114
- sync = async () => {
115
- this.servers = new Array();
116
- this.vm = new Virtual_machine(this);
117
- this.compiler = new this.manager.compiler(this);
118
-
119
- await this.chain.sync();
120
- await this.vm.sync();
121
-
122
- await register(this);
123
- };
124
-
125
- stringify = () => {
126
- return {
127
- physical_address: this.physical_address,
128
- path: this.path,
129
- name: this.name,
130
- private: this.private,
131
- };
132
- };
182
+ }
133
183
  }
134
184
 
135
185
  export default Account;
@@ -1,3 +1,5 @@
1
+ import Chain from "./Chain.js";
2
+
1
3
  class Blockweb{
2
4
  constructor(mgr){
3
5
  this.mgr = mgr;
@@ -6,17 +8,10 @@ class Blockweb{
6
8
  }
7
9
 
8
10
  set = async(physical_address, parent)=>{
9
- let load = this.chains[physical_address]
10
- if (!load){
11
- load = {parents: new Object(), chains: new Array()}
12
- this.chains[physical_address] = load
13
- }
14
-
15
- load.parents[parent.physical_address] = parent;
16
- let child = await parent.birth(physical_address)
17
- load.chains.push(child)
18
-
19
- return child;
11
+ let folder = new Chain(physical_address, parent)
12
+ await folder.sync()
13
+
14
+ return folder;
20
15
  }
21
16
  }
22
17