Skip to content

Commit

Permalink
feat: refactor protobufs and utils to remove grpc-js dependency (#798)
Browse files Browse the repository at this point in the history
* remove grpc-js dependency from protobufs, refactor hubble to use hub-nodejs

* hub-web to use @farcaster/protobufs and utils

* add yarn.lock

* refactor hubble app to only use hub-nodejs

* update readme

* update export order

* update export order

* fix protobufs namespace build issue

* update codecov

* fix protobufCommand naming

---------

Co-authored-by: Paul Fletcher-Hill <[email protected]>
  • Loading branch information
PangZhi and pfletcherhill authored Apr 4, 2023
1 parent 71d6494 commit 1f47906
Show file tree
Hide file tree
Showing 105 changed files with 11,117 additions and 6,059 deletions.
10 changes: 10 additions & 0 deletions .changeset/honest-news-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@farcaster/protobufs': minor
'@farcaster/hub-web': minor
'@farcaster/utils': minor
'@farcaster/hub-nodejs': patch
'@farcaster/hubble': patch
---

remove grpc-js dependency from protobufs, refactor hubble to use hub-nodejs
hub-web to use @farcaster/protobufs and utils
3 changes: 1 addition & 2 deletions apps/hubble/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
"dependencies": {
"@chainsafe/libp2p-gossipsub": "6.1.0",
"@chainsafe/libp2p-noise": "^11.0.0 ",
"@farcaster/protobufs": "0.1.11",
"@farcaster/utils": "0.4.0",
"@farcaster/hub-nodejs": "^0.6.0",
"@grpc/grpc-js": "~1.8.7",
"@libp2p/interface-connection": "^3.0.2",
"@libp2p/interface-peer-id": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/hubble/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import { FarcasterNetwork } from '@farcaster/protobufs';
import { FarcasterNetwork } from '@farcaster/hub-nodejs';
import { PeerId } from '@libp2p/interface-peer-id';
import { createEd25519PeerId, createFromProtobuf, exportToProtobuf } from '@libp2p/peer-id-factory';
import { Command } from 'commander';
Expand Down
7 changes: 3 additions & 4 deletions apps/hubble/src/console/adminCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as protobufs from '@farcaster/protobufs';
import { AdminRpcClient } from '@farcaster/utils';
import { AdminRpcClient, Empty } from '@farcaster/hub-nodejs';
import { ConsoleCommandInterface } from './console';

export class AdminCommand implements ConsoleCommandInterface {
Expand All @@ -21,15 +20,15 @@ export class AdminCommand implements ConsoleCommandInterface {
object() {
return {
rebuildSyncTrie: async () => {
const result = await this.adminClient.rebuildSyncTrie(protobufs.Empty.create());
const result = await this.adminClient.rebuildSyncTrie(Empty.create());
return result.match(
() => '',
(e) => `Error: ${e}`
);
},

deleteAllMessagesFromDb: async () => {
const result = await this.adminClient.deleteAllMessagesFromDb(protobufs.Empty.create());
const result = await this.adminClient.deleteAllMessagesFromDb(Empty.create());
return result.match(
() => '',
(e) => `Error: ${e}`
Expand Down
10 changes: 8 additions & 2 deletions apps/hubble/src/console/console.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Empty, Metadata } from '@farcaster/protobufs';
import { getAdminRpcClient, getAuthMetadata, getInsecureHubRpcClient, getSSLHubRpcClient } from '@farcaster/utils';
import {
Empty,
Metadata,
getAdminRpcClient,
getAuthMetadata,
getInsecureHubRpcClient,
getSSLHubRpcClient,
} from '@farcaster/hub-nodejs';
import path from 'path';
import * as repl from 'repl';
import { ADMIN_SERVER_PORT } from '~/rpc/adminServer';
Expand Down
19 changes: 13 additions & 6 deletions apps/hubble/src/console/genCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import * as protobufs from '@farcaster/protobufs';
import { AdminRpcClient, Factories, getAuthMetadata, HubRpcClient } from '@farcaster/utils';
import {
AdminRpcClient,
Factories,
getAuthMetadata,
HubRpcClient,
Metadata,
FarcasterNetwork,
Message,
} from '@farcaster/hub-nodejs';
import { ConsoleCommandInterface } from './console';

// We use console.log() in this file, so we disable the eslint rule. This is the REPL console, after all!
Expand Down Expand Up @@ -37,12 +44,12 @@ export class GenCommand implements ConsoleCommandInterface {
return {
submitMessages: async (
numMessages = 100,
network = protobufs.FarcasterNetwork.DEVNET,
username?: string | protobufs.Metadata,
network = FarcasterNetwork.DEVNET,
username?: string | Metadata,
password?: string
): Promise<string | SubmitStats> => {
// Submit messages might need a username/password
let metadata = new protobufs.Metadata();
let metadata = new Metadata();
if (username && typeof username !== 'string') {
metadata = username;
} else if (username && password) {
Expand Down Expand Up @@ -83,7 +90,7 @@ export class GenCommand implements ConsoleCommandInterface {
return `Failed to submit signer add message for fid ${fid}: ${signerResult.error}`;
}

const submitBatch = async (batch: protobufs.Message[]) => {
const submitBatch = async (batch: Message[]) => {
const promises = [];
for (const castAdd of batch) {
promises.push(this.rpcClient.submitMessage(castAdd, metadata));
Expand Down
6 changes: 3 additions & 3 deletions apps/hubble/src/console/protobufCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as protobufs from '@farcaster/protobufs';
import { Factories } from '@farcaster/utils';
import * as hubNodejs from '@farcaster/hub-nodejs';
import { Factories } from '@farcaster/hub-nodejs';
import { ConsoleCommandInterface } from './console';

export class ProtobufCommand implements ConsoleCommandInterface {
Expand All @@ -18,7 +18,7 @@ export class ProtobufCommand implements ConsoleCommandInterface {
`;
}
object() {
return protobufs;
return hubNodejs;
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/hubble/src/console/rpcClientCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HubRpcClient } from '@farcaster/utils';
import { HubRpcClient } from '@farcaster/hub-nodejs';
import { ConsoleCommandInterface } from './console';

export class RpcClientCommand implements ConsoleCommandInterface {
Expand Down
Loading

0 comments on commit 1f47906

Please sign in to comment.