Skip to content

Commit

Permalink
add buf gen config files; modified pb file; generated initial obj file
Browse files Browse the repository at this point in the history
  • Loading branch information
d-roak committed Jul 25, 2024
1 parent f11ccb7 commit 5e70d98
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 293 deletions.
10 changes: 10 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: v2
plugins:
- local: ./node_modules/ts-proto/protoc-gen-ts_proto
strategy: directory
out: ./packages
opt:
- esModuleInterop=true
- fileSuffix=_pb
inputs:
- directory: ./packages
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"scripts": {
"docs": "typedoc",
"proto-gen": "buf generate",
"release": "release-it",
"test": "vitest"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = "0.0.22-2";
export const VERSION = "0.0.22";
6 changes: 1 addition & 5 deletions packages/object/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@
"build": "tsc -b",
"clean": "rm -rf dist/ node_modules/",
"prepack": "tsc -b",
"protobuf": "buf generate",
"proto-gen": "buf generate",
"test": "vitest"
},
"dependencies": {
"protobufjs": "^7.3.2",
"ts-proto": "^1.181.1"
},
"devDependencies": {
"protobufjs-cli": "^1.1.2"
}
}
44 changes: 14 additions & 30 deletions packages/object/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
import * as crypto from "crypto";
import * as protobuf from "protobufjs";
import { TopologyObject } from "./proto/object_pb.js";

export abstract class TopologyObject {
// TODO generate functions from the abi
private abi?: string;
private id?: string;
export * from "./proto/index.js";

constructor(peerId: string) {
protobuf.load("abi.proto", (err, _) => {
if (err) {
throw err;
}
});
this.abi = "";
function newTopologyObject(peerId: string, abi?: string, bytecode?: string): TopologyObject {
const id = crypto
.createHash("sha256")
.update(abi ?? "")
.update(peerId)
.update(Math.floor(Math.random() * Number.MAX_VALUE).toString())
.digest("hex");

// id = sha256(abi, peer_id, random_nonce)
this.id = crypto
.createHash("sha256")
.update(this.abi)
.update(peerId)
.update(Math.floor(Math.random() * Number.MAX_VALUE).toString())
.digest("hex");
}

getObjectAbi(): string {
return this.abi ?? "";
}

getObjectId(): string {
return this.id ?? "";
}

abstract merge(other: TopologyObject): void;
return {
id,
abi: abi ?? "",
bytecode: bytecode ?? ""
};
}
1 change: 1 addition & 0 deletions packages/object/src/proto/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./object_pb.js";
4 changes: 1 addition & 3 deletions packages/object/src/proto/object.proto
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
syntax = "proto3"
syntax = "proto3";

package topology.object;

message TopologyObject {
string id = 1;
string abi = 2;
string bytecode = 3;


}
121 changes: 121 additions & 0 deletions packages/object/src/proto/object_pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/object/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"compilerOptions": {
"outDir": "dist"
},
"include": ["src/**/*.ts"]
"include": [
"src/**/*.ts"
]
}
Loading

0 comments on commit 5e70d98

Please sign in to comment.