godprotocol 1.0.81 → 1.0.83
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/.babelrc +3 -0
- package/Index.js +8 -19
- package/Loader_sequence/main.js +368 -234
- package/Objects/Account.js +229 -176
- package/Objects/Block.js +64 -61
- package/Objects/Blockweb.js +27 -34
- package/Objects/Chain.js +122 -118
- package/Objects/Explorer.js +30 -37
- package/Objects/Filesystem.js +96 -81
- package/Objects/Frame.js +43 -48
- package/Objects/Manager.js +60 -69
- package/Objects/Opcodes.js +39 -101
- package/Objects/Oracle.js +71 -69
- package/Objects/Virtual_machine.js +135 -132
- package/[object Object]/.GDS/godprotocol/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/0100dcacc00a6dc0263290e414f3d199b50f82b4dcbf9232b8a0bad9365d6878/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/03a089ffda6ca7be6e9327749c7417b3f759f4447de4dc1d8508c72571c8a46c/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817~9wMLAwapUgr25rjl~1721561106826 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817~xipvdPqJsd5PneYbcFNbJ0vQxthmu~1721561134383 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/0f4659b04f82c52bf8bf75ae0b4dc407574652ad35c84aa62ff4a52a868c7096/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/14fbd9082d61d0554e4917cb8e1b47966358762689a2bf021fc5e1dc38c7b239/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/221dbfff32f92e889762b6eb632423cbf51439fc16552940ee7ea7a2f92db662/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/2569577431a0c797f7526c5f2c59251343a1131adfd03f53363725951b7fd0d4/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/2743cfe8f897cdd0b22cb93cfd18fc58269705169bf0a01117edd1894cdce537/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/30dc10d3485923c0c19083559094fe636f9491bff9c997306ffdbf3e1618a402/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/30dc10d3485923c0c19083559094fe636f9491bff9c997306ffdbf3e1618a402/30dc10d3485923c0c19083559094fe636f9491bff9c997306ffdbf3e1618a402~5BrzgFCkRU4H7Cmlht1UyjorCm~1721561134375 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/30dc10d3485923c0c19083559094fe636f9491bff9c997306ffdbf3e1618a402/30dc10d3485923c0c19083559094fe636f9491bff9c997306ffdbf3e1618a402~VMHaNZbDCtpoSB~1721561106813 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/3ef66e0b0e059670edfa53a5c505196a5bc451d3c9e3a1b71f58519ca3c86146/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da~GJVjeKlgSCUdKGWUJ~1721561134114 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da~OsMwcPCk8F5SaSUdCGmM6~1721561106561 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/40149a5ceadd07e7cadcbad839efd7e1ac2a14b3d4a17dfa70aeff14778ed820/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/4503206d1cc4cdcef228061891a7a54a6a9838dce526bc4d755b0762d0da896b/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/4dc569813ce0a2f446a3eec01358f5774f8564641ef8d579ff5b6d94b4d031a7/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/4dc569813ce0a2f446a3eec01358f5774f8564641ef8d579ff5b6d94b4d031a7/4dc569813ce0a2f446a3eec01358f5774f8564641ef8d579ff5b6d94b4d031a7~8dBekgqAvRnIyZomf~1721561134269 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/4dc569813ce0a2f446a3eec01358f5774f8564641ef8d579ff5b6d94b4d031a7/4dc569813ce0a2f446a3eec01358f5774f8564641ef8d579ff5b6d94b4d031a7~Zc7Fa5AIsUySTCcWEiXmmYg3~1721561106712 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/54b16422271d6924c17c2abf55806035f5f36d4f4edb7f68bdd326bdb0abe500/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/57551ba66193cbc4696ca16cc27e9ccb73b79ddfae6b10fdf382747099033f3f/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/57d351527a4e63d51d13771038ac9ad59810f01960cc74b0f18158de872a20cc/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/5f87c4e573fa678825d72d8009f9aacce94d94bade4a26123db3c9e3a7488dc8/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/60fe28ac093915ec5e5cd08cb71650e3dab0e4c3644c32dd1ab13672f828f073/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/61bdf0593cd727752cb917ab968a08853d45142b8a8e4cdcd0fe03d1616f3586/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/61f3b3350c0c092e4c864b1a8c94f8b9272a132b100f8a5eb3a2e54dd20983be/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/646f04e302b372dc14871693fd87b6f80575c48f0045276f1a2b3ff999ae45fb/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/695853d02abbfe2f2a380598a871741caafa602d096a45adbe863e8f7e72f255/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/75944e73a11a149023ecf3430316a2b301a0b72c00cbd0b129f62b0f96e02f32/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/787456fe235bf126b6299374ecedb92c54e280238e67a2bed7446ff581cb6a6f/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/81e5bdff5d308919377d7d85da689f6888cbdc61b3ca73e18648fd7c365d4684/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/83e0dcafe93e39fa0973ee663d38477b5302704f4aca728b8701a919675340db/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/88f7c75e6701c06b4ffa070f7b4bab01c1aee299140234cf06fd83bf1a6af372/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/a965464a6d9f981543ce3aede226bd0fb989d9300cd8468f41cd1fc0139c8f44/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/a965464a6d9f981543ce3aede226bd0fb989d9300cd8468f41cd1fc0139c8f44/a965464a6d9f981543ce3aede226bd0fb989d9300cd8468f41cd1fc0139c8f44~2pZyTBlnZEjqeqLRX49qa~1721561134187 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/a965464a6d9f981543ce3aede226bd0fb989d9300cd8468f41cd1fc0139c8f44/a965464a6d9f981543ce3aede226bd0fb989d9300cd8468f41cd1fc0139c8f44~GacmVaFxSmu5yLRhGW4kvf~1721561106631 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/b15dcc79636744d7df8a3e28bfb9551bbb2f766d3e93885964ee4cda0070ec5d/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/b6d738d96a23a2b0638541041328e58895358c5ef9c21e2f8304939bff3e27f2/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/b6d738d96a23a2b0638541041328e58895358c5ef9c21e2f8304939bff3e27f2/b6d738d96a23a2b0638541041328e58895358c5ef9c21e2f8304939bff3e27f2~rB45nHr3uT34~1721561106844 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/b6d738d96a23a2b0638541041328e58895358c5ef9c21e2f8304939bff3e27f2/b6d738d96a23a2b0638541041328e58895358c5ef9c21e2f8304939bff3e27f2~tmfqGhOsoJv91mdvgo5~1721561134385 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/blocks/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/c9c105370802042618805ccac28f7d9aaaf49db9873e14eb7a4e74a73f3cce89/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/cac2db27e0f3f0e4c80a3c28aea1fee8b935d0a41f2384f4a90acb57a888ac22/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/cbf8ec551d71fc89a73768c65a6c0d630cd3d85fe88dcab7d6b45ea6bd6a9e33/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/d479db3b8a1efa0e6ac5106c1aba0b6b806744df0f6a4730c0b9f6a01cac8a33/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/de551b5a493859e532316cbbf1e4a14eb06e0512556b1c1295ad60ffe07c185b/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f0ffe7cc032479994c0732c6a65b7887c09afafb1b0aa20062ccad2810d25101/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f13022c98357d9d9da982270f21ce304af3d89fecbf9364ab0a00a87e39bde57/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f3184b1d23adf18ef18e5d3f6e6978a77364642eef9edba0240b77d626334235/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f8a165e3f556ca2ea189f4d4401d139b22a6f19d0b38329fe4a5f14599840634/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7~3EOv6CEb1xPUw8~1721561134016 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7~DEp3QlIt6A44WxAccRmf~1721561106464 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/fcc2a595781c53a76c4cd54382d3758d15120d3c4fcfae30f86067f8e6a830a2/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/fce39acf93dd6bdd9bc2e28288fd5b1c3c3c23313fe8527ec1d4d32a0081c94f/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/fda5b539dcb04ba96e6e929d05d8df7b42316351de91f2d33b66edb97ede4dc5/.config +1 -0
- package/build/Account.js +187 -0
- package/build/Block.js +68 -0
- package/build/Blockweb.js +36 -0
- package/build/Chain.js +119 -0
- package/build/Explorer.js +47 -0
- package/build/Filesystem.js +127 -0
- package/build/Frame.js +52 -0
- package/build/Index.js +20 -0
- package/build/Manager.js +86 -0
- package/build/Opcodes.js +109 -0
- package/build/Oracle.js +81 -0
- package/build/Virtual_machine.js +136 -0
- package/build/add.js +26 -0
- package/build/create_server.js +132 -0
- package/build/framer.js +59 -0
- package/build/functions.js +82 -0
- package/build/hash.js +14 -0
- package/build/indices.js +31 -0
- package/build/jmp.js +19 -0
- package/build/main.js +327 -0
- package/build/opcodes.js +60 -0
- package/build/privacy.js +27 -0
- package/build/services.js +50 -0
- package/build/std.js +15 -0
- package/framer.js +36 -34
- package/opcodes/add.js +9 -25
- package/opcodes/indices.js +13 -16
- package/opcodes/jmp.js +7 -12
- package/opcodes/std.js +7 -13
- package/opcodes.js +34 -42
- package/package.json +1 -1
- package/readme.md +4 -4
- package/utils/create_server.js +72 -105
- package/utils/functions.js +31 -43
- package/utils/hash.js +10 -11
- package/utils/privacy.js +10 -15
- package/utils/services.js +32 -33
package/Objects/Account.js
CHANGED
|
@@ -1,187 +1,240 @@
|
|
|
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
|
-
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(program, signature, callback)) return;
|
|
64
|
-
var pid = account.manage_buffer(callback);
|
|
65
|
-
_this.manager.push({
|
|
66
|
-
sequence: instructions,
|
|
67
|
-
account: account,
|
|
68
|
-
pid: pid
|
|
1
|
+
import Loader_sequence from "../Loader_sequence/main";
|
|
2
|
+
import validate_signature from "../utils/privacy";
|
|
3
|
+
import { post_request } from "../utils/services";
|
|
4
|
+
import Filesystem from "./Filesystem";
|
|
5
|
+
import Virtual_machine from "./Virtual_machine";
|
|
6
|
+
|
|
7
|
+
class Account extends Filesystem {
|
|
8
|
+
constructor(name, meta = {}) {
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
meta = meta || {};
|
|
12
|
+
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.private = meta.private;
|
|
15
|
+
this.manager = meta.manager;
|
|
16
|
+
this.account = this;
|
|
17
|
+
this.stdin = new Array();
|
|
18
|
+
this.stdout = new Array();
|
|
19
|
+
|
|
20
|
+
if (!this.manager) throw new Error("Manager instance missing.");
|
|
21
|
+
|
|
22
|
+
this.name_hash();
|
|
23
|
+
this.physical_address = `${this.base_address}/${this.name}`;
|
|
24
|
+
this.set_paths(this);
|
|
25
|
+
|
|
26
|
+
this.assembler = new Loader_sequence(this);
|
|
27
|
+
|
|
28
|
+
this.chain = this.account_chain(this);
|
|
29
|
+
this.vm = new Virtual_machine(this.chain);
|
|
30
|
+
|
|
31
|
+
this.mine_buffer = {};
|
|
32
|
+
this.privileges = new Object();
|
|
33
|
+
|
|
34
|
+
console.log(`Account Instance: ${this.name}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
propagate = (data, endpoint) => {
|
|
38
|
+
if (data.is_propagated) return;
|
|
39
|
+
|
|
40
|
+
let servers = this.privileges[endpoint];
|
|
41
|
+
|
|
42
|
+
data.is_propagated = true;
|
|
43
|
+
data = JSON.stringify(data);
|
|
44
|
+
|
|
45
|
+
if (servers && servers.length) {
|
|
46
|
+
servers.map((serv) => {
|
|
47
|
+
post_request({
|
|
48
|
+
options: {
|
|
49
|
+
...serv,
|
|
50
|
+
path: `/${endpoint}`,
|
|
51
|
+
},
|
|
52
|
+
data,
|
|
53
|
+
});
|
|
69
54
|
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
add_server = ({ server, privileges }) => {
|
|
59
|
+
if (!Array.isArray(privileges) && privileges)
|
|
60
|
+
privileges = ["load", "parse", "run", "create_account"];
|
|
61
|
+
|
|
62
|
+
privileges.map((privilege) => {
|
|
63
|
+
let priv = this.privileges[privilege];
|
|
64
|
+
if (!priv) {
|
|
65
|
+
priv = [];
|
|
66
|
+
this.privileges[privilege] = priv;
|
|
67
|
+
}
|
|
68
|
+
if (!priv.find((serv) => serv.domain === server.domain))
|
|
69
|
+
priv.push(server);
|
|
70
70
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
get_account = (name) => {
|
|
74
|
+
return this.manager.get_account(name) || this;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
manage_buffer = (callback) => {
|
|
78
|
+
let call_session = `${Date.now()}-${Math.random()}`;
|
|
79
|
+
this.mine_buffer[call_session] = { blocks: [], callback };
|
|
80
|
+
|
|
81
|
+
return call_session;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
buff = (block, pid) => {
|
|
85
|
+
let buffer = this.mine_buffer[pid];
|
|
86
|
+
if (!buffer) return;
|
|
87
|
+
|
|
88
|
+
buffer.blocks.push(block.stringify());
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
flush_buffer = (pid) => {
|
|
92
|
+
let buff = this.mine_buffer[pid];
|
|
93
|
+
if (!buff) return;
|
|
94
|
+
|
|
95
|
+
buff.callback && this.run_callback(buff.callback, buff.blocks);
|
|
96
|
+
delete this.mine_buffer[pid];
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
load = (payload) => {
|
|
100
|
+
let { program, signature, callback } = payload;
|
|
101
|
+
let { instructions, account } = program;
|
|
102
|
+
account = this.get_account(account);
|
|
103
|
+
account.propagate(payload, "load");
|
|
104
|
+
|
|
105
|
+
if (!account.validate(program, signature, callback)) return;
|
|
106
|
+
|
|
107
|
+
let pid = account.manage_buffer(callback);
|
|
108
|
+
|
|
109
|
+
this.manager.push({ sequence: instructions, account, pid });
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
parse = (program) => {
|
|
113
|
+
let { payload, signature, callback } = program;
|
|
114
|
+
let { physical_address, account, query } = payload;
|
|
115
|
+
account = this.get_account(account);
|
|
116
|
+
this.propagate(program, "parse");
|
|
117
|
+
|
|
118
|
+
if (!account.validate(payload, signature))
|
|
119
|
+
return this.run_callback(callback, {
|
|
120
|
+
private: account.private,
|
|
81
121
|
error: true,
|
|
82
|
-
error_message: "Invalid signature"
|
|
122
|
+
error_message: "Invalid signature",
|
|
83
123
|
});
|
|
84
|
-
|
|
85
|
-
|
|
124
|
+
|
|
125
|
+
let chain = account.manager.web.get(physical_address);
|
|
126
|
+
|
|
127
|
+
if (!chain)
|
|
128
|
+
return this.run_callback(callback, {
|
|
86
129
|
error: true,
|
|
87
|
-
error_message: "Address not found"
|
|
130
|
+
error_message: "Address not found",
|
|
88
131
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
132
|
+
|
|
133
|
+
let data = query ? chain.explore(query) : chain;
|
|
134
|
+
|
|
135
|
+
this.run_callback(callback, data && data.stringify());
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
run = (request) => {
|
|
139
|
+
let { payload, signature, callback } = request;
|
|
140
|
+
|
|
141
|
+
let { physical_address, account, query } = payload;
|
|
142
|
+
account = this.get_account(account);
|
|
143
|
+
account.propagate(request, "run");
|
|
144
|
+
|
|
145
|
+
if (!account.validate(payload, signature, callback)) return;
|
|
146
|
+
|
|
147
|
+
let pid = account.manage_buffer(callback);
|
|
148
|
+
|
|
149
|
+
let context = physical_address
|
|
150
|
+
? this.manager.web.get(physical_address)
|
|
151
|
+
: account.vm.get_context();
|
|
152
|
+
|
|
153
|
+
if (!context) return account.flush_buffer(pid);
|
|
154
|
+
|
|
155
|
+
let blk = query ? context.explore(query) : context.get_latest_block();
|
|
156
|
+
|
|
157
|
+
if (blk && blk.metadata && blk.metadata.program) {
|
|
158
|
+
let program = this.read(blk.metadata.program);
|
|
159
|
+
|
|
160
|
+
account.vm.contexts.push(context);
|
|
161
|
+
program.push("pop");
|
|
162
|
+
|
|
163
|
+
Array.isArray(program) &&
|
|
164
|
+
program.length &&
|
|
165
|
+
this.manager.push({
|
|
110
166
|
sequence: program,
|
|
111
|
-
account
|
|
112
|
-
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);
|
|
167
|
+
account,
|
|
168
|
+
pid,
|
|
122
169
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
170
|
+
} else account.flush_buffer(pid);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
run_callback = (callback, payload) => {
|
|
174
|
+
setTimeout(() => {
|
|
175
|
+
if (!callback) return;
|
|
176
|
+
|
|
177
|
+
if (typeof callback === "function") return callback(payload);
|
|
178
|
+
|
|
179
|
+
callback.payload &&
|
|
180
|
+
callback.payload.physical_address &&
|
|
181
|
+
this.vm.stdin(payload, () => this.run(callback));
|
|
182
|
+
}, 0);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
flush_stdout = (block) => {
|
|
186
|
+
for (let s = 0; s < this.stdout.length; s++) {
|
|
187
|
+
let out = this.stdout[s];
|
|
188
|
+
if (out.pid === this.vm.track.pid) {
|
|
189
|
+
block.metadata.stdout.push(out.data);
|
|
190
|
+
this.stdout[s] = null;
|
|
132
191
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
192
|
+
}
|
|
193
|
+
this.stdout = this.stdout.filter((out) => !!out);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
validate = (payload, signature, callback) => {
|
|
197
|
+
if (!this.private) return true;
|
|
198
|
+
|
|
199
|
+
let valid = validate_signature(
|
|
200
|
+
this.name,
|
|
201
|
+
JSON.stringify(payload),
|
|
202
|
+
signature
|
|
203
|
+
);
|
|
204
|
+
if (!valid && callback)
|
|
205
|
+
this.run_callback(callback, {
|
|
206
|
+
private: this.private,
|
|
142
207
|
error: true,
|
|
143
|
-
error_message: "Invalid signature"
|
|
208
|
+
error_message: "Invalid signature",
|
|
144
209
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
_this.set_paths(_assertThisInitialized(_this));
|
|
177
|
-
_this.assembler = new _main["default"](_assertThisInitialized(_this));
|
|
178
|
-
_this.chain = _this.account_chain(_assertThisInitialized(_this));
|
|
179
|
-
_this.vm = new _Virtual_machine["default"](_this.chain);
|
|
180
|
-
_this.mine_buffer = {};
|
|
181
|
-
console.log("Account Instance: ".concat(_this.name));
|
|
182
|
-
return _this;
|
|
183
|
-
}
|
|
184
|
-
return _createClass(Account);
|
|
185
|
-
}(_Filesystem2["default"]);
|
|
186
|
-
var _default = Account;
|
|
187
|
-
exports["default"] = _default;
|
|
210
|
+
|
|
211
|
+
return valid;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
stringify = (str) => {
|
|
215
|
+
let obj = {};
|
|
216
|
+
|
|
217
|
+
obj.name = this.name;
|
|
218
|
+
obj.hash = this.hash;
|
|
219
|
+
obj.path = this.path;
|
|
220
|
+
obj.private = this.private;
|
|
221
|
+
obj.chain = this.chain.stringify();
|
|
222
|
+
obj.physical_address = this.physical_address;
|
|
223
|
+
|
|
224
|
+
return str ? JSON.stringify(obj) : obj;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
create_account = (payload) => {
|
|
228
|
+
this.propagate(payload, "create_account");
|
|
229
|
+
let { name, meta } = payload;
|
|
230
|
+
|
|
231
|
+
return this.manager.add_account(name, meta);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
endpoint = (endpoint, payload) => {
|
|
235
|
+
let method = this[endpoint];
|
|
236
|
+
typeof method === "function" && method(payload);
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export default Account;
|
package/Objects/Block.js
CHANGED
|
@@ -1,68 +1,71 @@
|
|
|
1
|
-
|
|
1
|
+
import { hash } from "../utils/hash";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (!no_curs)
|
|
3
|
+
class Block {
|
|
4
|
+
constructor(chain) {
|
|
5
|
+
this.chain = chain;
|
|
6
|
+
this.data = this.chain.txs;
|
|
7
|
+
this.metadata = {};
|
|
8
|
+
this.children = new Array();
|
|
9
|
+
this.index = this.chain.blocks.length;
|
|
10
|
+
|
|
11
|
+
this.blocks_folder = this.chain.account.manager.oracle.gds.folder(
|
|
12
|
+
process.env.BLOCKS_FOLDER || "blocks"
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
generate_hash = () => {
|
|
17
|
+
this.previous_hash = this.chain.get_latest_block();
|
|
18
|
+
if (this.previous_hash) this.previous_hash = this.previous_hash.hash;
|
|
19
|
+
|
|
20
|
+
this.hash = hash(JSON.stringify(this.data));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
store = (no_curs) => {
|
|
24
|
+
let content = this.chain.buffs.splice(-1)[0];
|
|
25
|
+
if (!no_curs) this.cursor = this.chain.cursors.splice(-1)[0];
|
|
26
26
|
if (!content) return;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
|
|
28
|
+
let cursors = Object.keys(content).filter(
|
|
29
|
+
(c) => c.startsWith("{") && c.endsWith("}")
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
for (let c = 0; c < cursors.length; c++) {
|
|
33
|
+
let curs = cursors[c];
|
|
34
|
+
|
|
35
|
+
this.metadata[curs.slice(1, -1)] = content[curs];
|
|
33
36
|
delete content[curs];
|
|
34
37
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
obj
|
|
44
|
-
|
|
45
|
-
obj.
|
|
46
|
-
obj.
|
|
47
|
-
obj.
|
|
48
|
-
obj.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
this.metadata.stdout = new Array();
|
|
39
|
+
this.chain.account.flush_stdout(this);
|
|
40
|
+
|
|
41
|
+
let datapath = this.chain.account.save(content, this.chain);
|
|
42
|
+
this.datapath = datapath;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
stringify = (str) => {
|
|
46
|
+
let obj = {};
|
|
47
|
+
|
|
48
|
+
obj.metadata = this.metadata;
|
|
49
|
+
obj.datapath = this.datapath;
|
|
50
|
+
obj.timelapse = this.timelapse;
|
|
51
|
+
obj.index = this.index;
|
|
52
|
+
obj.hash = this.hash;
|
|
53
|
+
obj.data = this.data;
|
|
54
|
+
obj.children = this.children.map(
|
|
55
|
+
(ch) =>
|
|
56
|
+
new Object({
|
|
57
|
+
hash: ch.hash,
|
|
58
|
+
chain: ch.chain.hash,
|
|
59
|
+
physical_address: ch.chain.physical_address,
|
|
60
|
+
})
|
|
61
|
+
);
|
|
55
62
|
obj.chain = {
|
|
56
|
-
hash:
|
|
57
|
-
physical_address:
|
|
63
|
+
hash: this.chain.hash,
|
|
64
|
+
physical_address: this.chain.physical_address,
|
|
58
65
|
};
|
|
66
|
+
|
|
59
67
|
return str ? JSON.stringify(obj) : obj;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.children = new Array();
|
|
65
|
-
this.index = this.chain.blocks.length;
|
|
66
|
-
});
|
|
67
|
-
var _default = Block;
|
|
68
|
-
exports["default"] = _default;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default Block;
|
package/Objects/Blockweb.js
CHANGED
|
@@ -1,36 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 Blockweb = /*#__PURE__*/_createClass(function Blockweb(mgr) {
|
|
17
|
-
var _this = this;
|
|
18
|
-
_classCallCheck(this, Blockweb);
|
|
19
|
-
_defineProperty(this, "get", function (addr) {
|
|
20
|
-
var hash = _this.physical_addresses[addr];
|
|
21
|
-
var chain = _this.chains[hash];
|
|
1
|
+
import Chain from "./Chain";
|
|
2
|
+
|
|
3
|
+
class Blockweb {
|
|
4
|
+
constructor(mgr) {
|
|
5
|
+
this.mgr = mgr;
|
|
6
|
+
this.physical_addresses = new Object();
|
|
7
|
+
this.chains = new Object();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get = (addr) => {
|
|
11
|
+
let hash = this.physical_addresses[addr];
|
|
12
|
+
|
|
13
|
+
let chain = this.chains[hash];
|
|
14
|
+
|
|
22
15
|
return chain;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
set = (parent, name) => {
|
|
19
|
+
let chain = new Chain(parent, name);
|
|
20
|
+
this.chains[chain.hash] = chain;
|
|
21
|
+
|
|
22
|
+
this.physical_addresses[chain.physical_address] = chain.hash;
|
|
23
|
+
this.chains[chain.hash] = chain;
|
|
24
|
+
|
|
29
25
|
return chain;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
var _default = Blockweb;
|
|
36
|
-
exports["default"] = _default;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default Blockweb;
|