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/Objects/Oracle.js CHANGED
@@ -1,110 +1,93 @@
1
1
  import fs from "fs";
2
2
  import GDS from "generalised-datastore";
3
- import { hash } from "../utils/hash";
4
3
 
5
- class Oracle {
6
- constructor(mgr, meta) {
7
- meta = meta || {};
8
-
9
- this.compression = meta.compression;
4
+ class Fs {
5
+ constructor(oracle) {
6
+ this.oracle = oracle;
10
7
  this.fs = fs;
11
- this.mgr = mgr;
12
- this.datapaths = new Object();
13
- this.gds = new GDS(
14
- meta.datastore || process.env.DATASTORE || "godprotocol"
15
- ).sync({
16
- manager: this.mgr,
17
- });
8
+ this.base = __dirname;
18
9
  }
19
10
 
20
- get_folder = (physical_address, options) => {
21
- if (typeof options !== "object") {
22
- options = { no_new: options ? false : true };
23
- }
24
- return this.gds.folder(this.hash(physical_address));
11
+ exists = async (path) => {
12
+ this.fs.existsSync(`${this.base}/${path}`);
25
13
  };
26
14
 
27
- set = (path, { type, obj }) => {
28
- this.datapaths[path] = {
29
- obj,
30
- type,
31
- };
15
+ mkdir = async (path) => {
16
+ path = `${this.base}/${path}`;
17
+
18
+ !(await this.exists(path)) && this.fs.mkdirSync(path, { recursive: true });
32
19
  };
33
20
 
34
- get = (path) => {
35
- let obj = this.datapaths[path];
36
-
37
- if (!obj) {
38
- try {
39
- obj = this.fs.readFileSync(`${this.mgr.root}/${path}`, {encoding:'utf-8'});
40
- obj = JSON.parse(obj);
41
- let type = obj && obj.payload && typeof obj.payload;
42
- obj = obj && obj.payload;
43
- type =
44
- type === "object" ? (Array.isArray(obj) ? "array" : "twain") : type;
45
-
46
- obj = { type, obj };
47
- this.set(path, obj);
48
- } catch (e) {
49
- // console.log(e.message, 'Error thrown?')
50
- }
51
- }
21
+ read_file = async (path) => {
22
+ path = `${this.base}/${path}`;
23
+ try {
24
+ if (await this.exists(path)) return this.fs.readFileSync(path);
25
+ else return null;
26
+ } catch (e) {}
27
+ };
28
+
29
+ write_file = async (path, content) => {
30
+ if (typeof content !== "string") content = JSON.stringify(content);
52
31
 
53
- return obj;
32
+ this.fs.writeFileSync(`${this.base}/${path}`, content, { recursive: true });
54
33
  };
34
+ }
55
35
 
56
- hash = (data, alg) => {
57
- data = typeof data !== "string" ? JSON.stringify(data) : data;
58
- return hash(data, alg);
36
+ class Oracle {
37
+ constructor(manager) {
38
+ this.manager = manager;
39
+ this.repository = manager.repository;
40
+
41
+ this.fs = new Fs(this);
42
+ this.gds = new GDS(manager.name, { manager });
43
+ }
44
+
45
+ folder = async (physical_address, options) => {
46
+ return await this.gds.folder(physical_address, options);
59
47
  };
60
48
 
61
- handle_compression = ({ addr, data, no_string }) => {
62
- if (this.compression) {
63
- let res = this.compression({ addr, data, no_string });
64
- if (res) data = res.data;
65
- }
66
- if (!no_string && (typeof addr !== "string" || typeof data !== "string"))
67
- return;
49
+ sync = async () => {
50
+ await this.gds.sync();
51
+ };
68
52
 
69
- return data;
53
+ read = async (address, account) => {
54
+ let content = await this.repository.read_address(address);
55
+
56
+ return content;
70
57
  };
71
58
 
72
- write = (address, payload) => {
73
- payload = JSON.stringify({ payload });
74
- let data = this.handle_compression({
75
- addr: address,
76
- data: payload,
77
- });
78
-
79
- this.fs.writeFileSync(`${this.mgr.root}/${address}`, data, {
80
- encoding: "utf-8",
81
- });
59
+ write = async (payload) => {
60
+ await payload.hash();
61
+
62
+ let address = await this.repository.write_file(
63
+ payload.path,
64
+ payload.content
65
+ );
66
+
67
+ return address;
82
68
  };
83
69
 
84
- fetch = async (payload, callback) => {
85
- let { physical_address, config, remote, query } = payload,
86
- result;
87
-
88
- let folder = this.get_folder(physical_address);
89
-
90
- if (config) {
91
- result = folder.config.stringify();
92
- folder.add_remote(remote);
93
- } else {
94
- if (!folder.check_remote(query.operation)) {
95
- result = {
96
- error: true,
97
- error_message: "Query operation cannot be performed remotely.",
98
- };
99
- } else {
100
- let op = folder[query.operation];
70
+ add_server = async ({ path, ds, server }) => {
71
+ console.log(path, ds, "here", this.manager.server, server);
72
+ if (ds) {
73
+ if (this.gds.path === path) {
74
+ await this.gds.add_server(server);
101
75
 
102
- result = await op(query.query, query.options);
103
- folder.remote_stuff(remote, result);
76
+ return { listening: true };
77
+ } else return { not_found: true };
78
+ }
79
+ let folder = await this.gds.get_folder(path);
80
+ if (folder) {
81
+ await folder.add_server(server);
82
+ return { listening: true };
83
+ }
84
+ if (!folder) {
85
+ if (await this.fs.exists(path)) {
86
+ return { sleeping: true };
87
+ } else {
88
+ return { not_found: true };
104
89
  }
105
90
  }
106
-
107
- callback(result);
108
91
  };
109
92
  }
110
93
 
@@ -0,0 +1,67 @@
1
+ import { get_request, post_request } from "../utils/services";
2
+
3
+ class Repository {
4
+ constructor(manager) {
5
+ this.manager = manager;
6
+
7
+ this.gds = this.manager.oracle.gds;
8
+ }
9
+
10
+ read_address = async (address) => {
11
+ let content = await get_request(`${address}`);
12
+
13
+ try {
14
+ content = JSON.parse(content);
15
+ } catch (err) {}
16
+
17
+ return content;
18
+ };
19
+
20
+ sync = async () => {
21
+ this.ds = await this.gds.sync();
22
+ };
23
+
24
+ create_or_update_file = async (path, content, message, sha) => {
25
+ post_request({
26
+ data: {
27
+ content: Buffer.from(content).toString("base64"),
28
+ message: message || `Updating file content - ${Date.now()}`,
29
+ sha,
30
+ },
31
+ options: this.repo_domain,
32
+ path: `/repos/${this.manager.username}/${this.manager.repo_name}/contents/${path}`,
33
+ });
34
+
35
+ console.log("File created/updated successfully:", response.data);
36
+ };
37
+
38
+ get_file_sha = async (path) => {
39
+ try {
40
+ let sha = await post_request({});
41
+ return sha;
42
+ } catch (error) {
43
+ if (error.response && error.response.status === 404) {
44
+ console.log("File does not exist; a new file will be created.");
45
+ return null; // File doesn't exist, so SHA is not needed
46
+ }
47
+ throw new Error(`Failed to get file SHA: ${error.message}`);
48
+ }
49
+ };
50
+
51
+ write_file = async (path, content, message = "") => {
52
+ try {
53
+ let sha = await this.get_file_sha(path);
54
+
55
+ console.log(`File ${path} created/updated successfully.`);
56
+ } catch (error) {
57
+ console.error("Error creating/updating file:", error);
58
+ }
59
+
60
+ // Usage
61
+ // createOrUpdateFile("username", "my-new-repo", "README.md", "Hello, world!", "Add README");
62
+
63
+ return `${this.repo_domain}/${owner}/${path}`;
64
+ };
65
+ }
66
+
67
+ export default Repository;
@@ -0,0 +1,24 @@
1
+ import Manager from "./Manager";
2
+
3
+ class Trinity {
4
+ constructor() {
5
+ this.managers = new Object();
6
+ }
7
+
8
+ add_manager = async (name, options) => {
9
+ console.log(name, options);
10
+ let manager = new Manager(name, options);
11
+ let mgrs = this.managers[name];
12
+ if (!mgrs) {
13
+ mgrs = new Array();
14
+ this.managers[name] = mgrs;
15
+ }
16
+ await manager.sync();
17
+
18
+ mgrs.push(manager);
19
+
20
+ return manager;
21
+ };
22
+ }
23
+
24
+ export default Trinity;
@@ -1,220 +1,30 @@
1
- import Opcodes from "./Opcodes";
1
+ import Callable from "./Callable";
2
2
 
3
- class Virtual_machine extends Opcodes {
4
- constructor(context) {
3
+ class Virtual_machine extends Callable {
4
+ constructor(account) {
5
5
  super();
6
6
 
7
- this.account = context.account;
8
- this.contexts = [context];
9
- this.flags = {
10
- neg: false,
11
- equal: false,
12
- zero: false,
13
- void: false,
14
- };
15
-
16
- this.stacktrace = new Array()
17
-
18
- this.error_manager = new Object()
19
- }
20
-
21
- push_int = (name, payload)=>{
22
- let stacks = this.error_manager[name]
23
- if (!stacks){
24
- stacks = new Array()
25
- this.error_manager[name] = stacks;
26
- }
27
-
28
- stacks.push(payload)
7
+ this.account = account;
29
8
  }
30
9
 
31
- quit = (payload)=>{
32
- let instruction = this.track.sequence[this.track.pointer-1]
33
- if(instruction==='ret'){
34
- this.account.buff({ret:payload.op0}, this.track.pid)
35
- }
36
-
37
- this.account.flush_buffer(this.track.pid, payload);
38
- this.track.pointer = this.track.sequence.length;
39
- this.pop_context()
40
- }
41
-
42
- stderr = (err_object)=>{
43
- console.log(err_object)
44
- let{name, message} = err_object;
45
-
46
- if (!name){
47
- return this.quit(err_object)
48
- }
49
-
50
- let all = this.error_manager['*']
51
- let stacks = this.error_manager[name]
52
-
53
- if (!stacks){
54
- if(all){
55
- all = all.slice(-1)[0]
56
- let object = this.read_chain(`${this.error_instance_address}/${name}_`)
57
- stacks = [{object, metadata: all.metadata, catch_pointer: all.catch_pointer}]
58
-
59
- if(!object)return this.quit({message: `Unknown Error instance - ${name}`})
60
- }
61
-
62
- if (!stacks)
63
- return this.quit(err_object)
64
- }else if(all){
65
- // Check precedence within all and stacks name, how?
66
- }
67
-
68
- let obj_payload, s;
69
- for(s = this.stacktrace.length - 1; s >= 0; s--){
70
- let trace = this.stacktrace[s]
71
- let should_break;
10
+ sync = async () => {};
72
11
 
73
- for (let t = stacks.length-1; t >= 0; t--){
74
- obj_payload = stacks[t]
75
- if(obj_payload.metadata.namespace === trace){
76
- should_break = true
77
- break;
78
- }
79
- }
80
- if (should_break) break;
81
- }
12
+ execute = async (instruction) => {
13
+ let { opcode, payload } = this.parse_instruction(instruction);
82
14
 
15
+ let callable = await this.callable(opcode);
83
16
 
84
- if (!obj_payload){
85
- return this.quit(err_object)
86
- }
87
-
88
- if(obj_payload.metadata.alias){
89
- // Instantiate error message as an aircode string object.
90
- let message_string = `${obj_payload.metadata.namespace}/${this.id_hash(
91
- message
92
- )}`;
93
- this.air_object(message, {
94
- location: message_string,
95
- callback: () => {
96
- this.exec({
97
- executable: obj_payload.object.set_message,
98
- location: obj_payload.metadata.alias,
99
- metadata: {
100
- callback: () => {
101
- this.slice_trace(s+1)
102
-
103
- this.track = this.account.manager.set_track({account: this.account.name, physical_address: obj_payload.metadata.namespace, pointer: obj_payload.catch_pointer}, true)
104
- },
105
- },
106
- arguments: {
107
- argv: [
108
- {
109
- address: message_string,
110
- position: 0,
111
- },
112
- ],
113
- argc: 1,
114
- },
115
- });
116
- },
17
+ if (!callable) {
18
+ return await this.stderr({
19
+ name: "runtime_error",
20
+ message: `opcode:${opcode} is not set.`,
117
21
  });
118
-
119
- }else {
120
- this.slice_trace(s-3)
121
-
122
- this.track = this.account.manager.set_track({account: this.account.name, physical_address: obj_payload.metadata.namespace, pointer: obj_payload.catch_pointer}, true)
123
-
124
22
  }
125
- }
23
+ let call = callable.callable;
24
+ let args = await this.parse_arguments(payload, callable.config);
126
25
 
127
- execute = (instruction, track) => {
128
- this.track = track;
129
-
130
- if (!instruction) return;
131
-
132
- let { opcode, args } = this.split_instruction(instruction);
133
-
134
- let context = this.get_context(-1);
135
-
136
- if (!context) return;
137
-
138
- context.add_tx(instruction);
139
-
140
- // console.log(`(${track.pointer}/${track.sequence.length})>> ${instruction}`)
141
- // this.account.log_output(`>> ${instruction}`);
142
-
143
- let chain;
144
-
145
- args = this.parse_arg(args, opcode);
146
-
147
- switch (opcode) {
148
- case "chain":
149
- chain = this.handle_chain(args, context)
150
-
151
- if(!chain)return this.stderr(`Chain error - ${args}`)
152
-
153
- this.push_context(chain);
154
-
155
- let dim = context.folder.config.dimensions;
156
- if (!dim) {
157
- dim = [];
158
- context.folder.config.dimensions = dim;
159
- }
160
- !dim.find((d) => d === args) && dim.push(args);
161
-
162
- chain.append_buffer();
163
-
164
- break;
165
- case "link":
166
- chain = this.handle_chain(args, context)
167
-
168
- if (!chain) {
169
- return this.stderr(`LINKing Failed. - ${args}`)
170
- }
171
-
172
- chain.append_buffer();
173
-
174
- this.push_context(chain);
175
-
176
- break;
177
- case "pop":
178
- let blk;
179
- if (context.txs.length > 1) {
180
- blk = context.mine(this);
181
- } else {
182
- if (this.account.initiated&& this.account.is_datatype(context)){
183
- blk= context.mine(this)
184
- }else {
185
- blk = context.get_latest_block();
186
- if(!blk || context.datapath){
187
- if(context.datapath){
188
- blk = context.fabricate_datapath_block()
189
- }else blk = this.get_voided_block()
190
- }
191
-
192
- if (blk){
193
- if (blk.chain.physical_address!== `${this.account.physical_address}/Datatypes/Void`) this.flags.void = false
194
-
195
- this.get_context(-2).connections.push(blk);
196
- }
197
-
198
- context.get_buffer()
199
- context.txs = [];
200
- }
201
-
202
- }
203
-
204
- blk && this.account.buff(blk, this.track.pid);
205
-
206
- this.pop_context();
207
- break;
208
- case "cursor":
209
- context.set_cursor(args);
210
- break;
211
- case "write":
212
- context.account.write(args, context);
213
- break;
214
- default:
215
- this.prepare_operation(opcode, context);
216
- break;
217
- }
26
+ let result = await call(args);
27
+ return result;
218
28
  };
219
29
  }
220
30
 
@@ -0,0 +1,6 @@
1
+ const assign = async (args, vm, options) => {
2
+ console.log(args);
3
+ process.exit();
4
+ };
5
+
6
+ export default assign;
@@ -0,0 +1,3 @@
1
+ const display = async (args) => {};
2
+
3
+ export default display;
@@ -0,0 +1,22 @@
1
+ import assign from "./functions/assign";
2
+ import display from "./functions/display";
3
+
4
+ const register = async (account) => {
5
+ let set = account.vm.set;
6
+
7
+ set("assign", {
8
+ callable: assign,
9
+ config: {
10
+ parameters: [{ name: "assignment", position: 0 }],
11
+ },
12
+ });
13
+
14
+ set("display", {
15
+ callable: display,
16
+ config: {
17
+ parameters: [{ name: "data", position: 0, spread: true }],
18
+ },
19
+ });
20
+ };
21
+
22
+ export default register;
package/package.json CHANGED
@@ -1,60 +1,41 @@
1
1
  {
2
2
  "name": "godprotocol",
3
- "version": "1.1.0",
4
- "description": "A data mediator.",
3
+ "version": "1.1.2",
4
+ "description": "A distributed computing environment",
5
5
  "main": "Index.js",
6
- "types": "types/index.d.ts",
7
6
  "scripts": {
8
7
  "test": "echo \"Error: no test specified\" && exit 1",
9
- "start": "nodemon -r esm Index.js",
10
- "prepack": "npmignore"
11
- },
12
- "author": "Savvy",
13
- "license": "ISC",
14
- "devDependencies": {
15
- "@babel/cli": "latest",
16
- "@babel/core": "^7.19.1",
17
- "apidoc": "^0.54.0",
18
- "babel-preset-env": "^1.7.0",
19
- "esm": "^3.2.25",
20
- "nodemon": "^3.1.0",
21
- "npmignore": "^0.3.1"
8
+ "start": "nodemon -r esm Index.js"
22
9
  },
23
10
  "repository": {
24
11
  "type": "git",
25
- "url": "git+https://github.com/godprotocol4/godprotocol.git"
26
- },
27
- "bugs": {
28
- "url": "https://github.com/godprotocol4/godprotocol/issues"
12
+ "url": "git+https://github.com/immanuel-savvy/GodProtocol.git"
29
13
  },
30
- "homepage": "https://github.com/godprotocol4/godprotocol#readme",
31
14
  "keywords": [
32
- "web 4.0",
33
- "framework",
34
- "intelligence",
35
- "AR / VR",
36
- "modeling",
37
- "load sequence",
38
- "blockchain",
39
- "instruction",
40
- "decentralisation",
41
- "distribution",
42
- "flow",
43
- "godprotocol"
15
+ "decentralise",
16
+ "distribute",
17
+ "web4",
18
+ "ai",
19
+ "ar",
20
+ "vr",
21
+ "virtual-machine"
44
22
  ],
23
+ "author": "Savvy",
24
+ "license": "ISC",
25
+ "bugs": {
26
+ "url": "https://github.com/immanuel-savvy/GodProtocol/issues"
27
+ },
28
+ "homepage": "https://github.com/immanuel-savvy/GodProtocol#readme",
45
29
  "dependencies": {
30
+ "@octokit/rest": "^21.0.2",
46
31
  "crypto": "^1.0.1",
47
- "elliptic": "^6.5.5",
32
+ "elliptic": "^6.6.0",
48
33
  "fs": "^0.0.1-security",
49
- "generalised-datastore": "^2.0.112"
34
+ "generalised-datastore": "^2.0.13",
35
+ "js-base64": "^3.7.7"
50
36
  },
51
- "publishConfig": {
52
- "ignore": [
53
- "Accounts/",
54
- ".github/",
55
- "build/",
56
- ".babelrc",
57
- "node_modules/"
58
- ]
37
+ "devDependencies": {
38
+ "esm": "^3.2.25",
39
+ "nodemon": "^3.1.7"
59
40
  }
60
41
  }