godprotocol 1.0.839 → 1.0.841
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 +17 -15
- package/Loader_sequence/main.js +292 -439
- package/Loader_sequence/repository.js +44 -27
- package/Objects/Account.js +237 -262
- package/Objects/Block.js +76 -77
- package/Objects/Blockweb.js +40 -36
- package/Objects/Chain.js +157 -162
- package/Objects/Explorer.js +47 -30
- package/Objects/Filesystem.js +82 -98
- package/Objects/Frame.js +48 -43
- package/Objects/Manager.js +108 -112
- package/Objects/Opcodes.js +44 -44
- package/Objects/Oracle.js +131 -91
- package/Objects/Virtual_machine.js +145 -145
- package/framer.js +35 -42
- package/opcodes/add.js +25 -9
- package/opcodes/indices.js +14 -15
- package/opcodes/jmp.js +12 -7
- package/opcodes/std.js +13 -7
- package/opcodes.js +58 -41
- package/package.json +3 -2
- package/utils/create_server.js +106 -71
- package/utils/functions.js +43 -31
- package/utils/hash.js +11 -10
- package/utils/privacy.js +15 -10
- package/utils/services.js +33 -32
|
@@ -1,32 +1,49 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
"use strict";
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
8
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
11
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
12
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
13
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
15
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
|
+
var Repository = /*#__PURE__*/_createClass(function Repository(main) {
|
|
17
|
+
var _this = this;
|
|
18
|
+
_classCallCheck(this, Repository);
|
|
19
|
+
_defineProperty(this, "add_program", function (config) {
|
|
20
|
+
var codes = config.codes.filter(function (line) {
|
|
21
|
+
return !!line.trim();
|
|
22
|
+
});
|
|
23
|
+
var code_hash = _this.oracle.hash(codes);
|
|
24
|
+
var code_exist = _this.codes.readone({
|
|
25
|
+
hash: code_hash
|
|
26
|
+
});
|
|
27
|
+
var code = _this.codes.write({
|
|
28
|
+
body: codes,
|
|
16
29
|
hash: code_hash,
|
|
17
|
-
_id: code_exist && code_exist._id
|
|
30
|
+
_id: code_exist && code_exist._id
|
|
18
31
|
});
|
|
19
32
|
config.codes = code._id;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.programs.write({
|
|
25
|
-
...config,
|
|
26
|
-
hash: program_hash,
|
|
27
|
-
_id: program_exist && program_exist._id,
|
|
33
|
+
var program_hash = _this.oracle.hash(JSON.stringify(config));
|
|
34
|
+
var program_exist = _this.programs.readone({
|
|
35
|
+
hash: program_hash
|
|
28
36
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
_this.programs.write(_objectSpread(_objectSpread({}, config), {}, {
|
|
38
|
+
hash: program_hash,
|
|
39
|
+
_id: program_exist && program_exist._id
|
|
40
|
+
}));
|
|
41
|
+
});
|
|
42
|
+
this.main = main;
|
|
43
|
+
this.oracle = this.main.account.manager.oracle;
|
|
44
|
+
this.gds = this.oracle.gds;
|
|
45
|
+
this.programs = this.gds.folder("programs");
|
|
46
|
+
this.codes = this.gds.folder("codes");
|
|
47
|
+
});
|
|
48
|
+
var _default = Repository;
|
|
49
|
+
exports["default"] = _default;
|
package/Objects/Account.js
CHANGED
|
@@ -1,282 +1,257 @@
|
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
let servers = this.privileges[endpoint];
|
|
58
|
-
|
|
59
|
-
if (data.exclusive) {
|
|
60
|
-
if (typeof data.exclusive === "boolean") return;
|
|
61
|
-
else if (Array.isArray(data.exclusive)) {
|
|
62
|
-
servers =
|
|
63
|
-
servers &&
|
|
64
|
-
servers.filter((serv) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _main = _interopRequireDefault(require("../Loader_sequence/main"));
|
|
8
|
+
var _privacy = _interopRequireDefault(require("../utils/privacy"));
|
|
9
|
+
var _services = require("../utils/services");
|
|
10
|
+
var _Filesystem2 = _interopRequireDefault(require("./Filesystem"));
|
|
11
|
+
var _Virtual_machine = _interopRequireDefault(require("./Virtual_machine"));
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
14
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
17
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
18
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
19
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
20
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
21
|
+
function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
|
|
22
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
23
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
24
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
25
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
26
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
27
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
28
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
29
|
+
var Account = /*#__PURE__*/function (_Filesystem) {
|
|
30
|
+
_inherits(Account, _Filesystem);
|
|
31
|
+
var _super = _createSuper(Account);
|
|
32
|
+
function Account(_name) {
|
|
33
|
+
var _this;
|
|
34
|
+
var _meta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
35
|
+
_classCallCheck(this, Account);
|
|
36
|
+
_this = _super.call(this);
|
|
37
|
+
_defineProperty(_assertThisInitialized(_this), "on", function (event, handler) {
|
|
38
|
+
var handlers = _this.events[event];
|
|
39
|
+
if (!handlers) {
|
|
40
|
+
handlers = new Array();
|
|
41
|
+
_this.events[event] = handlers;
|
|
42
|
+
}
|
|
43
|
+
handlers.push(handler);
|
|
44
|
+
});
|
|
45
|
+
_defineProperty(_assertThisInitialized(_this), "emit", function (event, data) {
|
|
46
|
+
var handlers = _this.events[event];
|
|
47
|
+
Array.isArray(handlers) && handlers.map(function (handle) {
|
|
48
|
+
return _this.run_callback(handle, data);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
_defineProperty(_assertThisInitialized(_this), "propagate", function (data, endpoint) {
|
|
52
|
+
if (data.is_propagated) return;
|
|
53
|
+
var servers = _this.privileges[endpoint];
|
|
54
|
+
if (data.exclusive) {
|
|
55
|
+
if (typeof data.exclusive === "boolean") return;else if (Array.isArray(data.exclusive)) {
|
|
56
|
+
servers = servers && servers.filter(function (serv) {
|
|
65
57
|
return data.exclusive.includes(serv.domain);
|
|
66
58
|
});
|
|
59
|
+
}
|
|
67
60
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
path: `/${endpoint}`,
|
|
79
|
-
},
|
|
80
|
-
data,
|
|
61
|
+
data.is_propagated = true;
|
|
62
|
+
data = JSON.stringify(data);
|
|
63
|
+
if (servers && servers.length) {
|
|
64
|
+
servers.map(function (serv) {
|
|
65
|
+
(0, _services.post_request)({
|
|
66
|
+
options: _objectSpread(_objectSpread({}, serv), {}, {
|
|
67
|
+
path: "/".concat(endpoint)
|
|
68
|
+
}),
|
|
69
|
+
data: data
|
|
70
|
+
});
|
|
81
71
|
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
add_server = ({ server, privileges }) => {
|
|
87
|
-
if (!Array.isArray(privileges) && privileges)
|
|
88
|
-
privileges = ["load", "parse", "run", "create_account"];
|
|
89
|
-
|
|
90
|
-
privileges.map((privilege) => {
|
|
91
|
-
let priv = this.privileges[privilege];
|
|
92
|
-
if (!priv) {
|
|
93
|
-
priv = [];
|
|
94
|
-
this.privileges[privilege] = priv;
|
|
95
72
|
}
|
|
96
|
-
if (!priv.find((serv) => serv.domain === server.domain))
|
|
97
|
-
priv.push(server);
|
|
98
73
|
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return call_session;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
buff = (block, pid) => {
|
|
113
|
-
let buffer = this.mine_buffer[pid];
|
|
114
|
-
if (!buffer) return;
|
|
115
|
-
|
|
116
|
-
buffer.blocks.push(block.stringify());
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
flush_buffer = (pid, payload) => {
|
|
120
|
-
let buff = this.mine_buffer[pid];
|
|
121
|
-
if (!buff) return;
|
|
122
|
-
|
|
123
|
-
buff.callback && this.run_callback(buff.callback, payload || buff.blocks);
|
|
124
|
-
delete this.mine_buffer[pid];
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
load = (payload) => {
|
|
128
|
-
let { program, callback } = payload;
|
|
129
|
-
let { instructions, assemble } = program;
|
|
130
|
-
|
|
131
|
-
this.propagate(payload, "load");
|
|
132
|
-
|
|
133
|
-
if (assemble) {
|
|
134
|
-
this.assembler.run(instructions, { cb: callback });
|
|
135
|
-
} else {
|
|
136
|
-
let pid = this.manage_buffer(callback);
|
|
137
|
-
|
|
138
|
-
this.manager.push({ sequence: instructions, account: this, pid });
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
parse = (program) => {
|
|
143
|
-
let { payload, callback, signature } = program;
|
|
144
|
-
|
|
145
|
-
this.propagate(program, "parse");
|
|
146
|
-
|
|
147
|
-
this.manager.oracle.fetch({ ...payload, signature }, (result) =>
|
|
148
|
-
this.run_callback(callback, result)
|
|
149
|
-
);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
run = (request) => {
|
|
153
|
-
let { payload, callback } = request;
|
|
154
|
-
|
|
155
|
-
let { physical_address, query, history } = payload;
|
|
156
|
-
|
|
157
|
-
history = Math.abs(Number(history)) || 0;
|
|
158
|
-
|
|
159
|
-
this.propagate(request, "run");
|
|
160
|
-
|
|
161
|
-
let pid = this.manage_buffer(callback);
|
|
162
|
-
|
|
163
|
-
let context = physical_address
|
|
164
|
-
? this.manager.web.get(physical_address)
|
|
165
|
-
: this.vm.get_context();
|
|
166
|
-
|
|
167
|
-
if (!context) {
|
|
168
|
-
if (physical_address)
|
|
169
|
-
context = this.manager.web.split_set(physical_address);
|
|
170
|
-
else return this.flush_buffer(pid);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
let blk = query ? context.explore(query) : context.get_latest_block();
|
|
174
|
-
|
|
175
|
-
if (!query) {
|
|
176
|
-
let index = context.height;
|
|
177
|
-
index -= 2;
|
|
178
|
-
|
|
179
|
-
if (blk && blk.metadata.program) {
|
|
180
|
-
if (history) {
|
|
181
|
-
history--;
|
|
182
|
-
blk = null;
|
|
74
|
+
_defineProperty(_assertThisInitialized(_this), "add_server", function (_ref) {
|
|
75
|
+
var server = _ref.server,
|
|
76
|
+
privileges = _ref.privileges;
|
|
77
|
+
if (!Array.isArray(privileges) && privileges) privileges = ["load", "parse", "run", "create_account"];
|
|
78
|
+
privileges.map(function (privilege) {
|
|
79
|
+
var priv = _this.privileges[privilege];
|
|
80
|
+
if (!priv) {
|
|
81
|
+
priv = [];
|
|
82
|
+
_this.privileges[privilege] = priv;
|
|
183
83
|
}
|
|
84
|
+
if (!priv.find(function (serv) {
|
|
85
|
+
return serv.domain === server.domain;
|
|
86
|
+
})) priv.push(server);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
_defineProperty(_assertThisInitialized(_this), "get_account", function (name) {
|
|
90
|
+
return _this.manager.get_account(name) || _assertThisInitialized(_this);
|
|
91
|
+
});
|
|
92
|
+
_defineProperty(_assertThisInitialized(_this), "manage_buffer", function (callback) {
|
|
93
|
+
var call_session = "".concat(Date.now(), "-").concat(Math.random());
|
|
94
|
+
_this.mine_buffer[call_session] = {
|
|
95
|
+
blocks: [],
|
|
96
|
+
callback: callback
|
|
97
|
+
};
|
|
98
|
+
return call_session;
|
|
99
|
+
});
|
|
100
|
+
_defineProperty(_assertThisInitialized(_this), "buff", function (block, pid) {
|
|
101
|
+
var buffer = _this.mine_buffer[pid];
|
|
102
|
+
if (!buffer) return;
|
|
103
|
+
buffer.blocks.push(block.stringify());
|
|
104
|
+
});
|
|
105
|
+
_defineProperty(_assertThisInitialized(_this), "flush_buffer", function (pid, payload) {
|
|
106
|
+
var buff = _this.mine_buffer[pid];
|
|
107
|
+
if (!buff) return;
|
|
108
|
+
buff.callback && _this.run_callback(buff.callback, payload || buff.blocks);
|
|
109
|
+
delete _this.mine_buffer[pid];
|
|
110
|
+
});
|
|
111
|
+
_defineProperty(_assertThisInitialized(_this), "load", function (payload) {
|
|
112
|
+
var program = payload.program,
|
|
113
|
+
callback = payload.callback;
|
|
114
|
+
var instructions = program.instructions,
|
|
115
|
+
assemble = program.assemble;
|
|
116
|
+
_this.propagate(payload, "load");
|
|
117
|
+
if (assemble) {
|
|
118
|
+
_this.assembler.spawn().run(instructions, {
|
|
119
|
+
cb: callback
|
|
120
|
+
});
|
|
121
|
+
} else {
|
|
122
|
+
var pid = _this.manage_buffer(callback);
|
|
123
|
+
_this.manager.push({
|
|
124
|
+
sequence: instructions,
|
|
125
|
+
account: _assertThisInitialized(_this),
|
|
126
|
+
pid: pid
|
|
127
|
+
});
|
|
184
128
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
129
|
+
});
|
|
130
|
+
_defineProperty(_assertThisInitialized(_this), "parse", function (program) {
|
|
131
|
+
var payload = program.payload,
|
|
132
|
+
callback = program.callback,
|
|
133
|
+
signature = program.signature;
|
|
134
|
+
_this.propagate(program, "parse");
|
|
135
|
+
_this.manager.oracle.fetch(_objectSpread(_objectSpread({}, payload), {}, {
|
|
136
|
+
signature: signature
|
|
137
|
+
}), function (result) {
|
|
138
|
+
return _this.run_callback(callback, result);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
_defineProperty(_assertThisInitialized(_this), "run", function (request) {
|
|
142
|
+
var payload = request.payload,
|
|
143
|
+
callback = request.callback;
|
|
144
|
+
var physical_address = payload.physical_address,
|
|
145
|
+
query = payload.query,
|
|
146
|
+
history = payload.history;
|
|
147
|
+
history = Math.abs(Number(history)) || 0;
|
|
148
|
+
_this.propagate(request, "run");
|
|
149
|
+
var pid = _this.manage_buffer(callback);
|
|
150
|
+
var context = physical_address ? _this.manager.web.get(physical_address) : _this.vm.get_context();
|
|
151
|
+
if (!context) {
|
|
152
|
+
if (physical_address) context = _this.manager.web.split_set(physical_address);else return _this.flush_buffer(pid);
|
|
153
|
+
}
|
|
154
|
+
var blk = query ? context.explore(query) : context.get_latest_block();
|
|
155
|
+
if (!query) {
|
|
156
|
+
var index = context.height;
|
|
157
|
+
index -= 2;
|
|
190
158
|
if (blk && blk.metadata.program) {
|
|
191
159
|
if (history) {
|
|
192
160
|
history--;
|
|
193
161
|
blk = null;
|
|
194
162
|
}
|
|
195
163
|
}
|
|
164
|
+
while (!blk && index >= 0) {
|
|
165
|
+
index--;
|
|
166
|
+
blk = context.get_block(index);
|
|
167
|
+
if (blk && blk.metadata.program) {
|
|
168
|
+
if (history) {
|
|
169
|
+
history--;
|
|
170
|
+
blk = null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
196
174
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
this.vm.contexts.push(context);
|
|
203
|
-
program.push("pop");
|
|
204
|
-
|
|
205
|
-
Array.isArray(program) &&
|
|
206
|
-
program.length &&
|
|
207
|
-
this.manager.push({
|
|
175
|
+
if (blk && blk.metadata && blk.metadata.program) {
|
|
176
|
+
var program = _this.read(blk.metadata.program);
|
|
177
|
+
_this.vm.contexts.push(context);
|
|
178
|
+
program.push("pop");
|
|
179
|
+
Array.isArray(program) && program.length && _this.manager.push({
|
|
208
180
|
sequence: program,
|
|
209
|
-
account:
|
|
210
|
-
pid
|
|
181
|
+
account: _assertThisInitialized(_this),
|
|
182
|
+
pid: pid
|
|
211
183
|
});
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return;
|
|
232
|
-
|
|
233
|
-
for (let s = 0; s < this.stdout.length; s++) {
|
|
234
|
-
let out = this.stdout[s];
|
|
235
|
-
if (out.pid === this.vm.track.pid) {
|
|
236
|
-
block.metadata.stdout.push(out.data);
|
|
237
|
-
this.stdout[s] = null;
|
|
184
|
+
} else _this.flush_buffer(pid);
|
|
185
|
+
});
|
|
186
|
+
_defineProperty(_assertThisInitialized(_this), "run_callback", function (callback, payload) {
|
|
187
|
+
setTimeout(function () {
|
|
188
|
+
if (!callback) return;
|
|
189
|
+
if (typeof callback === "function") return callback(payload);
|
|
190
|
+
callback.payload && callback.payload.physical_address && _this.vm.stdin(payload, function () {
|
|
191
|
+
return _this.run(callback);
|
|
192
|
+
});
|
|
193
|
+
}, 0);
|
|
194
|
+
});
|
|
195
|
+
_defineProperty(_assertThisInitialized(_this), "flush_stdout", function (block) {
|
|
196
|
+
if (block.chain.physical_address === "".concat(_this.physical_address, "/Opcodes/stdout")) return;
|
|
197
|
+
for (var s = 0; s < _this.stdout.length; s++) {
|
|
198
|
+
var out = _this.stdout[s];
|
|
199
|
+
if (out.pid === _this.vm.track.pid) {
|
|
200
|
+
block.metadata.stdout.push(out.data);
|
|
201
|
+
_this.stdout[s] = null;
|
|
202
|
+
}
|
|
238
203
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
JSON.stringify(payload),
|
|
249
|
-
signature
|
|
250
|
-
);
|
|
251
|
-
if (!valid && callback)
|
|
252
|
-
this.run_callback(callback, {
|
|
253
|
-
private: this.private,
|
|
204
|
+
_this.stdout = _this.stdout.filter(function (out) {
|
|
205
|
+
return !!out;
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
_defineProperty(_assertThisInitialized(_this), "validate", function (payload, signature, callback) {
|
|
209
|
+
if (!_this["private"]) return true;
|
|
210
|
+
var valid = (0, _privacy["default"])(_this.name, JSON.stringify(payload), signature);
|
|
211
|
+
if (!valid && callback) _this.run_callback(callback, {
|
|
212
|
+
"private": _this["private"],
|
|
254
213
|
error: true,
|
|
255
|
-
error_message: "Invalid signature"
|
|
214
|
+
error_message: "Invalid signature"
|
|
256
215
|
});
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
216
|
+
return valid;
|
|
217
|
+
});
|
|
218
|
+
_defineProperty(_assertThisInitialized(_this), "stringify", function (str) {
|
|
219
|
+
var obj = {};
|
|
220
|
+
obj.name = _this.name;
|
|
221
|
+
obj.hash = _this.hash;
|
|
222
|
+
obj.path = _this.path;
|
|
223
|
+
obj["private"] = _this["private"];
|
|
224
|
+
obj.chain = _this.chain.stringify();
|
|
225
|
+
obj.physical_address = _this.physical_address;
|
|
226
|
+
return str ? JSON.stringify(obj) : obj;
|
|
227
|
+
});
|
|
228
|
+
_defineProperty(_assertThisInitialized(_this), "create_account", function (payload) {
|
|
229
|
+
_this.propagate(payload, "create_account");
|
|
230
|
+
var name = payload.name,
|
|
231
|
+
meta = payload.meta;
|
|
232
|
+
return _this.manager.add_account(name, meta);
|
|
233
|
+
});
|
|
234
|
+
_meta = _meta || {};
|
|
235
|
+
_this.name = _name;
|
|
236
|
+
_this["private"] = _meta["private"];
|
|
237
|
+
_this.manager = _meta.manager;
|
|
238
|
+
_this.account = _assertThisInitialized(_this);
|
|
239
|
+
_this.stdin = new Array();
|
|
240
|
+
_this.stdout = new Array();
|
|
241
|
+
if (!_this.manager) throw new Error("Manager instance missing.");
|
|
242
|
+
_this.name_hash();
|
|
243
|
+
_this.physical_address = "".concat(_this.base_address, "/").concat(_this.name);
|
|
244
|
+
_this.set_paths(_assertThisInitialized(_this));
|
|
245
|
+
_this.assembler = new _main["default"](_assertThisInitialized(_this));
|
|
246
|
+
_this.chain = _this.account_chain(_assertThisInitialized(_this));
|
|
247
|
+
_this.vm = new _Virtual_machine["default"](_this.chain);
|
|
248
|
+
_this.mine_buffer = {};
|
|
249
|
+
_this.privileges = new Object();
|
|
250
|
+
_this.events = new Object();
|
|
251
|
+
console.log("Account Instance: ".concat(_this.name));
|
|
252
|
+
return _this;
|
|
253
|
+
}
|
|
254
|
+
return _createClass(Account);
|
|
255
|
+
}(_Filesystem2["default"]);
|
|
256
|
+
var _default = Account;
|
|
257
|
+
exports["default"] = _default;
|