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
@@ -1,33 +0,0 @@
1
- class Repository {
2
- constructor(main) {
3
- this.main = main;
4
- this.oracle = this.main.account.manager.oracle;
5
- this.gds = this.oracle.gds;
6
- this.programs = this.gds.folder("programs");
7
- this.codes = this.gds.folder("codes");
8
- }
9
-
10
- add_program = (config) => {
11
- let codes = config.codes.filter(line=>!!line.trim())
12
- let code_hash = this.oracle.hash(codes);
13
- let code_exist = this.codes.readone({ hash: code_hash });
14
-
15
- let code = this.codes.write({
16
- body: codes,
17
- hash: code_hash,
18
- _id: code_exist && code_exist._id,
19
- });
20
- config.codes = code._id;
21
-
22
- let program_hash = this.oracle.hash(JSON.stringify(config));
23
- let program_exist = this.programs.readone({ hash: program_hash });
24
-
25
- this.programs.write({
26
- ...config,
27
- hash: program_hash,
28
- _id: program_exist && program_exist._id,
29
- });
30
- };
31
- }
32
-
33
- export default Repository;
@@ -1,40 +0,0 @@
1
- class Explorer {
2
- constructor() {}
3
-
4
- chain_props = ["blocks"];
5
-
6
- explore = (query) => {
7
- if (!query) return;
8
-
9
- if (query.startsWith("{")) query = query.slice(1, -1);
10
- query = query.split(":");
11
-
12
- query[0] = query[0].split(".");
13
-
14
- let q2 = Number(query[1]),
15
- prop;
16
-
17
- if (this.chain_props.includes(query[0][0])) prop = query[0][0];
18
-
19
- let obj;
20
- if (isNaN(q2)) {
21
- obj = this[prop || "connections"].find((c) => c.hash === query[1]);
22
- } else if (q2 >= 0) {
23
- obj = this[prop || "connections"].find((q) => q.index === q2);
24
- } else {
25
- obj = this[prop || "connections"].slice(q2)[0];
26
- }
27
-
28
- if (!prop)
29
- for (let q = 0; q < query[0].length; q++) {
30
- let que = query[0][q];
31
-
32
- if (!obj) break;
33
- obj = obj[que];
34
- }
35
-
36
- return obj;
37
- };
38
- }
39
-
40
- export default Explorer;
package/Objects/Fee.js DELETED
@@ -1,33 +0,0 @@
1
- class Fee {
2
- constructor(chain){
3
- this.chain = chain;
4
-
5
- this.fees = new Object()
6
- }
7
-
8
- set = ({purpose, fee, validator})=>{
9
- let fees= this.fees[purpose]
10
- if (!fees){
11
- fees = new Array();
12
- this.fees[purpose] = fees;
13
- }
14
- fees.push({fee, validator})
15
- }
16
-
17
- get = (purpose)=>{
18
- let fees = this.fees[purpose]
19
- if (!fees)return
20
-
21
- return fees.slice(-1)[0]
22
- }
23
- }
24
-
25
- // Fee is a physical_address
26
- // Validator is also a physical_address
27
- // If fee address is a callable/executable
28
- // validator runs itself using the result from the address using the payload as argument 0
29
- // Else if fee is a datastructure,
30
- // validator runs itself using data as argument.
31
- // Validator must return a true, to pass.
32
-
33
- // A chain can have multiple price purposes.
@@ -1,216 +0,0 @@
1
- import { hash } from "../utils/hash";
2
-
3
- class Filesystem {
4
- constructor() {
5
- this.root = process.env.ROOT || __dirname;
6
- this.base_address = process.env.BASE_ADDRESS || "Accounts";
7
- }
8
-
9
- parse_path = (path) => {
10
- if (!path || (typeof path === 'string' && (!path.includes("/") || path.includes(' ')))) return path;
11
-
12
- return this.read(path);
13
- };
14
-
15
- read = (datapath) => {
16
- if (!datapath) return null;
17
-
18
- let type_folder = this.account.manager.oracle.get(datapath);
19
-
20
- if (!type_folder){
21
- return datapath;
22
- }
23
-
24
- let content;
25
- if (type_folder.type === "twain") {
26
- content = {};
27
- for (let prop in type_folder.obj) {
28
- let val = type_folder.obj[prop];
29
-
30
- content[this.parse_path(prop)] = this.parse_path(val);
31
- }
32
- } else if (type_folder.type === "array") {
33
- content = [];
34
- type_folder.obj.map((t) => {
35
- content.push(this.parse_path(t));
36
- });
37
- } else content = type_folder.obj;
38
-
39
- return content;
40
- };
41
-
42
- object_type = (obj, chain)=>{
43
- let type = typeof obj
44
- if (type === 'object'){
45
- if (Array.isArray(obj)) type = 'array'
46
- else if (!obj) type = 'void'
47
- else type = 'twain'
48
- }
49
-
50
- if (!chain)return type;
51
-
52
- type = `${type[0].toUpperCase()}${type.slice(1)}`
53
-
54
- return this.get_datatype_chain(type)
55
- }
56
-
57
- get_datatype_chain = (type)=>{
58
- let chain = this.vm.handle_chain(`${this.account.physical_address}/Datatypes/${type}`)
59
-
60
- return chain
61
- }
62
-
63
- save = (content, chain, options) => {
64
- let just_obj, pure;
65
- if (typeof options !== 'object'){
66
- just_obj = options
67
- }else if(options) {
68
- just_obj = options.just_obj
69
- pure = options.pure
70
- }
71
- let addr, obj;
72
-
73
- if (!chain){
74
- chain = this.object_type(content, true)
75
- }
76
-
77
- let type = typeof chain === "string" ? chain : this.get_type(chain);
78
-
79
-
80
- if(!pure){
81
- if(typeof content==='string'){
82
- if(type!=="string")obj= JSON.parse(content)
83
- else obj = content
84
- } else{
85
- if (type === "array" || type === "string") {
86
- obj = [];
87
-
88
- for (let curs in content)
89
- obj.splice(Number(curs) || -1, 0, content[curs]);
90
-
91
- if (type === "string") obj = obj.join(" ");
92
- } else if (type === "twain") {
93
- obj = {};
94
- for (let curs in content) {
95
- obj[curs] = content[curs];
96
- }
97
- } else if (type === "number") {
98
- obj = Number(content["-1"]);
99
- if (isNaN(obj)) obj = 0;
100
- }else if (type === 'boolean'){
101
- obj = content['-1']
102
- obj = obj === 'True' ? true:false
103
- } else {
104
- obj = null;
105
- }
106
- }
107
- }else obj = content
108
-
109
- if (just_obj) return obj;
110
-
111
- addr = `${chain.path}/${hash(JSON.stringify(obj))}`;
112
- this;
113
- if (obj != null || type === 'void') this.manager.oracle.write(addr, obj);
114
-
115
- this.manager.oracle.set(addr, { obj, type });
116
-
117
- return addr;
118
- };
119
-
120
- data_addr = (type) => {
121
- return `${this.physical_address}/Datatypes/${type}`;
122
- };
123
-
124
- get_type = (chain) => {
125
- switch (chain.physical_address) {
126
- case this.data_addr(`Number`):
127
- return "number";
128
- case this.data_addr(`String`):
129
- return "string";
130
- case this.data_addr(`Twain`):
131
- return "twain";
132
- case this.data_addr(`Array`):
133
- return "array";
134
- case this.data_addr(`Boolean`):
135
- return "boolean";
136
- case this.data_addr(`Void`):
137
- return "void";
138
- }
139
- };
140
-
141
- is_datatype=chain=>{
142
-
143
- let type = this.get_type(chain);
144
- return !!type
145
- }
146
-
147
- stringify_type = (type)=>{
148
- let val;
149
- switch(type){
150
- case 'string':
151
- val = ""
152
- break;
153
- case 'number':
154
- val = "0"
155
- break;
156
- case 'array':
157
- val = "[]"
158
- break;
159
- case 'twain':
160
- val = "{}"
161
- break;
162
- case 'void':
163
- val = 'null'
164
- break
165
- ;
166
- }
167
- return val
168
- }
169
-
170
- write = (arg, context) => {
171
- let content = context.get_buffer();
172
-
173
- if (!content || !arg) return;
174
-
175
- content[context.cursor] = arg;
176
- };
177
-
178
- name_hash = () => {
179
- this.hash = hash(this.name);
180
- };
181
-
182
- set_paths = (chain) => {
183
- if (chain.parent && chain.parent.manager) {
184
- chain.path = chain.parent.path;
185
- return;
186
- }
187
- chain.path = `${chain.parent ? chain.parent.path : this.base_address}/${
188
- chain.hash
189
- }`;
190
-
191
- let fs = this.manager.oracle.fs;
192
-
193
- if (!fs.existsSync(`${this.manager.root}/${chain.path}`)) {
194
- fs.mkdirSync(`${this.manager.root}/${chain.path}`, { recursive: true });
195
- }
196
- };
197
-
198
- add_chain = (name, parent) => {
199
- let chain = this.manager.web.get(`${parent.physical_address}/${name}`);
200
- if (!chain) chain = this.manager.web.set(parent, name);
201
-
202
- return chain;
203
- };
204
-
205
- account_chain = (account) => {
206
- let chain = this.manager.web.get(account.physical_address);
207
-
208
- if (!chain) {
209
- chain = this.manager.web.set(account);
210
- }
211
-
212
- return chain;
213
- };
214
- }
215
-
216
- export default Filesystem;
package/Objects/Frame.js DELETED
@@ -1,54 +0,0 @@
1
- import { array_to_nested_objects } from "../utils/functions";
2
-
3
- class Frame {
4
- constructor(object, parent) {
5
- this.parent = parent;
6
-
7
- this.object = Array.isArray(object)
8
- ? array_to_nested_objects(object)
9
- : object;
10
-
11
- this.instructions = new Array();
12
- }
13
-
14
- frame = (object) => {
15
- let frame = new Frame(object, this);
16
- frame.account = this.account;
17
-
18
- this.instructions.push(frame);
19
-
20
- return frame;
21
- };
22
-
23
- to_instruction = () => {
24
- for (let prop in this.object) {
25
- let val = this.object[prop];
26
- this.instructions.push(`chain ${prop}`);
27
-
28
- if(val && val.__type){
29
- let instructions = this.account.assembler.run(JSON.stringify(val.value), {instructions: true, pure: true})
30
-
31
- this.instructions.push(...instructions)
32
-
33
- this.instructions.push(`cursor {output}`)
34
- this.instructions.push(`write {datapath:-1}`)
35
- }else val && this.frame(val).to_instruction();
36
-
37
- this.instructions.push(`pop ${prop}`);
38
- }
39
- };
40
-
41
- flatten_instructions = () => {
42
- let inss = new Array();
43
-
44
- for (let i = 0; i < this.instructions.length; i++) {
45
- let ins = this.instructions[i];
46
- if (ins instanceof Frame) inss.push(...ins.flatten_instructions());
47
- else inss.push(ins);
48
- }
49
-
50
- return inss;
51
- };
52
- }
53
-
54
- export default Frame;
@@ -1,87 +0,0 @@
1
- import Vm_utils from "../utils/vm_utils";
2
- import { obj } from "../framer";
3
-
4
- class Opcodes extends Vm_utils {
5
- constructor() {
6
- super()
7
-
8
- this.opcodes = new Object();
9
- }
10
-
11
- set = (opcode, circuit) => {
12
- this.opcodes[opcode] = circuit;
13
- obj.Opcodes[opcode] = null;
14
-
15
- this.account.assembler.opcodes.push(opcode);
16
- };
17
-
18
- prepare_operation = (opcode, context) => {
19
- let circ = this.opcodes[opcode];
20
-
21
- if (typeof circ !== "function") return;
22
-
23
- let buf = context.get_buffer();
24
-
25
- let args =
26
- context.account.read(buf && buf.inputs) ||
27
- this.account.stdin.splice(-1)[0];
28
-
29
- try{
30
- let res = circ(args, this);
31
-
32
- this.stdin(this.static_cast(res));
33
- } catch(e){
34
- console.log(e)
35
- this.stderr(`${JSON.stringify({circuit:opcode,args, error_message:e.message})}`)
36
- }
37
- };
38
-
39
- stdin = (object, cb, options) => {
40
- options = options || {}
41
- let full_obj = object
42
- object = object.static_value
43
-
44
- if (object == null) {
45
- this.flags.void = true;
46
- object = null
47
- } else this.flags.void = false;
48
-
49
- this.flags.zero = !object;
50
- if (typeof object === "number") this.flags.neg = object < 0;
51
-
52
- let code_string;
53
-
54
- if (cb && cb.payload && cb.payload.stdin)
55
- options.address = cb.payload.stdin;
56
-
57
- if (!options.address){
58
- let contx_2 = this.get_context(-2)
59
- if (full_obj&& typeof full_obj === 'object'){
60
- if(contx_2){
61
- full_obj.__address__ = contx_2.physical_address
62
- }else full_obj .__address__ = this.get_context().physical_address
63
- }
64
- }
65
-
66
- if (typeof full_obj === 'string'){
67
- code_string = full_obj
68
- } else if (full_obj.type){
69
- if (full_obj.type === 'boolean'){
70
- code_string = `{"type":"boolean", "static_value":${full_obj.static_value?'True':'False'},"__address__":"${full_obj.__address__}"}`
71
- }else code_string = JSON.stringify(full_obj)
72
- }else code_string= typeof object !== "string" ?object ==null?'Void': JSON.stringify(object) : `"${object}"`;
73
-
74
- if (options.address){
75
- let addr = options.address;
76
- if(!addr.startsWith('@')){
77
- addr = `@/${addr.split('/').slice(2).join('/')}`
78
- }
79
-
80
- code_string = `>${addr} ${code_string}`
81
- }
82
-
83
- this.account.assembler.run(code_string, { cb, pure: true });
84
- };
85
- }
86
-
87
- export default Opcodes;
@@ -1,5 +0,0 @@
1
- class Protocol{
2
-
3
- }
4
-
5
- export default Protocol
package/Trinity.js DELETED
@@ -1,20 +0,0 @@
1
- import create_server from "./utils/create_server"
2
- import Manager from "./Objects/Manager";
3
-
4
- class Trinity{
5
- constructor(){
6
- this.manager = new Manager()
7
- }
8
-
9
- create_server = (app, settings)=>{
10
- settings = settings||{}
11
- create_server(app, {...settings, manager: this.manager})
12
- }
13
-
14
- account= name=>this.manager.get_account(name)
15
-
16
- add_account = (name, meta) =>this.manager.add_account(name, meta)
17
- }
18
-
19
-
20
- export default Trinity
package/callables.js DELETED
@@ -1,172 +0,0 @@
1
- import { get, set } from "./Executables/functions/indices";
2
- import { display } from "./Executables/functions/display";
3
- import typecast from "./Executables/functions/typecast";
4
- import { ops } from "./opcodes/add";
5
- import operation from "./Executables/functions/op";
6
- import assign from "./Executables/functions/assign";
7
- import importcheck from "./Executables/functions/importcheck";
8
- import set_error_catch from "./Executables/functions/set_error_catch";
9
- import string_register from "./Executables/functions/string_register";
10
- import array_register from "./Executables/functions/array_register";
11
- import twain_register from "./Executables/functions/twain_register";
12
- import price_register from "./Executables/functions/price_register";
13
- import folder_register from "./Executables/functions/folder_register";
14
- import chain_register from "./Executables/functions/servers/chain_register";
15
- import block_register from "./Executables/functions/servers/block_register";
16
- import account_register from "./Executables/functions/servers/account_register";
17
- import len from "./Executables/functions/len";
18
- import { get_address, get_id } from "./Executables/functions/utils";
19
- import adm_register from "./Executables/functions/adminstrator/adm_register";
20
-
21
- const callables = account => {
22
- let add_callable= account.vm.add_callable;
23
-
24
- chain_register(account)
25
- block_register(account)
26
- account_register(account)
27
- price_register(account)
28
- folder_register(account)
29
- string_register(account)
30
- array_register(account)
31
- twain_register(account)
32
- adm_register(account)
33
-
34
- add_callable('read_chain', {
35
- callable:(args, vm, options)=> {
36
- let res = account.vm.read_chain(args.address, args.options)
37
-
38
- if (typeof options.location === 'string'){
39
- vm.write_chain(res, options.location)
40
- }
41
- return res;
42
- },
43
- config: {
44
- parameters: [
45
- {name:'address', position:0,},
46
- {name: 'options', position:1}
47
- ]
48
- }
49
- })
50
-
51
-
52
- add_callable('air_object', {
53
- callable: (args, vm, options)=>{
54
- vm.air_object(args.literal, options)
55
- },
56
- config:{
57
- parameters: [
58
- {name:'literal', position:0,}
59
- ]
60
- }
61
- })
62
-
63
- add_callable('display', {
64
- callable: display,
65
- config: {
66
- parameters: [
67
- {name:'data', position:0, spread: true}
68
- ]
69
- }
70
- })
71
-
72
- add_callable('importcheck', {
73
- callable: importcheck,
74
- config: {
75
- parameters: [
76
- {name:'address', position:0},
77
- {name:'names', position:1, spread: true}
78
- ]
79
- }
80
- })
81
-
82
- add_callable('set_error_catch', {
83
- callable: set_error_catch,
84
- config: {
85
- parameters: [
86
- {name:'object', position:0},
87
- {name:'metadata', position:1},
88
- ]
89
- }
90
- })
91
-
92
- add_callable('set', {
93
- callable: set,
94
- config: {
95
- parameters: [
96
- {name:'obj', position:0, },
97
- {name:'prop', position:1, },
98
- {name:'value', position:2, },
99
- ]
100
- }
101
- })
102
-
103
- add_callable('get', {
104
- callable: get,
105
- config: {
106
- parameters: [
107
- {name:'obj', position:0, },
108
- {name:'prop', position:1, }
109
- ]
110
- }
111
- })
112
-
113
- add_callable('typecast', {
114
- callable: typecast,
115
- config: {
116
- parameters: [
117
- {name:'obj', position:0, },
118
- {name:'type', position:1, }
119
- ]
120
- }
121
- })
122
-
123
- add_callable('assign', {
124
- callable: assign,
125
- config: {
126
- parameters: [
127
- {name:'value', position:0, }
128
- ]
129
- }
130
- })
131
-
132
- add_callable('get_address', {
133
- callable: get_address,
134
- config: {
135
- parameters: [
136
- {name:'object', position:0, }
137
- ]
138
- }
139
- })
140
-
141
- add_callable('get_id', {
142
- callable: get_id,
143
- config: {
144
- parameters: [
145
- {name:'object', position:0, }
146
- ]
147
- }
148
- })
149
-
150
- add_callable('len', {
151
- callable: len,
152
- config: {
153
- parameters: [
154
- {name:'object', position:0, }
155
- ]
156
- }
157
- })
158
-
159
- ops.map(op=>{
160
- add_callable(`__${op.name}__`, {
161
- callable: (args, vm, options)=> operation(args, vm, {...options, op: op.name}),
162
- config: {
163
- parameters: [
164
- {name:'left', position:0},
165
- {name:'right', position:1}
166
- ]
167
- }
168
- })
169
- })
170
- }
171
-
172
- export default callables;