godprotocol 1.0.841 → 1.0.842
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.
- package/Index.js +15 -17
- package/Loader_sequence/main.js +447 -292
- package/Loader_sequence/repository.js +27 -43
- package/Objects/Account.js +262 -237
- package/Objects/Block.js +78 -76
- package/Objects/Blockweb.js +36 -40
- package/Objects/Chain.js +164 -157
- package/Objects/Explorer.js +36 -39
- package/Objects/Filesystem.js +99 -82
- package/Objects/Frame.js +43 -48
- package/Objects/Manager.js +115 -108
- package/Objects/Opcodes.js +44 -44
- package/Objects/Oracle.js +93 -129
- package/Objects/Virtual_machine.js +145 -145
- package/framer.js +42 -35
- package/opcodes/add.js +9 -25
- package/opcodes/indices.js +15 -14
- package/opcodes/jmp.js +7 -12
- package/opcodes/std.js +7 -13
- package/opcodes.js +41 -58
- package/package.json +2 -3
- package/utils/create_server.js +71 -106
- package/utils/functions.js +31 -43
- package/utils/hash.js +10 -11
- package/utils/privacy.js +10 -15
- package/utils/services.js +32 -33
package/Objects/Manager.js
CHANGED
|
@@ -1,139 +1,146 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
servers: _this.servers
|
|
1
|
+
import { _id } from "generalised-datastore/utils/functions";
|
|
2
|
+
import framer from "../framer";
|
|
3
|
+
import opcodes from "../opcodes";
|
|
4
|
+
import Account from "./Account";
|
|
5
|
+
import Blockweb from "./Blockweb";
|
|
6
|
+
import Oracle from "./Oracle";
|
|
7
|
+
|
|
8
|
+
class Manager {
|
|
9
|
+
constructor(meta) {
|
|
10
|
+
meta = meta || {};
|
|
11
|
+
|
|
12
|
+
this.compression = meta.compression;
|
|
13
|
+
this.manager_id = _id("manager");
|
|
14
|
+
this.accounts = new Object();
|
|
15
|
+
this.running = 0;
|
|
16
|
+
this.tracks = new Object();
|
|
17
|
+
this.web = new Blockweb(this);
|
|
18
|
+
this.oracle = new Oracle(this, {
|
|
19
|
+
compression: this.compression,
|
|
20
|
+
datastore: meta.datastore,
|
|
21
|
+
});
|
|
22
|
+
this.servers = new Array();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
stringify = (str) => {
|
|
26
|
+
let obj = {
|
|
27
|
+
_id: this.manager_id,
|
|
28
|
+
servers: this.servers,
|
|
30
29
|
};
|
|
30
|
+
|
|
31
31
|
return str ? JSON.stringify(obj) : obj;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
initiate = (meta) => {
|
|
35
|
+
this.initiator = this.add_account(
|
|
36
|
+
process.env.INITIATOR || "initiator",
|
|
37
|
+
meta
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return this.initiator;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
start_clock = () => {
|
|
44
|
+
let frequency = Number(process.env.HERTS) || 10;
|
|
45
|
+
this.clock = setInterval(() => {
|
|
46
|
+
for (let account in this.tracks) {
|
|
47
|
+
let track = this.tracks[account];
|
|
48
|
+
let program = track.slice(-1)[0];
|
|
49
|
+
|
|
43
50
|
if (program.hold) continue;
|
|
44
|
-
|
|
51
|
+
|
|
52
|
+
let instruction = program.sequence[program.pointer];
|
|
53
|
+
|
|
45
54
|
program.account.vm.execute(instruction, program);
|
|
46
55
|
program.pointer++;
|
|
56
|
+
|
|
47
57
|
if (program.pointer === program.sequence.length) {
|
|
48
58
|
program.account.flush_buffer(program.pid);
|
|
59
|
+
|
|
49
60
|
track.pop();
|
|
50
61
|
}
|
|
51
62
|
if (!track.length) {
|
|
52
|
-
|
|
53
|
-
delete
|
|
63
|
+
this.running -= 1;
|
|
64
|
+
delete this.tracks[account];
|
|
54
65
|
program.account.chain.mine(program.account.vm);
|
|
55
66
|
}
|
|
56
67
|
}
|
|
57
|
-
|
|
68
|
+
|
|
69
|
+
!this.running && clearInterval(this.clock);
|
|
58
70
|
}, frequency);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
get_account = (name) => this.accounts[name];
|
|
74
|
+
|
|
75
|
+
add_account = (name, meta) => {
|
|
64
76
|
meta = meta || {};
|
|
65
77
|
if (!name) name = meta.name;
|
|
66
|
-
|
|
78
|
+
|
|
79
|
+
let account;
|
|
67
80
|
if (!name) {
|
|
68
|
-
account = {
|
|
69
|
-
error: true,
|
|
70
|
-
error_message: "Name cannot be blank"
|
|
71
|
-
};
|
|
81
|
+
account = { error: true, error_message: "Name cannot be blank" };
|
|
72
82
|
} else {
|
|
73
|
-
account =
|
|
83
|
+
account = this.get_account(name);
|
|
84
|
+
|
|
74
85
|
if (!account) {
|
|
75
|
-
account = new
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
(
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
account = new Account(name, { ...meta, manager: this });
|
|
87
|
+
|
|
88
|
+
opcodes(account);
|
|
89
|
+
framer(account, meta.on_framed);
|
|
90
|
+
|
|
91
|
+
this.accounts[account.name] = account;
|
|
81
92
|
if (meta.string) account = account.stringify();
|
|
82
|
-
} else if (meta && meta
|
|
83
|
-
account
|
|
93
|
+
} else if (meta && meta.private && !account.private) {
|
|
94
|
+
account.private = true;
|
|
84
95
|
}
|
|
85
96
|
}
|
|
97
|
+
|
|
86
98
|
return meta.string ? JSON.stringify(account) : account;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
push = (program) => {
|
|
102
|
+
let track = this.tracks[program.account.name];
|
|
103
|
+
|
|
90
104
|
if (track) {
|
|
91
|
-
track.push(
|
|
92
|
-
pointer: 0
|
|
93
|
-
}));
|
|
105
|
+
track.push({ ...program, pointer: 0 });
|
|
94
106
|
} else {
|
|
95
|
-
track = [
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
_this.running === 1 && _this.start_clock();
|
|
107
|
+
track = [{ ...program, pointer: 0 }];
|
|
108
|
+
this.tracks[program.account.name] = track;
|
|
109
|
+
|
|
110
|
+
this.running++;
|
|
111
|
+
this.running === 1 && this.start_clock();
|
|
101
112
|
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
get_initiator = () => this.initiator || this.initiate();
|
|
116
|
+
|
|
117
|
+
endpoint = (endpoint, payload, callback) => {
|
|
118
|
+
let account = this.get_account(payload.account);
|
|
108
119
|
if (!account) {
|
|
109
|
-
return
|
|
120
|
+
return this.get_initiator().run_callback(callback, {
|
|
110
121
|
error: true,
|
|
111
122
|
error_message: "Account is not found",
|
|
112
|
-
payload
|
|
113
|
-
endpoint
|
|
123
|
+
payload,
|
|
124
|
+
endpoint,
|
|
114
125
|
});
|
|
115
126
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
this.servers = new Array();
|
|
137
|
-
});
|
|
138
|
-
var _default = Manager;
|
|
139
|
-
exports["default"] = _default;
|
|
127
|
+
|
|
128
|
+
if (
|
|
129
|
+
!account.validate(
|
|
130
|
+
payload.program || payload.payload,
|
|
131
|
+
payload.signature,
|
|
132
|
+
callback || payload.callback
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
return;
|
|
136
|
+
|
|
137
|
+
let method = account[endpoint];
|
|
138
|
+
typeof method === "function" && method({ ...payload, callback });
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
add_server = (server) => {
|
|
142
|
+
this.servers.push(server);
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export default Manager;
|
package/Objects/Opcodes.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
_defineProperty(this, "set", function (opcode, circuit) {
|
|
19
|
-
_this.opcodes[opcode] = circuit;
|
|
20
|
-
_framer.obj.Opcodes[opcode] = null;
|
|
21
|
-
_this.account.assembler.opcodes.push(opcode);
|
|
22
|
-
});
|
|
23
|
-
_defineProperty(this, "prepare_operation", function (opcode, context) {
|
|
24
|
-
var circ = _this.opcodes[opcode];
|
|
1
|
+
import { obj } from "../framer";
|
|
2
|
+
|
|
3
|
+
class Opcodes {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.opcodes = new Object();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
set = (opcode, circuit) => {
|
|
9
|
+
this.opcodes[opcode] = circuit;
|
|
10
|
+
obj.Opcodes[opcode] = null;
|
|
11
|
+
|
|
12
|
+
this.account.assembler.opcodes.push(opcode);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
prepare_operation = (opcode, context) => {
|
|
16
|
+
let circ = this.opcodes[opcode];
|
|
17
|
+
|
|
25
18
|
if (typeof circ !== "function") return;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
|
|
20
|
+
let buf = context.get_buffer();
|
|
21
|
+
|
|
22
|
+
let args =
|
|
23
|
+
context.account.read(buf && buf.inputs) ||
|
|
24
|
+
this.account.stdin.splice(-1)[0];
|
|
25
|
+
|
|
26
|
+
let res = circ(args, this);
|
|
27
|
+
|
|
28
|
+
this.stdin(res);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
stdin = (object, cb) => {
|
|
32
32
|
if (object == null) {
|
|
33
|
-
|
|
33
|
+
this.flags.void = true;
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
this.flags.void = false;
|
|
37
|
+
|
|
38
|
+
this.flags.zero = !object;
|
|
39
|
+
if (typeof object === "number") this.flags.neg = object < 0;
|
|
40
|
+
|
|
41
|
+
let code_string =
|
|
42
|
+
typeof object !== "string" ? JSON.stringify(object) : object;
|
|
43
|
+
|
|
44
|
+
this.account.assembler.run(code_string, { cb, pure: true });
|
|
44
45
|
// console.log(`Writing in: ${code_string}`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
exports["default"] = _default;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default Opcodes;
|
package/Objects/Oracle.js
CHANGED
|
@@ -1,144 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
_classCallCheck(this, Oracle);
|
|
24
|
-
_defineProperty(this, "get_folder", function (physical_address, options) {
|
|
25
|
-
if (_typeof(options) !== "object") {
|
|
26
|
-
options = {
|
|
27
|
-
no_new: options ? false : true
|
|
28
|
-
};
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import GDS from "generalised-datastore";
|
|
3
|
+
import { hash } from "../utils/hash";
|
|
4
|
+
|
|
5
|
+
class Oracle {
|
|
6
|
+
constructor(mgr, meta) {
|
|
7
|
+
meta = meta || {};
|
|
8
|
+
|
|
9
|
+
this.compression = meta.compression;
|
|
10
|
+
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
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get_folder = (physical_address, options) => {
|
|
21
|
+
if (typeof options !== "object") {
|
|
22
|
+
options = { no_new: options ? false : true };
|
|
29
23
|
}
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
type: type
|
|
24
|
+
return this.gds.folder(this.hash(physical_address));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
set = (path, { type, obj }) => {
|
|
28
|
+
this.datapaths[path] = {
|
|
29
|
+
obj,
|
|
30
|
+
type,
|
|
38
31
|
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
get = (path) => {
|
|
35
|
+
let obj = this.datapaths[path];
|
|
36
|
+
|
|
42
37
|
if (!obj) {
|
|
43
38
|
try {
|
|
44
|
-
obj =
|
|
39
|
+
obj = this.fs.readFileSync(`${this.mgr.initiator.root}/${path}`);
|
|
45
40
|
obj = JSON.parse(obj).payload;
|
|
46
|
-
|
|
47
|
-
type =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
_this.set(path, obj);
|
|
41
|
+
let type = obj && obj.payload && typeof obj.payload;
|
|
42
|
+
type =
|
|
43
|
+
type === "object" ? (Array.isArray(obj) ? "array" : "twain") : type;
|
|
44
|
+
|
|
45
|
+
obj = { type, obj };
|
|
46
|
+
this.set(path, obj);
|
|
53
47
|
} catch (e) {}
|
|
54
48
|
}
|
|
49
|
+
|
|
55
50
|
return obj;
|
|
56
|
-
}
|
|
57
|
-
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
hash = (data) => {
|
|
58
54
|
data = typeof data !== "string" ? JSON.stringify(data) : data;
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (_this.compression) {
|
|
66
|
-
var res = _this.compression({
|
|
67
|
-
addr: addr,
|
|
68
|
-
data: data,
|
|
69
|
-
no_string: no_string
|
|
70
|
-
});
|
|
55
|
+
return hash(data);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
handle_compression = ({ addr, data, no_string }) => {
|
|
59
|
+
if (this.compression) {
|
|
60
|
+
let res = this.compression({ addr, data, no_string });
|
|
71
61
|
if (res) data = res.data;
|
|
72
62
|
}
|
|
73
|
-
if (!no_string && (typeof addr !== "string" || typeof data !== "string"))
|
|
63
|
+
if (!no_string && (typeof addr !== "string" || typeof data !== "string"))
|
|
64
|
+
return;
|
|
65
|
+
|
|
74
66
|
return data;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
var data = _this.handle_compression({
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
write = (address, payload) => {
|
|
70
|
+
payload = JSON.stringify({ payload });
|
|
71
|
+
let data = this.handle_compression({
|
|
81
72
|
addr: address,
|
|
82
|
-
data: payload
|
|
73
|
+
data: payload,
|
|
83
74
|
});
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
|
|
76
|
+
this.fs.writeFileSync(`${this.mgr.initiator.root}/${address}`, data, {
|
|
77
|
+
encoding: "utf-8",
|
|
86
78
|
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
_context.next = 14;
|
|
118
|
-
return op(query.query, query.options);
|
|
119
|
-
case 14:
|
|
120
|
-
result = _context.sent;
|
|
121
|
-
folder.remote_stuff(remote, result);
|
|
122
|
-
case 16:
|
|
123
|
-
callback(result);
|
|
124
|
-
case 17:
|
|
125
|
-
case "end":
|
|
126
|
-
return _context.stop();
|
|
127
|
-
}
|
|
128
|
-
}, _callee);
|
|
129
|
-
}));
|
|
130
|
-
return function (_x, _x2) {
|
|
131
|
-
return _ref3.apply(this, arguments);
|
|
132
|
-
};
|
|
133
|
-
}());
|
|
134
|
-
meta = meta || {};
|
|
135
|
-
this.compression = meta.compression;
|
|
136
|
-
this.fs = _fs["default"];
|
|
137
|
-
this.mgr = mgr;
|
|
138
|
-
this.datapaths = new Object();
|
|
139
|
-
this.gds = new _generalisedDatastore["default"](meta.datastore || process.env.DATASTORE || "godprotocol").sync({
|
|
140
|
-
manager: this.mgr
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
var _default = Oracle;
|
|
144
|
-
exports["default"] = _default;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
fetch = async (payload, callback) => {
|
|
82
|
+
let { physical_address, config, remote, query } = payload,
|
|
83
|
+
result;
|
|
84
|
+
|
|
85
|
+
let folder = this.get_folder(physical_address);
|
|
86
|
+
|
|
87
|
+
if (config) {
|
|
88
|
+
result = folder.config.stringify();
|
|
89
|
+
folder.add_remote(remote);
|
|
90
|
+
} else {
|
|
91
|
+
if (!folder.check_remote(query.operation)) {
|
|
92
|
+
result = {
|
|
93
|
+
error: true,
|
|
94
|
+
error_message: "Query operation cannot be performed remotely.",
|
|
95
|
+
};
|
|
96
|
+
} else {
|
|
97
|
+
let op = folder[query.operation];
|
|
98
|
+
|
|
99
|
+
result = await op(query.query, query.options);
|
|
100
|
+
folder.remote_stuff(remote, result);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
callback(result);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export default Oracle;
|