godprotocol 1.0.788 → 1.0.791
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/Objects/Account.js +260 -80
- package/Objects/Manager.js +2 -3
- package/Objects/Opcodes.js +75 -12
- package/Objects/Virtual_machine.js +242 -105
- package/build/Account.js +173 -0
- package/build/Block.js +103 -0
- package/build/Blockweb.js +78 -0
- package/build/Chain.js +205 -0
- package/build/Explorer.js +85 -0
- package/build/Filesystem.js +165 -0
- package/build/Frame.js +108 -0
- package/build/Index.js +19 -0
- package/build/Manager.js +178 -0
- package/build/Opcodes.js +102 -0
- package/build/Oracle.js +84 -0
- package/build/Virtual_machine.js +128 -0
- package/build/add.js +41 -0
- package/build/create_server.js +495 -0
- package/build/framer.js +88 -0
- package/build/functions.js +127 -0
- package/build/hash.js +14 -0
- package/build/jmp.js +19 -0
- package/build/main.js +339 -0
- package/build/opcodes.js +42 -0
- package/build/privacy.js +27 -0
- package/build/services.js +96 -0
- package/build/std.js +11 -0
- package/package.json +1 -1
- package/readme.md +94 -71
|
@@ -1,128 +1,265 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
4
|
+
value: true,
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _Opcodes2 = _interopRequireDefault(require("./Opcodes"));
|
|
8
|
-
function _interopRequireDefault(e) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
function _interopRequireDefault(e) {
|
|
9
|
+
return e && e.__esModule ? e : { default: e };
|
|
10
|
+
}
|
|
11
|
+
function _typeof(o) {
|
|
12
|
+
"@babel/helpers - typeof";
|
|
13
|
+
return (
|
|
14
|
+
(_typeof =
|
|
15
|
+
"function" == typeof Symbol && "symbol" == typeof Symbol.iterator
|
|
16
|
+
? function (o) {
|
|
17
|
+
return typeof o;
|
|
18
|
+
}
|
|
19
|
+
: function (o) {
|
|
20
|
+
return o &&
|
|
21
|
+
"function" == typeof Symbol &&
|
|
22
|
+
o.constructor === Symbol &&
|
|
23
|
+
o !== Symbol.prototype
|
|
24
|
+
? "symbol"
|
|
25
|
+
: typeof o;
|
|
26
|
+
}),
|
|
27
|
+
_typeof(o)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
function _defineProperties(e, r) {
|
|
31
|
+
for (var t = 0; t < r.length; t++) {
|
|
32
|
+
var o = r[t];
|
|
33
|
+
(o.enumerable = o.enumerable || !1),
|
|
34
|
+
(o.configurable = !0),
|
|
35
|
+
"value" in o && (o.writable = !0),
|
|
36
|
+
Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function _createClass(e, r, t) {
|
|
40
|
+
return (
|
|
41
|
+
r && _defineProperties(e.prototype, r),
|
|
42
|
+
t && _defineProperties(e, t),
|
|
43
|
+
Object.defineProperty(e, "prototype", { writable: !1 }),
|
|
44
|
+
e
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
function _classCallCheck(a, n) {
|
|
48
|
+
if (!(a instanceof n))
|
|
49
|
+
throw new TypeError("Cannot call a class as a function");
|
|
50
|
+
}
|
|
51
|
+
function _inherits(t, e) {
|
|
52
|
+
if ("function" != typeof e && null !== e)
|
|
53
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
54
|
+
(t.prototype = Object.create(e && e.prototype, {
|
|
55
|
+
constructor: { value: t, writable: !0, configurable: !0 },
|
|
56
|
+
})),
|
|
57
|
+
Object.defineProperty(t, "prototype", { writable: !1 }),
|
|
58
|
+
e && _setPrototypeOf(t, e);
|
|
59
|
+
}
|
|
60
|
+
function _setPrototypeOf(t, e) {
|
|
61
|
+
return (
|
|
62
|
+
(_setPrototypeOf = Object.setPrototypeOf
|
|
63
|
+
? Object.setPrototypeOf.bind()
|
|
64
|
+
: function (t, e) {
|
|
65
|
+
return (t.__proto__ = e), t;
|
|
66
|
+
}),
|
|
67
|
+
_setPrototypeOf(t, e)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
function _createSuper(t) {
|
|
71
|
+
var r = _isNativeReflectConstruct();
|
|
72
|
+
return function () {
|
|
73
|
+
var e,
|
|
74
|
+
o = _getPrototypeOf(t);
|
|
75
|
+
if (r) {
|
|
76
|
+
var s = _getPrototypeOf(this).constructor;
|
|
77
|
+
e = Reflect.construct(o, arguments, s);
|
|
78
|
+
} else e = o.apply(this, arguments);
|
|
79
|
+
return _possibleConstructorReturn(this, e);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function _possibleConstructorReturn(t, e) {
|
|
83
|
+
if (e && ("object" == _typeof(e) || "function" == typeof e)) return e;
|
|
84
|
+
if (void 0 !== e)
|
|
85
|
+
throw new TypeError(
|
|
86
|
+
"Derived constructors may only return object or undefined"
|
|
87
|
+
);
|
|
88
|
+
return _assertThisInitialized(t);
|
|
89
|
+
}
|
|
90
|
+
function _assertThisInitialized(e) {
|
|
91
|
+
if (void 0 === e)
|
|
92
|
+
throw new ReferenceError(
|
|
93
|
+
"this hasn't been initialised - super() hasn't been called"
|
|
94
|
+
);
|
|
95
|
+
return e;
|
|
96
|
+
}
|
|
97
|
+
function _isNativeReflectConstruct() {
|
|
98
|
+
try {
|
|
99
|
+
var t = !Boolean.prototype.valueOf.call(
|
|
100
|
+
Reflect.construct(Boolean, [], function () {})
|
|
101
|
+
);
|
|
102
|
+
} catch (t) {}
|
|
103
|
+
return (_isNativeReflectConstruct = function _isNativeReflectConstruct() {
|
|
104
|
+
return !!t;
|
|
105
|
+
})();
|
|
106
|
+
}
|
|
107
|
+
function _getPrototypeOf(t) {
|
|
108
|
+
return (
|
|
109
|
+
(_getPrototypeOf = Object.setPrototypeOf
|
|
110
|
+
? Object.getPrototypeOf.bind()
|
|
111
|
+
: function (t) {
|
|
112
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
113
|
+
}),
|
|
114
|
+
_getPrototypeOf(t)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
function _defineProperty(e, r, t) {
|
|
118
|
+
return (
|
|
119
|
+
(r = _toPropertyKey(r)) in e
|
|
120
|
+
? Object.defineProperty(e, r, {
|
|
121
|
+
value: t,
|
|
122
|
+
enumerable: !0,
|
|
123
|
+
configurable: !0,
|
|
124
|
+
writable: !0,
|
|
125
|
+
})
|
|
126
|
+
: (e[r] = t),
|
|
127
|
+
e
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
function _toPropertyKey(t) {
|
|
131
|
+
var i = _toPrimitive(t, "string");
|
|
132
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
133
|
+
}
|
|
134
|
+
function _toPrimitive(t, r) {
|
|
135
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
136
|
+
var e = t[Symbol.toPrimitive];
|
|
137
|
+
if (void 0 !== e) {
|
|
138
|
+
var i = e.call(t, r || "default");
|
|
139
|
+
if ("object" != _typeof(i)) return i;
|
|
140
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
141
|
+
}
|
|
142
|
+
return ("string" === r ? String : Number)(t);
|
|
143
|
+
}
|
|
144
|
+
var Virtual_machine = /*#__PURE__*/ (function (_Opcodes) {
|
|
24
145
|
_inherits(Virtual_machine, _Opcodes);
|
|
25
146
|
var _super = _createSuper(Virtual_machine);
|
|
26
147
|
function Virtual_machine(_context) {
|
|
27
148
|
var _this;
|
|
28
149
|
_classCallCheck(this, Virtual_machine);
|
|
29
150
|
_this = _super.call(this);
|
|
30
|
-
_defineProperty(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var args = arg.split("/"),
|
|
36
|
-
i = 0;
|
|
37
|
-
while (args[0] === "..") {
|
|
38
|
-
i++;
|
|
39
|
-
args.splice(0, 1);
|
|
151
|
+
_defineProperty(
|
|
152
|
+
_assertThisInitialized(_this),
|
|
153
|
+
"get_context",
|
|
154
|
+
function (index) {
|
|
155
|
+
return _this.contexts.slice(index == null ? -1 : index)[0];
|
|
40
156
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
157
|
+
);
|
|
158
|
+
_defineProperty(
|
|
159
|
+
_assertThisInitialized(_this),
|
|
160
|
+
"parse_arg",
|
|
161
|
+
function (arg, is_cursor) {
|
|
162
|
+
var context = _this.get_context();
|
|
163
|
+
var args = arg.split("/"),
|
|
164
|
+
i = 0;
|
|
165
|
+
while (args[0] === "..") {
|
|
166
|
+
i++;
|
|
167
|
+
args.splice(0, 1);
|
|
168
|
+
}
|
|
169
|
+
i = (i + 1) * -1;
|
|
170
|
+
context = i ? _this.get_context(i) : context;
|
|
171
|
+
arg = args.join("/");
|
|
172
|
+
while (arg.includes("^")) {
|
|
173
|
+
var blk = context.connections.slice(-1)[0];
|
|
174
|
+
if (!blk) break;
|
|
175
|
+
context = blk.chain;
|
|
176
|
+
var _i = arg.indexOf("^");
|
|
177
|
+
arg = "".concat(arg.slice(0, _i)).concat(arg.slice(_i + 1));
|
|
178
|
+
}
|
|
179
|
+
if (arg.startsWith("{*") && is_cursor) {
|
|
180
|
+
arg = context.explore(arg.slice(2, -1));
|
|
181
|
+
} else if (arg.startsWith("{") && !is_cursor) {
|
|
182
|
+
arg = context.explore(arg.slice(1, -1));
|
|
183
|
+
}
|
|
184
|
+
return arg;
|
|
50
185
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
186
|
+
);
|
|
187
|
+
_defineProperty(
|
|
188
|
+
_assertThisInitialized(_this),
|
|
189
|
+
"split_instruction",
|
|
190
|
+
function (instruction) {
|
|
191
|
+
var split = instruction.split(" ");
|
|
192
|
+
var opcode = split[0],
|
|
193
|
+
args = split.slice(1).join(" ");
|
|
194
|
+
return {
|
|
195
|
+
opcode: opcode,
|
|
196
|
+
args: args,
|
|
197
|
+
};
|
|
55
198
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
opcode
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
case "write":
|
|
113
|
-
context.account.write(args, context);
|
|
114
|
-
break;
|
|
115
|
-
default:
|
|
116
|
-
_this.prepare_operation(opcode, context);
|
|
117
|
-
break;
|
|
199
|
+
);
|
|
200
|
+
_defineProperty(
|
|
201
|
+
_assertThisInitialized(_this),
|
|
202
|
+
"execute",
|
|
203
|
+
function (instruction, track) {
|
|
204
|
+
_this.track = track;
|
|
205
|
+
if (!instruction) return;
|
|
206
|
+
var _this$split_instructi = _this.split_instruction(instruction),
|
|
207
|
+
opcode = _this$split_instructi.opcode,
|
|
208
|
+
args = _this$split_instructi.args;
|
|
209
|
+
var context = _this.get_context();
|
|
210
|
+
if (!context) return;
|
|
211
|
+
context.add_tx(instruction);
|
|
212
|
+
var chain;
|
|
213
|
+
args = _this.parse_arg(args, opcode === "cursor");
|
|
214
|
+
switch (opcode) {
|
|
215
|
+
case "chain":
|
|
216
|
+
chain = context.account.add_chain(args, context);
|
|
217
|
+
_this.contexts.push(chain);
|
|
218
|
+
chain.append_buffer();
|
|
219
|
+
break;
|
|
220
|
+
case "link":
|
|
221
|
+
chain = context.account.manager.web.get(args);
|
|
222
|
+
if (!chain) {
|
|
223
|
+
console.log("LINKing Failed. - ".concat(args));
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
chain.append_buffer();
|
|
227
|
+
_this.contexts.push(chain);
|
|
228
|
+
break;
|
|
229
|
+
case "mine":
|
|
230
|
+
var bloc = context.mine(_assertThisInitialized(_this), true);
|
|
231
|
+
_this.account.buff(bloc, _this.track.pids.slice(-1)[0]);
|
|
232
|
+
break;
|
|
233
|
+
case "pop":
|
|
234
|
+
var blk;
|
|
235
|
+
if (context.txs.length > 1) {
|
|
236
|
+
blk = context.mine(_assertThisInitialized(_this));
|
|
237
|
+
} else {
|
|
238
|
+
blk = context.get_latest_block();
|
|
239
|
+
if (blk) _this.get_context(-2).connections.push(blk);
|
|
240
|
+
context.txs = [];
|
|
241
|
+
}
|
|
242
|
+
blk && _this.account.buff(blk, _this.track.pids.slice(-1)[0]);
|
|
243
|
+
_this.contexts.pop();
|
|
244
|
+
break;
|
|
245
|
+
case "cursor":
|
|
246
|
+
context.set_cursor(args);
|
|
247
|
+
break;
|
|
248
|
+
case "write":
|
|
249
|
+
context.account.write(args, context);
|
|
250
|
+
break;
|
|
251
|
+
default:
|
|
252
|
+
_this.prepare_operation(opcode, context);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
118
255
|
}
|
|
119
|
-
|
|
256
|
+
);
|
|
120
257
|
_this.account = _context.account;
|
|
121
258
|
_this.contexts = [_context];
|
|
122
259
|
_this.stack = new Array();
|
|
123
260
|
return _this;
|
|
124
261
|
}
|
|
125
262
|
return _createClass(Virtual_machine);
|
|
126
|
-
}(_Opcodes2["default"]);
|
|
263
|
+
})(_Opcodes2["default"]);
|
|
127
264
|
var _default = Virtual_machine;
|
|
128
|
-
exports["default"] = _default;
|
|
265
|
+
exports["default"] = _default;
|
package/build/Account.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
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 _Filesystem2 = _interopRequireDefault(require("./Filesystem"));
|
|
10
|
+
var _Virtual_machine = _interopRequireDefault(require("./Virtual_machine"));
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
|
+
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); }
|
|
13
|
+
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); } }
|
|
14
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
15
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
16
|
+
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); }
|
|
17
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
18
|
+
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); }; }
|
|
19
|
+
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); }
|
|
20
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
21
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
22
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
23
|
+
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; }
|
|
24
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
25
|
+
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); }
|
|
26
|
+
var Account = /*#__PURE__*/function (_Filesystem) {
|
|
27
|
+
_inherits(Account, _Filesystem);
|
|
28
|
+
var _super = _createSuper(Account);
|
|
29
|
+
function Account(_name) {
|
|
30
|
+
var _this;
|
|
31
|
+
var _meta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
32
|
+
_classCallCheck(this, Account);
|
|
33
|
+
_this = _super.call(this);
|
|
34
|
+
_defineProperty(_assertThisInitialized(_this), "get_account", function (name) {
|
|
35
|
+
return _this.manager.get_account(name) || _assertThisInitialized(_this);
|
|
36
|
+
});
|
|
37
|
+
_defineProperty(_assertThisInitialized(_this), "manage_buffer", function (callback) {
|
|
38
|
+
var call_session = "".concat(Date.now(), "-").concat(Math.random());
|
|
39
|
+
_this.mine_buffer[call_session] = {
|
|
40
|
+
blocks: [],
|
|
41
|
+
callback: callback
|
|
42
|
+
};
|
|
43
|
+
return call_session;
|
|
44
|
+
});
|
|
45
|
+
_defineProperty(_assertThisInitialized(_this), "buff", function (block, pid) {
|
|
46
|
+
var buffer = _this.mine_buffer[pid];
|
|
47
|
+
if (!buffer) return;
|
|
48
|
+
buffer.blocks.push(block.stringify());
|
|
49
|
+
});
|
|
50
|
+
_defineProperty(_assertThisInitialized(_this), "flush_buffer", function (pid) {
|
|
51
|
+
var buff = _this.mine_buffer[pid];
|
|
52
|
+
if (!buff) return;
|
|
53
|
+
buff.callback && _this.run_callback(buff.callback, buff.blocks);
|
|
54
|
+
delete _this.mine_buffer[pid];
|
|
55
|
+
});
|
|
56
|
+
_defineProperty(_assertThisInitialized(_this), "load", function (_ref) {
|
|
57
|
+
var program = _ref.program,
|
|
58
|
+
signature = _ref.signature,
|
|
59
|
+
callback = _ref.callback;
|
|
60
|
+
var instructions = program.instructions,
|
|
61
|
+
account = program.account;
|
|
62
|
+
account = _this.get_account(account);
|
|
63
|
+
if (!account.validate(payload, signature, callback)) return;
|
|
64
|
+
var pid = account.manage_buffer(callback);
|
|
65
|
+
_this.manager.push({
|
|
66
|
+
sequence: instructions,
|
|
67
|
+
account: account,
|
|
68
|
+
pid: pid
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
_defineProperty(_assertThisInitialized(_this), "parse", function (_ref2) {
|
|
72
|
+
var payload = _ref2.payload,
|
|
73
|
+
signature = _ref2.signature,
|
|
74
|
+
callback = _ref2.callback;
|
|
75
|
+
var physical_address = payload.physical_address,
|
|
76
|
+
account = payload.account,
|
|
77
|
+
query = payload.query;
|
|
78
|
+
account = _this.get_account(account);
|
|
79
|
+
if (!account.validate(payload, signature)) return _this.run_callback(callback, {
|
|
80
|
+
"private": account["private"],
|
|
81
|
+
error: true,
|
|
82
|
+
error_message: "Invalid signature"
|
|
83
|
+
});
|
|
84
|
+
var chain = account.manager.web.get(physical_address);
|
|
85
|
+
if (!chain) return _this.run_callback(callback, {
|
|
86
|
+
error: true,
|
|
87
|
+
error_message: "Address not found"
|
|
88
|
+
});
|
|
89
|
+
var data = query ? chain.explore(query) : chain;
|
|
90
|
+
_this.run_callback(callback, data && data.stringify());
|
|
91
|
+
});
|
|
92
|
+
_defineProperty(_assertThisInitialized(_this), "run", function (request) {
|
|
93
|
+
var payload = request.payload,
|
|
94
|
+
signature = request.signature,
|
|
95
|
+
callback = request.callback;
|
|
96
|
+
var physical_address = payload.physical_address,
|
|
97
|
+
account = payload.account,
|
|
98
|
+
query = payload.query;
|
|
99
|
+
account = _this.get_account(account);
|
|
100
|
+
if (!account.validate(payload, signature, callback)) return;
|
|
101
|
+
var pid = account.manage_buffer(callback);
|
|
102
|
+
var context = physical_address ? _this.manager.web.get(physical_address) : account.vm.get_context();
|
|
103
|
+
if (!context) return account.flush_buffer(pid);
|
|
104
|
+
var blk = query ? context.explore(query) : context.get_latest_block();
|
|
105
|
+
if (blk && blk.metadata && blk.metadata.program) {
|
|
106
|
+
var program = _this.read(blk.metadata.program);
|
|
107
|
+
account.vm.contexts.push(context);
|
|
108
|
+
program.push("pop");
|
|
109
|
+
Array.isArray(program) && program.length && _this.manager.push({
|
|
110
|
+
sequence: program,
|
|
111
|
+
account: account,
|
|
112
|
+
pid: pid
|
|
113
|
+
});
|
|
114
|
+
} else account.flush_buffer(pid);
|
|
115
|
+
});
|
|
116
|
+
_defineProperty(_assertThisInitialized(_this), "run_callback", function (callback, payload) {
|
|
117
|
+
setTimeout(function () {
|
|
118
|
+
if (!callback) return;
|
|
119
|
+
if (typeof callback === "function") return callback(payload);
|
|
120
|
+
callback.payload && callback.payload.physical_address && _this.vm.stdin(payload, function () {
|
|
121
|
+
return _this.run(callback);
|
|
122
|
+
});
|
|
123
|
+
}, 0);
|
|
124
|
+
});
|
|
125
|
+
_defineProperty(_assertThisInitialized(_this), "validate", function (payload, signature, callback) {
|
|
126
|
+
if (!_this["private"]) return true;
|
|
127
|
+
var valid = (0, _privacy["default"])(_this.name, JSON.stringify(payload), signature);
|
|
128
|
+
if (!valid) _this.run_callback(callback, {
|
|
129
|
+
"private": _this["private"],
|
|
130
|
+
error: true,
|
|
131
|
+
error_message: "Invalid signature"
|
|
132
|
+
});
|
|
133
|
+
return valid;
|
|
134
|
+
});
|
|
135
|
+
_defineProperty(_assertThisInitialized(_this), "stringify", function (str) {
|
|
136
|
+
var obj = {};
|
|
137
|
+
obj.name = _this.name;
|
|
138
|
+
obj.hash = _this.hash;
|
|
139
|
+
obj.path = _this.path;
|
|
140
|
+
obj["private"] = _this["private"];
|
|
141
|
+
obj.chain = _this.chain.stringify();
|
|
142
|
+
obj.physical_address = _this.physical_address;
|
|
143
|
+
return str ? JSON.stringify(obj) : obj;
|
|
144
|
+
});
|
|
145
|
+
_defineProperty(_assertThisInitialized(_this), "create_account", function (payload) {
|
|
146
|
+
var name = payload.name,
|
|
147
|
+
meta = payload.meta;
|
|
148
|
+
return _this.manager.add_account(name, meta);
|
|
149
|
+
});
|
|
150
|
+
_defineProperty(_assertThisInitialized(_this), "endpoint", function (endpoint, payload) {
|
|
151
|
+
var method = _this[endpoint];
|
|
152
|
+
typeof method === "function" && method(payload);
|
|
153
|
+
});
|
|
154
|
+
_meta = _meta || {};
|
|
155
|
+
_this.name = _name;
|
|
156
|
+
_this["private"] = _meta["private"];
|
|
157
|
+
_this.manager = _meta.manager;
|
|
158
|
+
_this.account = _assertThisInitialized(_this);
|
|
159
|
+
if (!_this.manager) throw new Error("Manager instance missing.");
|
|
160
|
+
_this.name_hash();
|
|
161
|
+
_this.physical_address = "".concat(_this.base_address, "/").concat(_this.name);
|
|
162
|
+
_this.set_paths(_assertThisInitialized(_this));
|
|
163
|
+
_this.assembler = new _main["default"](_assertThisInitialized(_this));
|
|
164
|
+
_this.chain = _this.account_chain(_assertThisInitialized(_this));
|
|
165
|
+
_this.vm = new _Virtual_machine["default"](_this.chain);
|
|
166
|
+
_this.mine_buffer = {};
|
|
167
|
+
console.log("Account Instance: ".concat(_this.name));
|
|
168
|
+
return _this;
|
|
169
|
+
}
|
|
170
|
+
return _createClass(Account);
|
|
171
|
+
}(_Filesystem2["default"]);
|
|
172
|
+
var _default = Account;
|
|
173
|
+
exports["default"] = _default;
|
package/build/Block.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _hash = require("../utils/hash");
|
|
8
|
+
function _typeof(o) {
|
|
9
|
+
"@babel/helpers - typeof";
|
|
10
|
+
|
|
11
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
12
|
+
return typeof o;
|
|
13
|
+
} : function (o) {
|
|
14
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
15
|
+
}, _typeof(o);
|
|
16
|
+
}
|
|
17
|
+
function _defineProperties(e, r) {
|
|
18
|
+
for (var t = 0; t < r.length; t++) {
|
|
19
|
+
var o = r[t];
|
|
20
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _createClass(e, r, t) {
|
|
24
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
25
|
+
writable: !1
|
|
26
|
+
}), e;
|
|
27
|
+
}
|
|
28
|
+
function _classCallCheck(a, n) {
|
|
29
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
30
|
+
}
|
|
31
|
+
function _defineProperty(e, r, t) {
|
|
32
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
33
|
+
value: t,
|
|
34
|
+
enumerable: !0,
|
|
35
|
+
configurable: !0,
|
|
36
|
+
writable: !0
|
|
37
|
+
}) : e[r] = t, e;
|
|
38
|
+
}
|
|
39
|
+
function _toPropertyKey(t) {
|
|
40
|
+
var i = _toPrimitive(t, "string");
|
|
41
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
42
|
+
}
|
|
43
|
+
function _toPrimitive(t, r) {
|
|
44
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
45
|
+
var e = t[Symbol.toPrimitive];
|
|
46
|
+
if (void 0 !== e) {
|
|
47
|
+
var i = e.call(t, r || "default");
|
|
48
|
+
if ("object" != _typeof(i)) return i;
|
|
49
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
50
|
+
}
|
|
51
|
+
return ("string" === r ? String : Number)(t);
|
|
52
|
+
}
|
|
53
|
+
var Block = /*#__PURE__*/_createClass(function Block(chain) {
|
|
54
|
+
var _this = this;
|
|
55
|
+
_classCallCheck(this, Block);
|
|
56
|
+
_defineProperty(this, "generate_hash", function () {
|
|
57
|
+
_this.previous_hash = _this.chain.get_latest_block();
|
|
58
|
+
if (_this.previous_hash) _this.previous_hash = _this.previous_hash.hash;
|
|
59
|
+
_this.hash = (0, _hash.hash)(JSON.stringify(_this.data));
|
|
60
|
+
});
|
|
61
|
+
_defineProperty(this, "store", function (no_curs) {
|
|
62
|
+
var content = _this.chain.buffs.splice(-1)[0];
|
|
63
|
+
if (!no_curs) _this.cursor = _this.chain.cursors.splice(-1)[0];
|
|
64
|
+
if (!content) return;
|
|
65
|
+
var cursors = Object.keys(content).filter(function (c) {
|
|
66
|
+
return c.startsWith("{") && c.endsWith("}");
|
|
67
|
+
});
|
|
68
|
+
for (var c = 0; c < cursors.length; c++) {
|
|
69
|
+
var curs = cursors[c];
|
|
70
|
+
_this.metadata[curs.slice(1, -1)] = content[curs];
|
|
71
|
+
delete content[curs];
|
|
72
|
+
}
|
|
73
|
+
var datapath = _this.chain.account.save(content, _this.chain);
|
|
74
|
+
_this.datapath = datapath;
|
|
75
|
+
});
|
|
76
|
+
_defineProperty(this, "stringify", function (str) {
|
|
77
|
+
var obj = {};
|
|
78
|
+
obj.metadata = _this.metadata;
|
|
79
|
+
obj.datapath = _this.datapath;
|
|
80
|
+
obj.timelapse = _this.timelapse;
|
|
81
|
+
obj.index = _this.index;
|
|
82
|
+
obj.hash = _this.hash;
|
|
83
|
+
obj.data = _this.data;
|
|
84
|
+
obj.children = _this.children.map(function (ch) {
|
|
85
|
+
return new Object({
|
|
86
|
+
hash: ch.hash,
|
|
87
|
+
chain: ch.chain.hash
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
obj.chain = {
|
|
91
|
+
hash: _this.chain.hash,
|
|
92
|
+
physical_address: _this.chain.physical_address
|
|
93
|
+
};
|
|
94
|
+
return str ? JSON.stringify(obj) : obj;
|
|
95
|
+
});
|
|
96
|
+
this.chain = chain;
|
|
97
|
+
this.data = this.chain.txs;
|
|
98
|
+
this.metadata = {};
|
|
99
|
+
this.children = new Array();
|
|
100
|
+
this.index = this.chain.blocks.length;
|
|
101
|
+
});
|
|
102
|
+
var _default = Block;
|
|
103
|
+
exports["default"] = _default;
|