godprotocol 1.0.3 → 1.0.4

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.
@@ -0,0 +1,36 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
+
4
+ name: Node.js Package
5
+
6
+ on:
7
+ release:
8
+ types: [created]
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: actions/setup-node@v3
16
+ with:
17
+ node-version: 16
18
+ - run: npm ci
19
+ - run: npm test
20
+
21
+ publish-gpr:
22
+ needs: build
23
+ runs-on: ubuntu-latest
24
+ permissions:
25
+ contents: read
26
+ packages: write
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+ - uses: actions/setup-node@v3
30
+ with:
31
+ node-version: 16
32
+ registry-url: https://npm.pkg.github.com/
33
+ - run: npm ci
34
+ - run: npm publish
35
+ env:
36
+ NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
package/Index.js CHANGED
@@ -5,50 +5,27 @@ import framer from "./framer";
5
5
  import opcodes from "./opcodes";
6
6
  import Socket_server from "./Socket";
7
7
  import { manage_key_pair } from "./utils/gen_key_pair";
8
+ import create_server, { PORT } from "./utils/create_server";
8
9
 
9
10
  manage_key_pair();
10
11
 
11
- let PORT = 1900;
12
-
13
12
  const initiator = new Account(process.env.PUBLIC_KEY);
14
- let server = process.env.SERVER;
13
+ let cli_server = process.env.SERVER;
15
14
 
16
- if (server) {
17
- initiator.add_server(server);
15
+ if (cli_server) {
16
+ initiator.add_server(cli_server);
18
17
  } else {
19
- console.warn("set SERVER in your env.");
20
- server = `http://localhost:${PORT}`;
21
- initiator.add_server(server);
18
+ // console.warn("set SERVER in your env.");
19
+ cli_server = `http://localhost:${PORT}`;
20
+ initiator.add_server(cli_server);
22
21
  }
23
22
 
24
23
  framer(initiator);
25
24
 
26
25
  opcodes(initiator);
27
26
 
28
- http
29
- .createServer((req, res) => {
30
- let data = "";
31
-
32
- req.on("data", (chunk) => {
33
- data += chunk;
34
- });
35
- req.on("end", () => {
36
- if (req.url === "/create_account") {
37
- console.log(data);
38
- initiator.account(data);
39
- } else {
40
- initiator.load(data);
41
- }
42
-
43
- res.end();
44
- });
45
- })
46
- .listen(PORT);
27
+ create_server(initiator);
47
28
 
48
29
  Socket_server();
49
30
 
50
31
  export { initiator };
51
-
52
- console.log(
53
- `\n...GOD PROTOCOL RUNNING :${PORT}\nYour Public_key: ${process.env.PUBLIC_KEY}`
54
- );
@@ -77,7 +77,8 @@ class Account {
77
77
  frame = (struct) => {
78
78
  let frame = new Frame(struct);
79
79
  frame.to_instruction();
80
- frame.load(this);
80
+
81
+ return frame;
81
82
  };
82
83
 
83
84
  load = ({ instructions, account }) => {
@@ -112,14 +113,14 @@ class Account {
112
113
  return account;
113
114
  };
114
115
 
115
- account = ({ public_key, server }) => {
116
+ create_account = ({ public_key, server }) => {
116
117
  let account = this.accounts[public_key];
117
118
  if (!account) {
118
119
  account = new Account(public_key);
119
120
 
120
121
  this.accounts[account.name] = account;
121
122
  }
122
- !account.server.includes(server) && account.server.push(server);
123
+ !account.servers.includes(server) && account.servers.push(server);
123
124
 
124
125
  return account;
125
126
  };
package/Socket.js CHANGED
@@ -8,6 +8,7 @@ let pendings = new Object();
8
8
 
9
9
  const Socket_server = () => {
10
10
  let server = net.createServer((socket) => {
11
+ console.log("meeeee");
11
12
  socket.on("connect", () => {
12
13
  Sockets[socket.id] = { socket };
13
14
  console.log(`New client connection - ${socket.id}`);
package/framer.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const framer = (initiator) => {
2
- initiator.frame({
2
+ let frame = initiator.frame({
3
3
  Opcodes: {
4
4
  add: null,
5
5
  equal: null,
@@ -33,6 +33,8 @@ const framer = (initiator) => {
33
33
  },
34
34
  },
35
35
  });
36
+
37
+ initiator.load({ instructions: frame.instructions });
36
38
  };
37
39
 
38
40
  export default framer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "godprotocol",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A data mediator.",
5
5
  "main": "Index.js",
6
6
  "types": "index.d.ts",
@@ -0,0 +1,42 @@
1
+ import http from "http";
2
+
3
+ let PORT = 1900;
4
+
5
+ const create_server = (initiator) => {
6
+ let server = http.createServer((req, res) => {
7
+ let data = "";
8
+
9
+ req.on("data", (chunk) => {
10
+ console.log("Received chunk");
11
+ data += chunk;
12
+ });
13
+
14
+ req.on("end", () => {
15
+ if (req.url === "/create_account" && req.method === "POST") {
16
+ initiator.create_account(data);
17
+ res.writeHead(200, { "Content-Type": "application/json" });
18
+ res.end(
19
+ JSON.stringify({ status: "success", message: "Account created" })
20
+ );
21
+ } else {
22
+ initiator.load(data);
23
+ res.writeHead(200, { "Content-Type": "application/json" });
24
+ res.end(JSON.stringify({ status: "success", message: "Data loaded" }));
25
+ }
26
+ });
27
+
28
+ req.on("error", (e) => {
29
+ res.writeHead(500, { "Content-Type": "application/json" });
30
+ res.end(JSON.stringify({ status: "error", message: e.message }));
31
+ });
32
+ });
33
+
34
+ server.listen(PORT, () => {
35
+ console.log(
36
+ `\n...GOD PROTOCOL RUNNING :${PORT}\nYour Public_key: ${process.env.PUBLIC_KEY}`
37
+ );
38
+ });
39
+ };
40
+
41
+ export default create_server;
42
+ export { PORT };