godprotocol 1.0.789 → 1.0.792
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/package.json +1 -1
- package/readme.md +94 -71
package/Objects/Account.js
CHANGED
|
@@ -1,58 +1,196 @@
|
|
|
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 _main = _interopRequireDefault(require("../Loader_sequence/main"));
|
|
8
8
|
var _privacy = _interopRequireDefault(require("../utils/privacy"));
|
|
9
9
|
var _Filesystem2 = _interopRequireDefault(require("./Filesystem"));
|
|
10
10
|
var _Virtual_machine = _interopRequireDefault(require("./Virtual_machine"));
|
|
11
|
-
function _interopRequireDefault(e) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
11
|
+
function _interopRequireDefault(e) {
|
|
12
|
+
return e && e.__esModule ? e : { default: e };
|
|
13
|
+
}
|
|
14
|
+
function _typeof(o) {
|
|
15
|
+
"@babel/helpers - typeof";
|
|
16
|
+
return (
|
|
17
|
+
(_typeof =
|
|
18
|
+
"function" == typeof Symbol && "symbol" == typeof Symbol.iterator
|
|
19
|
+
? function (o) {
|
|
20
|
+
return typeof o;
|
|
21
|
+
}
|
|
22
|
+
: function (o) {
|
|
23
|
+
return o &&
|
|
24
|
+
"function" == typeof Symbol &&
|
|
25
|
+
o.constructor === Symbol &&
|
|
26
|
+
o !== Symbol.prototype
|
|
27
|
+
? "symbol"
|
|
28
|
+
: typeof o;
|
|
29
|
+
}),
|
|
30
|
+
_typeof(o)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
function _defineProperties(e, r) {
|
|
34
|
+
for (var t = 0; t < r.length; t++) {
|
|
35
|
+
var o = r[t];
|
|
36
|
+
(o.enumerable = o.enumerable || !1),
|
|
37
|
+
(o.configurable = !0),
|
|
38
|
+
"value" in o && (o.writable = !0),
|
|
39
|
+
Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function _createClass(e, r, t) {
|
|
43
|
+
return (
|
|
44
|
+
r && _defineProperties(e.prototype, r),
|
|
45
|
+
t && _defineProperties(e, t),
|
|
46
|
+
Object.defineProperty(e, "prototype", { writable: !1 }),
|
|
47
|
+
e
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
function _classCallCheck(a, n) {
|
|
51
|
+
if (!(a instanceof n))
|
|
52
|
+
throw new TypeError("Cannot call a class as a function");
|
|
53
|
+
}
|
|
54
|
+
function _inherits(t, e) {
|
|
55
|
+
if ("function" != typeof e && null !== e)
|
|
56
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
57
|
+
(t.prototype = Object.create(e && e.prototype, {
|
|
58
|
+
constructor: { value: t, writable: !0, configurable: !0 },
|
|
59
|
+
})),
|
|
60
|
+
Object.defineProperty(t, "prototype", { writable: !1 }),
|
|
61
|
+
e && _setPrototypeOf(t, e);
|
|
62
|
+
}
|
|
63
|
+
function _setPrototypeOf(t, e) {
|
|
64
|
+
return (
|
|
65
|
+
(_setPrototypeOf = Object.setPrototypeOf
|
|
66
|
+
? Object.setPrototypeOf.bind()
|
|
67
|
+
: function (t, e) {
|
|
68
|
+
return (t.__proto__ = e), t;
|
|
69
|
+
}),
|
|
70
|
+
_setPrototypeOf(t, e)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
function _createSuper(t) {
|
|
74
|
+
var r = _isNativeReflectConstruct();
|
|
75
|
+
return function () {
|
|
76
|
+
var e,
|
|
77
|
+
o = _getPrototypeOf(t);
|
|
78
|
+
if (r) {
|
|
79
|
+
var s = _getPrototypeOf(this).constructor;
|
|
80
|
+
e = Reflect.construct(o, arguments, s);
|
|
81
|
+
} else e = o.apply(this, arguments);
|
|
82
|
+
return _possibleConstructorReturn(this, e);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function _possibleConstructorReturn(t, e) {
|
|
86
|
+
if (e && ("object" == _typeof(e) || "function" == typeof e)) return e;
|
|
87
|
+
if (void 0 !== e)
|
|
88
|
+
throw new TypeError(
|
|
89
|
+
"Derived constructors may only return object or undefined"
|
|
90
|
+
);
|
|
91
|
+
return _assertThisInitialized(t);
|
|
92
|
+
}
|
|
93
|
+
function _assertThisInitialized(e) {
|
|
94
|
+
if (void 0 === e)
|
|
95
|
+
throw new ReferenceError(
|
|
96
|
+
"this hasn't been initialised - super() hasn't been called"
|
|
97
|
+
);
|
|
98
|
+
return e;
|
|
99
|
+
}
|
|
100
|
+
function _isNativeReflectConstruct() {
|
|
101
|
+
try {
|
|
102
|
+
var t = !Boolean.prototype.valueOf.call(
|
|
103
|
+
Reflect.construct(Boolean, [], function () {})
|
|
104
|
+
);
|
|
105
|
+
} catch (t) {}
|
|
106
|
+
return (_isNativeReflectConstruct = function _isNativeReflectConstruct() {
|
|
107
|
+
return !!t;
|
|
108
|
+
})();
|
|
109
|
+
}
|
|
110
|
+
function _getPrototypeOf(t) {
|
|
111
|
+
return (
|
|
112
|
+
(_getPrototypeOf = Object.setPrototypeOf
|
|
113
|
+
? Object.getPrototypeOf.bind()
|
|
114
|
+
: function (t) {
|
|
115
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
116
|
+
}),
|
|
117
|
+
_getPrototypeOf(t)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
function _defineProperty(e, r, t) {
|
|
121
|
+
return (
|
|
122
|
+
(r = _toPropertyKey(r)) in e
|
|
123
|
+
? Object.defineProperty(e, r, {
|
|
124
|
+
value: t,
|
|
125
|
+
enumerable: !0,
|
|
126
|
+
configurable: !0,
|
|
127
|
+
writable: !0,
|
|
128
|
+
})
|
|
129
|
+
: (e[r] = t),
|
|
130
|
+
e
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
function _toPropertyKey(t) {
|
|
134
|
+
var i = _toPrimitive(t, "string");
|
|
135
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
136
|
+
}
|
|
137
|
+
function _toPrimitive(t, r) {
|
|
138
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
139
|
+
var e = t[Symbol.toPrimitive];
|
|
140
|
+
if (void 0 !== e) {
|
|
141
|
+
var i = e.call(t, r || "default");
|
|
142
|
+
if ("object" != _typeof(i)) return i;
|
|
143
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
144
|
+
}
|
|
145
|
+
return ("string" === r ? String : Number)(t);
|
|
146
|
+
}
|
|
147
|
+
var Account = /*#__PURE__*/ (function (_Filesystem) {
|
|
27
148
|
_inherits(Account, _Filesystem);
|
|
28
149
|
var _super = _createSuper(Account);
|
|
29
150
|
function Account(_name) {
|
|
30
151
|
var _this;
|
|
31
|
-
var _meta =
|
|
152
|
+
var _meta =
|
|
153
|
+
arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
32
154
|
_classCallCheck(this, Account);
|
|
33
155
|
_this = _super.call(this);
|
|
34
|
-
_defineProperty(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
156
|
+
_defineProperty(
|
|
157
|
+
_assertThisInitialized(_this),
|
|
158
|
+
"get_account",
|
|
159
|
+
function (name) {
|
|
160
|
+
return _this.manager.get_account(name) || _assertThisInitialized(_this);
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
_defineProperty(
|
|
164
|
+
_assertThisInitialized(_this),
|
|
165
|
+
"manage_buffer",
|
|
166
|
+
function (callback) {
|
|
167
|
+
var call_session = "".concat(Date.now(), "-").concat(Math.random());
|
|
168
|
+
_this.mine_buffer[call_session] = {
|
|
169
|
+
blocks: [],
|
|
170
|
+
callback: callback,
|
|
171
|
+
};
|
|
172
|
+
return call_session;
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
_defineProperty(
|
|
176
|
+
_assertThisInitialized(_this),
|
|
177
|
+
"buff",
|
|
178
|
+
function (block, pid) {
|
|
179
|
+
var buffer = _this.mine_buffer[pid];
|
|
180
|
+
if (!buffer) return;
|
|
181
|
+
buffer.blocks.push(block.stringify());
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
_defineProperty(
|
|
185
|
+
_assertThisInitialized(_this),
|
|
186
|
+
"flush_buffer",
|
|
187
|
+
function (pid) {
|
|
188
|
+
var buff = _this.mine_buffer[pid];
|
|
189
|
+
if (!buff) return;
|
|
190
|
+
buff.callback && _this.run_callback(buff.callback, buff.blocks);
|
|
191
|
+
delete _this.mine_buffer[pid];
|
|
192
|
+
}
|
|
193
|
+
);
|
|
56
194
|
_defineProperty(_assertThisInitialized(_this), "load", function (_ref) {
|
|
57
195
|
var program = _ref.program,
|
|
58
196
|
signature = _ref.signature,
|
|
@@ -60,12 +198,12 @@ var Account = /*#__PURE__*/function (_Filesystem) {
|
|
|
60
198
|
var instructions = program.instructions,
|
|
61
199
|
account = program.account;
|
|
62
200
|
account = _this.get_account(account);
|
|
63
|
-
if (!account.validate(
|
|
201
|
+
if (!account.validate(payload, signature, callback)) return;
|
|
64
202
|
var pid = account.manage_buffer(callback);
|
|
65
203
|
_this.manager.push({
|
|
66
204
|
sequence: instructions,
|
|
67
205
|
account: account,
|
|
68
|
-
pid: pid
|
|
206
|
+
pid: pid,
|
|
69
207
|
});
|
|
70
208
|
});
|
|
71
209
|
_defineProperty(_assertThisInitialized(_this), "parse", function (_ref2) {
|
|
@@ -76,12 +214,18 @@ var Account = /*#__PURE__*/function (_Filesystem) {
|
|
|
76
214
|
account = payload.account,
|
|
77
215
|
query = payload.query;
|
|
78
216
|
account = _this.get_account(account);
|
|
79
|
-
if (!account.validate(payload, signature))
|
|
217
|
+
if (!account.validate(payload, signature))
|
|
218
|
+
return _this.run_callback(callback, {
|
|
219
|
+
private: account["private"],
|
|
220
|
+
error: true,
|
|
221
|
+
error_message: "Invalid signature",
|
|
222
|
+
});
|
|
80
223
|
var chain = account.manager.web.get(physical_address);
|
|
81
|
-
if (!chain)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
224
|
+
if (!chain)
|
|
225
|
+
return _this.run_callback(callback, {
|
|
226
|
+
error: true,
|
|
227
|
+
error_message: "Address not found",
|
|
228
|
+
});
|
|
85
229
|
var data = query ? chain.explore(query) : chain;
|
|
86
230
|
_this.run_callback(callback, data && data.stringify());
|
|
87
231
|
});
|
|
@@ -93,34 +237,60 @@ var Account = /*#__PURE__*/function (_Filesystem) {
|
|
|
93
237
|
account = payload.account,
|
|
94
238
|
query = payload.query;
|
|
95
239
|
account = _this.get_account(account);
|
|
96
|
-
if (!account.validate(payload, signature)) return;
|
|
240
|
+
if (!account.validate(payload, signature, callback)) return;
|
|
97
241
|
var pid = account.manage_buffer(callback);
|
|
98
|
-
var context = physical_address
|
|
242
|
+
var context = physical_address
|
|
243
|
+
? _this.manager.web.get(physical_address)
|
|
244
|
+
: account.vm.get_context();
|
|
99
245
|
if (!context) return account.flush_buffer(pid);
|
|
100
246
|
var blk = query ? context.explore(query) : context.get_latest_block();
|
|
101
247
|
if (blk && blk.metadata && blk.metadata.program) {
|
|
102
248
|
var program = _this.read(blk.metadata.program);
|
|
103
249
|
account.vm.contexts.push(context);
|
|
104
250
|
program.push("pop");
|
|
105
|
-
Array.isArray(program) &&
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
setTimeout(function () {
|
|
114
|
-
if (!callback) return;
|
|
115
|
-
if (typeof callback === "function") return callback(payload);
|
|
116
|
-
_this.vm.stdin(payload);
|
|
117
|
-
callback.payload && callback.payload.physical_address && _this.run(callback);
|
|
118
|
-
}, 0);
|
|
119
|
-
});
|
|
120
|
-
_defineProperty(_assertThisInitialized(_this), "validate", function (payload, signature) {
|
|
121
|
-
if (!_this["private"]) return true;
|
|
122
|
-
return (0, _privacy["default"])(_this.name, JSON.stringify(payload), signature);
|
|
251
|
+
Array.isArray(program) &&
|
|
252
|
+
program.length &&
|
|
253
|
+
_this.manager.push({
|
|
254
|
+
sequence: program,
|
|
255
|
+
account: account,
|
|
256
|
+
pid: pid,
|
|
257
|
+
});
|
|
258
|
+
} else account.flush_buffer(pid);
|
|
123
259
|
});
|
|
260
|
+
_defineProperty(
|
|
261
|
+
_assertThisInitialized(_this),
|
|
262
|
+
"run_callback",
|
|
263
|
+
function (callback, payload) {
|
|
264
|
+
setTimeout(function () {
|
|
265
|
+
if (!callback) return;
|
|
266
|
+
if (typeof callback === "function") return callback(payload);
|
|
267
|
+
callback.payload &&
|
|
268
|
+
callback.payload.physical_address &&
|
|
269
|
+
_this.vm.stdin(payload, function () {
|
|
270
|
+
return _this.run(callback);
|
|
271
|
+
});
|
|
272
|
+
}, 0);
|
|
273
|
+
}
|
|
274
|
+
);
|
|
275
|
+
_defineProperty(
|
|
276
|
+
_assertThisInitialized(_this),
|
|
277
|
+
"validate",
|
|
278
|
+
function (payload, signature, callback) {
|
|
279
|
+
if (!_this["private"]) return true;
|
|
280
|
+
var valid = (0, _privacy["default"])(
|
|
281
|
+
_this.name,
|
|
282
|
+
JSON.stringify(payload),
|
|
283
|
+
signature
|
|
284
|
+
);
|
|
285
|
+
if (!valid)
|
|
286
|
+
_this.run_callback(callback, {
|
|
287
|
+
private: _this["private"],
|
|
288
|
+
error: true,
|
|
289
|
+
error_message: "Invalid signature",
|
|
290
|
+
});
|
|
291
|
+
return valid;
|
|
292
|
+
}
|
|
293
|
+
);
|
|
124
294
|
_defineProperty(_assertThisInitialized(_this), "stringify", function (str) {
|
|
125
295
|
var obj = {};
|
|
126
296
|
obj.name = _this.name;
|
|
@@ -131,15 +301,23 @@ var Account = /*#__PURE__*/function (_Filesystem) {
|
|
|
131
301
|
obj.physical_address = _this.physical_address;
|
|
132
302
|
return str ? JSON.stringify(obj) : obj;
|
|
133
303
|
});
|
|
134
|
-
_defineProperty(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
304
|
+
_defineProperty(
|
|
305
|
+
_assertThisInitialized(_this),
|
|
306
|
+
"create_account",
|
|
307
|
+
function (payload) {
|
|
308
|
+
var name = payload.name,
|
|
309
|
+
meta = payload.meta;
|
|
310
|
+
return _this.manager.add_account(name, meta);
|
|
311
|
+
}
|
|
312
|
+
);
|
|
313
|
+
_defineProperty(
|
|
314
|
+
_assertThisInitialized(_this),
|
|
315
|
+
"endpoint",
|
|
316
|
+
function (endpoint, payload) {
|
|
317
|
+
var method = _this[endpoint];
|
|
318
|
+
typeof method === "function" && method(payload);
|
|
319
|
+
}
|
|
320
|
+
);
|
|
143
321
|
_meta = _meta || {};
|
|
144
322
|
_this.name = _name;
|
|
145
323
|
_this["private"] = _meta["private"];
|
|
@@ -147,9 +325,11 @@ var Account = /*#__PURE__*/function (_Filesystem) {
|
|
|
147
325
|
_this.account = _assertThisInitialized(_this);
|
|
148
326
|
if (!_this.manager) throw new Error("Manager instance missing.");
|
|
149
327
|
_this.name_hash();
|
|
150
|
-
_this.physical_address = ""
|
|
328
|
+
_this.physical_address = ""
|
|
329
|
+
.concat(_this.base_address, "/")
|
|
330
|
+
.concat(_this.name);
|
|
151
331
|
_this.set_paths(_assertThisInitialized(_this));
|
|
152
|
-
_this.
|
|
332
|
+
_this.assembler = new _main["default"](_assertThisInitialized(_this));
|
|
153
333
|
_this.chain = _this.account_chain(_assertThisInitialized(_this));
|
|
154
334
|
_this.vm = new _Virtual_machine["default"](_this.chain);
|
|
155
335
|
_this.mine_buffer = {};
|
|
@@ -157,6 +337,6 @@ var Account = /*#__PURE__*/function (_Filesystem) {
|
|
|
157
337
|
return _this;
|
|
158
338
|
}
|
|
159
339
|
return _createClass(Account);
|
|
160
|
-
}(_Filesystem2["default"]);
|
|
340
|
+
})(_Filesystem2["default"]);
|
|
161
341
|
var _default = Account;
|
|
162
|
-
exports["default"] = _default;
|
|
342
|
+
exports["default"] = _default;
|
package/Objects/Manager.js
CHANGED
|
@@ -43,8 +43,7 @@ var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
|
43
43
|
delete _this.tracks[account];
|
|
44
44
|
}
|
|
45
45
|
if (track.breakpoint.slice(-1)[0] === track.pointer) {
|
|
46
|
-
track.account.flush_buffer(track.pids.
|
|
47
|
-
track.pid = track.pids.splice(-1)[0];
|
|
46
|
+
track.account.flush_buffer(track.pids.splice(-1)[0]);
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
!_this.running && clearInterval(_this.clock);
|
|
@@ -71,7 +70,7 @@ var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
|
71
70
|
var track = _this.tracks[program.account.name];
|
|
72
71
|
if (track) {
|
|
73
72
|
var _track$sequence;
|
|
74
|
-
track.breakpoint.push(track.pointer);
|
|
73
|
+
track.breakpoint.push(track.pointer + program.sequence.length + 1);
|
|
75
74
|
(_track$sequence = track.sequence).splice.apply(_track$sequence, [track.pointer + 1, 0].concat(_toConsumableArray(program.sequence)));
|
|
76
75
|
track.pids.push(program.pid);
|
|
77
76
|
if (!_this.running) {
|
package/Objects/Opcodes.js
CHANGED
|
@@ -1,18 +1,78 @@
|
|
|
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 _functions = require("../utils/functions");
|
|
8
|
-
function _typeof(o) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
function _typeof(o) {
|
|
9
|
+
"@babel/helpers - typeof";
|
|
10
|
+
return (
|
|
11
|
+
(_typeof =
|
|
12
|
+
"function" == typeof Symbol && "symbol" == typeof Symbol.iterator
|
|
13
|
+
? function (o) {
|
|
14
|
+
return typeof o;
|
|
15
|
+
}
|
|
16
|
+
: function (o) {
|
|
17
|
+
return o &&
|
|
18
|
+
"function" == typeof Symbol &&
|
|
19
|
+
o.constructor === Symbol &&
|
|
20
|
+
o !== Symbol.prototype
|
|
21
|
+
? "symbol"
|
|
22
|
+
: typeof o;
|
|
23
|
+
}),
|
|
24
|
+
_typeof(o)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
function _defineProperties(e, r) {
|
|
28
|
+
for (var t = 0; t < r.length; t++) {
|
|
29
|
+
var o = r[t];
|
|
30
|
+
(o.enumerable = o.enumerable || !1),
|
|
31
|
+
(o.configurable = !0),
|
|
32
|
+
"value" in o && (o.writable = !0),
|
|
33
|
+
Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function _createClass(e, r, t) {
|
|
37
|
+
return (
|
|
38
|
+
r && _defineProperties(e.prototype, r),
|
|
39
|
+
t && _defineProperties(e, t),
|
|
40
|
+
Object.defineProperty(e, "prototype", { writable: !1 }),
|
|
41
|
+
e
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
function _classCallCheck(a, n) {
|
|
45
|
+
if (!(a instanceof n))
|
|
46
|
+
throw new TypeError("Cannot call a class as a function");
|
|
47
|
+
}
|
|
48
|
+
function _defineProperty(e, r, t) {
|
|
49
|
+
return (
|
|
50
|
+
(r = _toPropertyKey(r)) in e
|
|
51
|
+
? Object.defineProperty(e, r, {
|
|
52
|
+
value: t,
|
|
53
|
+
enumerable: !0,
|
|
54
|
+
configurable: !0,
|
|
55
|
+
writable: !0,
|
|
56
|
+
})
|
|
57
|
+
: (e[r] = t),
|
|
58
|
+
e
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
function _toPropertyKey(t) {
|
|
62
|
+
var i = _toPrimitive(t, "string");
|
|
63
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
64
|
+
}
|
|
65
|
+
function _toPrimitive(t, r) {
|
|
66
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
67
|
+
var e = t[Symbol.toPrimitive];
|
|
68
|
+
if (void 0 !== e) {
|
|
69
|
+
var i = e.call(t, r || "default");
|
|
70
|
+
if ("object" != _typeof(i)) return i;
|
|
71
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
72
|
+
}
|
|
73
|
+
return ("string" === r ? String : Number)(t);
|
|
74
|
+
}
|
|
75
|
+
var Opcodes = /*#__PURE__*/ _createClass(function Opcodes() {
|
|
16
76
|
var _this = this;
|
|
17
77
|
_classCallCheck(this, Opcodes);
|
|
18
78
|
_defineProperty(this, "set", function (opcode, circuit) {
|
|
@@ -27,13 +87,16 @@ var Opcodes = /*#__PURE__*/_createClass(function Opcodes() {
|
|
|
27
87
|
var res = circ(args);
|
|
28
88
|
_this.stdin(res);
|
|
29
89
|
});
|
|
30
|
-
_defineProperty(this, "stdin", function (object) {
|
|
90
|
+
_defineProperty(this, "stdin", function (object, cb) {
|
|
31
91
|
if (object == null) return;
|
|
32
92
|
var code_string = (0, _functions.transpile_object)(object);
|
|
33
|
-
_this.account.
|
|
93
|
+
_this.account.assembler.run(code_string, {
|
|
94
|
+
cb: cb,
|
|
95
|
+
pure: true,
|
|
96
|
+
});
|
|
34
97
|
// console.log(`Writing in: ${code_string}`);
|
|
35
98
|
});
|
|
36
99
|
this.opcodes = new Object();
|
|
37
100
|
});
|
|
38
101
|
var _default = Opcodes;
|
|
39
|
-
exports["default"] = _default;
|
|
102
|
+
exports["default"] = _default;
|
|
@@ -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/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -10,111 +10,134 @@ npm install godprotocol --save
|
|
|
10
10
|
|
|
11
11
|
### Brief Description
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
It is to help provide multiple compute instances for servers and also data flexibility and transactions.
|
|
13
|
+
God Protocol makes data sharing and processing easy for apps. With simple APIs, developers can add advanced features like AI, distribution, and scaling. Here are the main endpoints:
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
### Endpoints
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
- [**/create_account:**](#create_account) Create a new machine account.
|
|
18
|
+
- [**/load:**](#load) Load and send an instruction sequence to the server.
|
|
19
|
+
- [**/run:**](#run) Execute the instruction sequence.
|
|
20
|
+
- [**/parse:**](#parse) Retrieve and process results from the server.
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## /create_account
|
|
25
|
+
|
|
26
|
+
The /create_account endpoint creates a new account in the God Protocol. This account is necessary for using other features and handling data and tasks in the decentralised system.
|
|
27
|
+
|
|
28
|
+
### Example Usage
|
|
21
29
|
|
|
22
30
|
```js
|
|
23
|
-
import
|
|
31
|
+
import manager from "godprotocol";
|
|
24
32
|
|
|
25
|
-
|
|
26
|
-
let
|
|
27
|
-
// if private is set to `true`, communication to the account instance must be validated by sigining with the private key.
|
|
28
|
-
// N.B your keypairs are generated offline.
|
|
33
|
+
let account = manager.add_account("name");
|
|
34
|
+
let private_account = manager.add_account("public_key", { private: true });
|
|
29
35
|
```
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
### Parameters
|
|
38
|
+
|
|
39
|
+
- `name` (string): The name to associate with the new account.
|
|
40
|
+
- `meta` (object): Optional. Configuration object for account settings. Use `{ private: true }` to create a [private account](https://godprotocol-web.vercel.app/accounts/private).
|
|
41
|
+
|
|
42
|
+
| Parameter | Possible Values | Default Value | Type | Description |
|
|
43
|
+
| --------- | ---------------- | ------------- | ------- | ------------------------------------------------------------- |
|
|
44
|
+
| `name` | Any string | `initiator` | string | The name to associate with the new account. |
|
|
45
|
+
| `meta` | `{private:true}` | `{}` | object | Optional. Configuration object for account settings. |
|
|
46
|
+
| `private` | `true`, `false` | `false` | boolean | Nested in `meta`. Specifies if the account should be private. |
|
|
35
47
|
|
|
36
|
-
##
|
|
48
|
+
## /load
|
|
37
49
|
|
|
38
|
-
The load
|
|
39
|
-
It is used to set your programs into the network web,
|
|
40
|
-
where its data can continue to be accessed, and subsequent
|
|
41
|
-
calls can be made on the loaded program.
|
|
50
|
+
The /load endpoint in the God Protocol framework loads a program with specified instructions and manages associated accounts.
|
|
42
51
|
|
|
43
|
-
### Usage
|
|
52
|
+
### Example Usage
|
|
44
53
|
|
|
45
54
|
```js
|
|
46
|
-
|
|
47
|
-
{
|
|
48
|
-
instructions: ["
|
|
49
|
-
account:
|
|
55
|
+
account.load({
|
|
56
|
+
program: {
|
|
57
|
+
instructions: ["instruction1", "instruction2"],
|
|
58
|
+
account: "account_id",
|
|
50
59
|
},
|
|
51
|
-
|
|
52
|
-
)
|
|
60
|
+
signature: "signature_string",
|
|
61
|
+
callback: () => {
|
|
62
|
+
// Callback function logic
|
|
63
|
+
},
|
|
64
|
+
});
|
|
53
65
|
```
|
|
54
66
|
|
|
55
|
-
Type
|
|
67
|
+
| **Paramters** | **Possible Values** | **Default Value** | **Type** | **Description** |
|
|
68
|
+
| ---------------------- | ----------------------------------- | ----------------- | ---------------------- | ----------------------------------------------------------------- |
|
|
69
|
+
| `program` | `{ instructions: [], account: "" }` | None | object | Object containing program instructions and associated account. |
|
|
70
|
+
| `program.instructions` | Array of strings | [] | array | Array of program instructions. |
|
|
71
|
+
| `program.account` | Any string | `"initiator"` | string | Associated account for program execution. |
|
|
72
|
+
| `signature` | String | None | string | Optional. Signature for private account access. |
|
|
73
|
+
| `callback` | Function or `account.run{}` | None | `function` or `object` | Optional. Function to call upon completion of the load operation. |
|
|
56
74
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
| `program` | object | `instructions` | An array of opcode-operands generated by the [`Loader Sequence`](https://godprotocol-web.vercel.app/loader_sequence) |
|
|
60
|
-
| | | `account` | Account instance to load and execute the program in. |
|
|
61
|
-
| `cb` | function | | A function that is called with the blocks mined during the execution. |
|
|
75
|
+
Description:
|
|
76
|
+
The /load endpoint loads a program with instructions (program.instructions) and links it to an account (program.account). For private accounts, include a signature of the `program` for access. Optionally, provide a callback function to handle completion events, which may include additional execution payload (account.run).
|
|
62
77
|
|
|
63
|
-
##
|
|
78
|
+
## `/run`
|
|
64
79
|
|
|
65
|
-
The run
|
|
80
|
+
The /run endpoint runs a program in the provided payload, physical address, and account details.
|
|
66
81
|
|
|
67
|
-
### Usage
|
|
82
|
+
### Example Usage
|
|
68
83
|
|
|
69
84
|
```js
|
|
70
|
-
|
|
71
|
-
{
|
|
72
|
-
physical_address: "
|
|
73
|
-
|
|
74
|
-
|
|
85
|
+
account.run({
|
|
86
|
+
payload: {
|
|
87
|
+
physical_address: "Accounts/name/path",
|
|
88
|
+
account: "account_id",
|
|
89
|
+
query: `blocks:0`,
|
|
90
|
+
},
|
|
91
|
+
signature: "signature_string",
|
|
92
|
+
callback: () => {
|
|
93
|
+
// Callback function logic
|
|
75
94
|
},
|
|
76
|
-
|
|
77
|
-
);
|
|
78
|
-
// N.B If query is missing, then VM starts execution from the block-index-0
|
|
95
|
+
});
|
|
79
96
|
```
|
|
80
97
|
|
|
81
|
-
Type
|
|
82
|
-
|
|
83
|
-
| `
|
|
84
|
-
|
|
|
85
|
-
| `payload`
|
|
86
|
-
|
|
|
87
|
-
|
|
|
88
|
-
| `
|
|
98
|
+
| Parameters | Possible Values | Default Value | Type | Descriptions |
|
|
99
|
+
| -------------------------- | ----------------------------------------------------------------------------- | ------------- | ---------------------- | ------------------------------------------------------------------- |
|
|
100
|
+
| `payload` | `{ physical_address: "", account: "", query: "" }` | None | object | Object containing the physical address, account, and query details. |
|
|
101
|
+
| `payload.physical_address` | Any [`physical_address`](https://godprotocol-web.vercel.app/physical_address) | None | string | The physical address path for the account. |
|
|
102
|
+
| `payload.account` | Any string | None | string | Associated account for execution. |
|
|
103
|
+
| `payload.query` | [`Query Strings`](https://godprotocol-web.vercel.app/explorer/query) | None | string | Query string to specify blocks or other parameters. |
|
|
104
|
+
| `signature` | String | None | string | Optional. Signature for private account access. |
|
|
105
|
+
| `callback` | Function or `account.run{}` | None | `function` or `object` | Optional. Function to call upon execution completion. |
|
|
89
106
|
|
|
90
|
-
|
|
107
|
+
**Description:**
|
|
108
|
+
The /run endpoint in the God Protocol framework allows users to execute a program with a specified payload, which includes the physical address (`payload.physical_address`), associated account (`payload.account`), and query (`payload.query`). If the account is private, a payload `signature` is required. An optional `callback` function can be provided to handle completion events, which may include further execution instructions (`account.run`).
|
|
91
109
|
|
|
92
|
-
|
|
110
|
+
## /parse Endpoint
|
|
93
111
|
|
|
94
|
-
|
|
112
|
+
The /parse endpoint parses data from a specified payload and returns matched blocks or the entire chain if no query is included.
|
|
95
113
|
|
|
96
|
-
|
|
114
|
+
### Example Usage
|
|
97
115
|
|
|
98
116
|
```js
|
|
99
|
-
|
|
100
|
-
{
|
|
101
|
-
physical_address: "
|
|
102
|
-
|
|
103
|
-
|
|
117
|
+
account.parse({
|
|
118
|
+
payload: {
|
|
119
|
+
physical_address: "Accounts/name/path",
|
|
120
|
+
account: "account_id",
|
|
121
|
+
query: "blocks:0",
|
|
104
122
|
},
|
|
105
|
-
|
|
106
|
-
)
|
|
107
|
-
//
|
|
123
|
+
signature: "signature_string",
|
|
124
|
+
callback: () => {
|
|
125
|
+
// Callback function logic
|
|
126
|
+
},
|
|
127
|
+
});
|
|
108
128
|
```
|
|
109
129
|
|
|
110
|
-
Type
|
|
111
|
-
|
|
112
|
-
| `
|
|
113
|
-
|
|
|
114
|
-
| `payload`
|
|
115
|
-
|
|
|
116
|
-
|
|
|
117
|
-
| `
|
|
130
|
+
| Parameters | Possible Values | Default Value | Type | Descriptions |
|
|
131
|
+
| -------------------------- | ----------------------------------------------------------------------------- | ------------- | ---------------------- | ------------------------------------------------------------------- |
|
|
132
|
+
| `payload` | `{ physical_address: "", account: "", query: "" }` | None | object | Object containing the physical address, account, and query details. |
|
|
133
|
+
| `payload.physical_address` | Any [`physical_address`](https://godprotocol-web.vercel.app/physical_address) | None | string | The physical address path for the account. |
|
|
134
|
+
| `payload.account` | Any string | None | string | Associated account for execution. |
|
|
135
|
+
| `payload.query` | [`Query Strings`](https://godprotocol-web.vercel.app/explorer/query) | None | string | Query string to specify blocks or other parameters. |
|
|
136
|
+
| `signature` | String | None | string | Optional. Signature for private account access. |
|
|
137
|
+
| `callback` | Function or `account.run{}` | None | `function` or `object` | Optional. Function to call upon execution completion. |
|
|
138
|
+
|
|
139
|
+
**Description:**
|
|
140
|
+
The /parse endpoint in the God Protocol framework parses data from the specified payload, which includes the physical address (`payload.physical_address`), associated account (`payload.account`), and an optional query (`payload.query`). If the account is private, a payload `signature` is required. An optional `callback` function can be provided to handle completion events, which may include further execution instructions (`account.run`). This endpoint returns the matched block to the callback if a query is included, or the entire chain of the path if no query is provided.
|
|
118
141
|
|
|
119
142
|
See the [package source](https://github.com/immanuel-savvy/godprotocol.git) for more details.
|
|
120
143
|
|