godprotocol 1.0.74 → 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.
- package/Objects/Account.js +18 -16
- package/Objects/Chain.js +1 -0
- package/Objects/Explorer.js +3 -0
- package/Objects/Manager.js +16 -1
- package/Objects/Virtual_machine.js +17 -0
- package/package.json +1 -1
- package/readme.md +126 -0
- package/utils/create_server.js +4 -4
package/Objects/Account.js
CHANGED
|
@@ -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
|
|
59
|
-
if (!
|
|
59
|
+
let bf = this.mine_buffer[pid];
|
|
60
|
+
if (!bf) return;
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
bf.blocks.push(block.stringify());
|
|
62
63
|
};
|
|
63
64
|
|
|
64
|
-
flush_buffer = (
|
|
65
|
-
let
|
|
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(
|
|
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) => {
|
|
@@ -124,6 +121,11 @@ class Account extends Filesystem {
|
|
|
124
121
|
obj.servers = this.servers;
|
|
125
122
|
obj.name = this.name;
|
|
126
123
|
obj.data_tracks = this.data_tracks;
|
|
124
|
+
obj.hash = this.hash;
|
|
125
|
+
obj.chain = this.chain.stringify();
|
|
126
|
+
obj.physical_address = this.physical_address;
|
|
127
|
+
|
|
128
|
+
return obj;
|
|
127
129
|
};
|
|
128
130
|
|
|
129
131
|
distribute = (data) => {
|
|
@@ -162,7 +164,7 @@ class Account extends Filesystem {
|
|
|
162
164
|
let account = this.accounts[name] || this.manager.accounts[name];
|
|
163
165
|
|
|
164
166
|
if (!account) {
|
|
165
|
-
account =
|
|
167
|
+
account = start(name, server);
|
|
166
168
|
this.accounts[account.name] = account;
|
|
167
169
|
this.manager.accounts[account.name] = account;
|
|
168
170
|
}
|
package/Objects/Chain.js
CHANGED
package/Objects/Explorer.js
CHANGED
package/Objects/Manager.js
CHANGED
|
@@ -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 = {
|
|
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
|
|
|
@@ -66,6 +77,8 @@ class Virtual_machine extends Opcodes {
|
|
|
66
77
|
|
|
67
78
|
let context = this.get_context();
|
|
68
79
|
|
|
80
|
+
if (!context) return;
|
|
81
|
+
|
|
69
82
|
context.add_tx(instruction);
|
|
70
83
|
|
|
71
84
|
let chain;
|
|
@@ -77,6 +90,7 @@ class Virtual_machine extends Opcodes {
|
|
|
77
90
|
chain = context.parent.add_chain(args);
|
|
78
91
|
this.contexts.push(chain);
|
|
79
92
|
|
|
93
|
+
this.run_block();
|
|
80
94
|
chain.append_buffer();
|
|
81
95
|
|
|
82
96
|
break;
|
|
@@ -93,6 +107,7 @@ class Virtual_machine extends Opcodes {
|
|
|
93
107
|
chain.append_buffer();
|
|
94
108
|
|
|
95
109
|
this.contexts.push(chain);
|
|
110
|
+
this.run_block();
|
|
96
111
|
|
|
97
112
|
break;
|
|
98
113
|
case "listen":
|
|
@@ -105,7 +120,9 @@ class Virtual_machine extends Opcodes {
|
|
|
105
120
|
|
|
106
121
|
break;
|
|
107
122
|
case "run":
|
|
123
|
+
this.running = true;
|
|
108
124
|
this.account.run({ query: original_arg }, this.stdin);
|
|
125
|
+
this.running = false;
|
|
109
126
|
break;
|
|
110
127
|
case "pop":
|
|
111
128
|
let blk;
|
package/package.json
CHANGED
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)
|
package/utils/create_server.js
CHANGED
|
@@ -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
|
|
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}`);
|