godprotocol 1.0.75 → 1.0.76

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.
@@ -1,4 +1,5 @@
1
1
  import Aircode from "../Aircode/main";
2
+ import start from "../Index";
2
3
  import { hash } from "../utils/hash";
3
4
  import { post_request } from "../utils/services";
4
5
  import Chain from "./Chain";
@@ -47,35 +48,33 @@ class Account extends Filesystem {
47
48
  return account || this;
48
49
  };
49
50
 
50
- manage_buffer = () => {
51
+ manage_buffer = (cb) => {
51
52
  let call_session = `${Date.now()}-${Math.random()}`;
52
- this.mine_buffer[call_session] = [];
53
+ this.mine_buffer[call_session] = { blocks: [], cb };
53
54
 
54
55
  return call_session;
55
56
  };
56
57
 
57
58
  buff = (block, pid) => {
58
- let blks = this.mine_buffer[pid];
59
- if (!blks) return;
59
+ let bf = this.mine_buffer[pid];
60
+ if (!bf) return;
60
61
 
61
- blks.push(block.stringify());
62
+ bf.blocks.push(block.stringify());
62
63
  };
63
64
 
64
- flush_buffer = (cb, pid) => {
65
- let blocks = this.mine_buffer[pid];
65
+ flush_buffer = (pid) => {
66
+ let buff = this.mine_buffer[pid];
66
67
 
67
- cb && cb(blocks);
68
+ buff.cb && buff.cb(buff.blocks);
68
69
  delete this.mine_buffer[pid];
69
70
  };
70
71
 
71
72
  load = ({ instructions, account }, cb) => {
72
73
  account = this.get_account(account);
73
74
 
74
- let pid = account.manage_buffer();
75
+ let pid = account.manage_buffer(cb);
75
76
 
76
77
  this.manager.push({ sequence: instructions, account, pid });
77
-
78
- account.flush_buffer(cb, pid);
79
78
  };
80
79
 
81
80
  parse = ({ physical_address, account, query }, cb) => {
@@ -92,19 +91,17 @@ class Account extends Filesystem {
92
91
  run = ({ account, query, physical_address }, cb) => {
93
92
  account = this.get_account(account);
94
93
 
95
- let pid = account.manage_buffer();
94
+ let pid = account.manage_buffer(cb);
96
95
 
97
96
  let context = physical_address
98
97
  ? this.manager.web.get({ physical_address }, true)
99
98
  : account.vm.get_context();
100
99
 
101
- if (!context) return account.flush_buffer(cb, pid);
100
+ if (!context) return account.flush_buffer(pid);
102
101
 
103
102
  let blk = query ? context.explore(query) : context.get_block(0);
104
103
 
105
104
  blk && this.manager.push({ sequence: blk.data, account, pid });
106
-
107
- account.flush_buffer(cb, pid);
108
105
  };
109
106
 
110
107
  add_server = (server) => {
@@ -167,7 +164,7 @@ class Account extends Filesystem {
167
164
  let account = this.accounts[name] || this.manager.accounts[name];
168
165
 
169
166
  if (!account) {
170
- account = new Account(name, this.manager);
167
+ account = start(name, server);
171
168
  this.accounts[account.name] = account;
172
169
  this.manager.accounts[account.name] = account;
173
170
  }
package/Objects/Chain.js CHANGED
@@ -78,6 +78,7 @@ class Chain extends Explorer {
78
78
  let obj = {};
79
79
 
80
80
  obj.physical_address = this.physical_address;
81
+ obj.height = this.blocks.length;
81
82
  obj.parent = this.parent.path;
82
83
  obj.account = this.parent.account.name;
83
84
  obj.name = this.name;
@@ -4,6 +4,9 @@ class Explorer {
4
4
  chain_props = ["blocks"];
5
5
 
6
6
  explore = (query) => {
7
+ if (!query) return;
8
+
9
+ if (query.startsWith("{")) query = query.slice(1, -1);
7
10
  query = query.split(":");
8
11
 
9
12
  query[0] = query[0].split(".");
@@ -21,8 +21,15 @@ class Manager {
21
21
  track.account.vm.execute(instruction, track);
22
22
  track.pointer++;
23
23
 
24
+ if (track.breakpoint.slice(-1)[0] === track.pointer) {
25
+ track.account.flush_buffer(track.pid);
26
+ track.pid = track.pids.splice(-1)[0];
27
+ }
28
+
24
29
  if (track.pointer === track.sequence.length) {
25
30
  this.total--;
31
+ track.account.flush_buffer(track.pid);
32
+
26
33
  delete this.tracks[account];
27
34
  }
28
35
  }
@@ -38,12 +45,20 @@ class Manager {
38
45
  let track = this.tracks[program.account.name];
39
46
 
40
47
  if (!track) {
41
- track = { ...program, sequence: [...program.sequence], pointer: 0 };
48
+ track = {
49
+ ...program,
50
+ sequence: [...program.sequence],
51
+ pointer: 0,
52
+ pids: [program.pid],
53
+ breakpoint: new Array(),
54
+ };
42
55
  this.tracks[track.account.name] = track;
43
56
  this.total++;
44
57
  this.total === 1 && this.start_clock();
45
58
  } else {
59
+ track.breakpoint.push(track.pointer + 1);
46
60
  track.sequence.splice(track.pointer + 1, 0, ...program.sequence);
61
+ track.pids.push(program.pid);
47
62
  }
48
63
  };
49
64
  }
@@ -53,6 +53,17 @@ class Virtual_machine extends Opcodes {
53
53
  return arg;
54
54
  };
55
55
 
56
+ run_block = () => {
57
+ if (!this.running) return;
58
+
59
+ let context = this.get_context();
60
+ let instructions = [];
61
+ for (let b = 0; b < context.blocks.length; b++) {
62
+ let blk = context.blocks[b];
63
+ // let last_ blk.data.slice(-1)[0]
64
+ }
65
+ };
66
+
56
67
  execute = (instruction, track) => {
57
68
  this.track = track;
58
69
 
@@ -79,6 +90,7 @@ class Virtual_machine extends Opcodes {
79
90
  chain = context.parent.add_chain(args);
80
91
  this.contexts.push(chain);
81
92
 
93
+ this.run_block();
82
94
  chain.append_buffer();
83
95
 
84
96
  break;
@@ -95,6 +107,7 @@ class Virtual_machine extends Opcodes {
95
107
  chain.append_buffer();
96
108
 
97
109
  this.contexts.push(chain);
110
+ this.run_block();
98
111
 
99
112
  break;
100
113
  case "listen":
@@ -107,7 +120,9 @@ class Virtual_machine extends Opcodes {
107
120
 
108
121
  break;
109
122
  case "run":
123
+ this.running = true;
110
124
  this.account.run({ query: original_arg }, this.stdin);
125
+ this.running = false;
111
126
  break;
112
127
  case "pop":
113
128
  let blk;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "godprotocol",
3
- "version": "1.0.75",
3
+ "version": "1.0.76",
4
4
  "description": "A data mediator.",
5
5
  "main": "Index.js",
6
6
  "types": "index.d.ts",
package/readme.md ADDED
@@ -0,0 +1,126 @@
1
+ # God Protocol
2
+
3
+ ### A data mediator
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ npm install godprotocol --save
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ You can get overall comprehension in just 4 method calls.
14
+
15
+ ### Create an Account
16
+
17
+ Accounts comes with their own VM, thereby providing concurrency on processes being executed.
18
+
19
+ ```js
20
+ import { start } from "godprotocol";
21
+
22
+ // Create an initial account
23
+ let initiator = start(`public_key`, { private: true | false });
24
+ // if private is set to `true`, communication to the account instance must be validated by sigining with the private key.
25
+ // N.B your keypairs are generated offline.
26
+ ```
27
+
28
+ | `Parameters` | Type | Description |
29
+ | ------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
30
+ | `name` | string | Account names can be any valid variable string. Such as a Public Key |
31
+ | `private` | object:boolean | default `false`, if set to true, then any payloads sent to the account must be signed using the private key belonging to the account `name` |
32
+
33
+ ### Load Instructions
34
+
35
+ The load method is the second in the pipeline,
36
+ It is used to set your programs into the network web,
37
+ where its data can continue to be accessed, and subsequent
38
+ calls can be made on the loaded program.
39
+
40
+ ## Usage
41
+
42
+ ```js
43
+ initiator.load(
44
+ {
45
+ instructions: ["link Account/initiator/Datatypes/Number", "write 7", "pop"],
46
+ account: `public_key`,
47
+ },
48
+ cb
49
+ );
50
+ ```
51
+
52
+ Type `method`
53
+
54
+ | `Parameters` | Type | Destructure | Description |
55
+ | ------------ | -------- | -------------- | -------------------------------------------------------------------------------------------------------------------- |
56
+ | `program` | object | `instructions` | An array of opcode-operands generated by the [`Loader Sequence`](https://godprotocol-web.vercel.app/loader_sequence) |
57
+ | | | `account` | Account instance to load and execute the program in. |
58
+ | `cb` | function | | A function that is called with the blocks mined during the execution. |
59
+
60
+ ### Run Program
61
+
62
+ The run is technically the second in the pipeline.
63
+
64
+ ## Usage
65
+
66
+ ```js
67
+ initiator.run(
68
+ {
69
+ physical_address: "Account/initiator/Datatypes/Number", // This points to a chain
70
+ query: { blocks: 0 }, // Basically saying, index 0 block in physical_address chain, run again its instructions.
71
+ account: `public_key`,
72
+ },
73
+ cb
74
+ );
75
+ // N.B If query is missing, then VM starts execution from the block-index-0
76
+ ```
77
+
78
+ Type `method`
79
+
80
+ | `Parameters` | Type | Destructure | Description |
81
+ | ------------ | -------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
82
+ | `payload` | object | `physical_address` | [`Physical Addresses`](https://godprotocol-web.vercel.app/physical_address) are logical namespace locations of tokens. They are derived from the high-level representation of the program's instructions. |
83
+ | | | `query` | A valid blockweb explorer query, you can read the explorer documentation [here](https://godprotocol-web.vercel.app/explorer) |
84
+ | | | `account` | Account instance to execute the instructions in. |
85
+ | `cb` | function | | A function that is called with the blocks mined during the execution. |
86
+
87
+ ### Parse Result
88
+
89
+ The parse is technically the third of the pipeline. It takes like parameters as the `run` method.
90
+
91
+ ## Usage
92
+
93
+ It is used to read blocks and chains
94
+
95
+ ```js
96
+ initiator.parse(
97
+ {
98
+ physical_address: "Account/initiator/Datatypes/Number", // This points to a chain
99
+ query: { blocks: 0 }, // Basically saying, index 0 block in physical_address chain, retrieve it.
100
+ account: `public_key`,
101
+ },
102
+ cb
103
+ );
104
+ // N.B If query isn't provided, then you parse the chain.
105
+ ```
106
+
107
+ Type `method`
108
+
109
+ | `Parameters` | Type | Destructure | Description |
110
+ | ------------ | -------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
111
+ | `payload` | object | `physical_address` | [`Physical Addresses`](https://godprotocol-web.vercel.app/physical_address) are logical namespace locations of tokens. They are derived from the high-level representation of the program's instructions. |
112
+ | | object | `query` | A valid blockweb explorer query, you can read the explorer documentation [here](https://godprotocol-web.vercel.app/explorer) |
113
+ | | | `account` | Account instance to execute the instructions in. |
114
+ | `cb` | function | | A function that is called with the blocks mined during the execution. |
115
+
116
+ See the [package source](https://github.com/immanuel-savvy/godprotocol.git) for more details.
117
+
118
+ [npm-url]: https://npmjs.org/package/godprotocol
119
+ [downloads-url]: https://npmjs.org/package/godprotocol
120
+
121
+ ## References
122
+
123
+ [Web Documentation]('https://godprotocol-web.vercel.app')
124
+ [`Physical Addresses`](https://godprotocol-web.vercel.app/physical_address)
125
+ [Explorer](https://godprotocol-web.vercel.app/explorer)
126
+ [`Loader Sequence`](https://godprotocol-web.vercel.app/loader_sequence)
@@ -7,7 +7,7 @@ let PORT = 1901,
7
7
  const cb = (res, data) => {
8
8
  if (typeof data !== "string") data = JSON.stringify(data);
9
9
 
10
- res.end(data);
10
+ res(data);
11
11
  };
12
12
 
13
13
  const create_server = async (initiator, serve) => {
@@ -43,11 +43,11 @@ const create_server = async (initiator, serve) => {
43
43
  let account = initiator.create_account(data.name, data.server);
44
44
  res.end(account.stringify(true));
45
45
  } else if (req.url === "/load") {
46
- initiator.load(data, (datagram) => cb(res, datagram));
46
+ initiator.load(data, (datagram) => cb(res.end, datagram));
47
47
  } else if (req.url === "/parse") {
48
- initiator.parse(data, (datagram) => cb(res, datagram));
48
+ initiator.parse(data, (datagram) => cb(res.end, datagram));
49
49
  } else if (req.url === "/run") {
50
- initiator.run(data, (datagram) => cb(res, datagram));
50
+ initiator.run(data, (datagram) => cb(res.end, datagram));
51
51
  }
52
52
  if (serve && req.headers.host !== `${serve.domain}:${serve.port}`)
53
53
  console.log(`services:${req.url}`);