Skip to content

Commit

Permalink
Migrate from grpc to grpc-js.
Browse files Browse the repository at this point in the history
- Change app dependency from `"grpc"` to `"@grpc-js"`.
- Regenerate all proto files with `generate_package_definition` flag.
- Remove unused files `annotations_pb.js` and `http_pb.js`, and don't regenerate them `regen.sh`.
- In the `regen.sh` for LN protos, use protoc installed locally in node_modules rather than one provided by the system.
  • Loading branch information
jholdstock committed Nov 14, 2020
1 parent 1b7e37b commit bf22f2f
Show file tree
Hide file tree
Showing 15 changed files with 1,380 additions and 2,941 deletions.
43 changes: 29 additions & 14 deletions app/middleware/grpc/client.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
process.env["GRPC_SSL_CIPHER_SUITES"] = "HIGH+ECDSA";

import grpc from "grpc";
const grpc = require("@grpc/grpc-js");

import { getWalletCert } from "config.js";
import { getWalletPath } from "main_dev/paths.js";
const services = require("../walletrpc/api_grpc_pb.js");

const proto = require("../walletrpc/api_grpc_pb.js");
const services = grpc.loadPackageDefinition(proto).walletrpc;

const getServiceClient = (clientClass) => (
isTestNet,
walletPath,
address,
port,
grpcKey,
grpccert,
grpcCert,
cb
) => {
const cert = getWalletCert(getWalletPath(isTestNet, walletPath));
Expand All @@ -26,9 +28,12 @@ const getServiceClient = (clientClass) => (
try {
// dcrwallet sends the key and cert on the same payload after starting.
// So we can use the same value for both of them.
const creds = grpc.credentials.createSsl(cert, grpcKey, grpccert);
const creds = grpc.credentials.createSsl(
cert,
Buffer.from(grpcKey),
Buffer.from(grpcCert)
);
const client = new clientClass(address + ":" + port, creds);

const deadline = new Date();
const deadlineInSeconds = 30;
deadline.setSeconds(deadline.getSeconds() + deadlineInSeconds);
Expand All @@ -44,20 +49,30 @@ const getServiceClient = (clientClass) => (
}
};

export const getWalletService = getServiceClient(services.WalletServiceClient);
export const getWalletService = getServiceClient(
services.WalletService
);
export const getTicketBuyerV2Service = getServiceClient(
services.TicketBuyerV2ServiceClient
services.TicketBuyerV2Service
);
export const loader = getServiceClient(
services.WalletLoaderService
);
export const getSeedService = getServiceClient(
services.SeedService
);
export const loader = getServiceClient(services.WalletLoaderServiceClient);
export const getSeedService = getServiceClient(services.SeedServiceClient);
export const getVersionService = getServiceClient(
services.VersionServiceClient
services.VersionService
);
export const getVotingService = getServiceClient(
services.VotingService
);
export const getAgendaService = getServiceClient(
services.AgendaService
);
export const getVotingService = getServiceClient(services.VotingServiceClient);
export const getAgendaService = getServiceClient(services.AgendaServiceClient);
export const getMessageVerificationService = getServiceClient(
services.MessageVerificationServiceClient
services.MessageVerificationService
);
export const getAccountMixerService = getServiceClient(
services.AccountMixerServiceClient
services.AccountMixerService
);
24 changes: 17 additions & 7 deletions app/middleware/ln/client.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
process.env["GRPC_SSL_CIPHER_SUITES"] = "HIGH+ECDSA";

import grpc from "grpc";
const grpc = require("@grpc/grpc-js");
import fs from "fs";

const services = require("./rpc_grpc_pb.js");
const wuServices = require("./walletunlocker_grpc_pb.js");
const wtServices = require("./wtclient_grpc_pb.js");

const proto = require("./rpc_grpc_pb.js");
const services = grpc.loadPackageDefinition(proto).lnrpc;

const wuProto = require("./walletunlocker_grpc_pb.js");
const wuServices = grpc.loadPackageDefinition(wuProto).lnrpc;

const wtProto = require("./wtclient_grpc_pb.js");
const wtServices = grpc.loadPackageDefinition(wtProto).wtclientrpc;

const getServiceClient = (clientClass) => async (
address,
Expand Down Expand Up @@ -75,8 +81,12 @@ const getServiceClient = (clientClass) => async (
});
};

export const getLightningClient = getServiceClient(services.LightningClient);
export const getWatchtowerClient = getServiceClient(wtServices.WatchtowerClientClient);
export const getLightningClient = getServiceClient(
services.Lightning
);
export const getWatchtowerClient = getServiceClient(
wtServices.WatchtowerClient
);
export const getWalletUnlockerClient = getServiceClient(
wuServices.WalletUnlockerClient
wuServices.WalletUnlocker
);
42 changes: 0 additions & 42 deletions app/middleware/ln/google/api/annotations_pb.js

This file was deleted.

Loading

0 comments on commit bf22f2f

Please sign in to comment.