Skip to content

Commit

Permalink
grpc -> grpcjs
Browse files Browse the repository at this point in the history
  • Loading branch information
antonilol committed Sep 15, 2022
1 parent eb58ea3 commit 4399888
Show file tree
Hide file tree
Showing 10 changed files with 6,506 additions and 9,884 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update_proto.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Update proto files
on:
schedule:
- cron: "0 0 1 * *"
- cron: '0 0 1 * *'

jobs:
update_proto:
Expand Down
16,288 changes: 6,441 additions & 9,847 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dev": "rm -rf dist/ && tsc && cp -r public dist/public && node --inspect ./dist/app.js",
"build-binaries": "rm -rf dist/ && tsc && cp config/app.json dist/config/app.json && cp config/config.json dist/config/config.json && pkg . --target node12-alpine-x64,node12-macos-x64 --out-path binaries",
"start-ecs": "cp config/app.json dist/config/app.json && cp config/config.json dist/config/config.json && export NODE_ENV=production && node --max-old-space-size=128 dist/app.js",
"lint": "eslint ./src/*.ts ./src/**/*.ts --fix --max-warnings 466"
"lint": "eslint ./src/*.ts ./src/**/*.ts --fix --max-warnings 454"
},
"keywords": [],
"author": "",
Expand All @@ -37,7 +37,8 @@
},
"dependencies": {
"@boltz/bolt11": "^1.2.7",
"@grpc/proto-loader": "^0.5.3",
"@grpc/grpc-js": "^1.7.0",
"@grpc/proto-loader": "^0.7.2",
"@octokit/webhooks-types": "^5.2.0",
"@scout_apm/scout-apm": "^0.1.10",
"async": "^2.6.4",
Expand All @@ -62,7 +63,6 @@
"fetch-blob": "^1.0.5",
"form-data": "^3.0.0",
"fs": "^0.0.1-security",
"grpc": "^1.24.3",
"helmet": "^3.21.1",
"ip": "^1.1.5",
"jasmine": "^3.5.0",
Expand Down Expand Up @@ -115,7 +115,7 @@
"@types/cron": "^2.0.0",
"@types/crypto-js": "^4.1.1",
"@types/ip": "^1.1.0",
"@types/jest": "^28.1.8",
"@types/jest": "^28.1.7",
"@types/md5": "^2.3.2",
"@types/minimist": "^1.2.2",
"@types/multer": "^1.4.7",
Expand Down
7 changes: 4 additions & 3 deletions src/grpc/greenlight.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs'
import * as grpc from 'grpc'
import * as grpc from '@grpc/grpc-js'
import { loadProto } from './proto'
import libhsmd from './libhsmd'
import { loadConfig } from '../utils/config'
import * as ByteBuffer from 'bytebuffer'
Expand Down Expand Up @@ -38,8 +39,8 @@ const loadSchedulerCredentials = () => {

function loadScheduler() {
// 35.236.110.178:2601
const descriptor = grpc.load('proto/scheduler.proto')
const scheduler: any = descriptor.scheduler
const descriptor = loadProto('scheduler')
const scheduler = descriptor.scheduler
const options = {
'grpc.ssl_target_name_override': 'localhost',
}
Expand Down
28 changes: 13 additions & 15 deletions src/grpc/lightning.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as ByteBuffer from 'bytebuffer'
import * as fs from 'fs'
import * as grpc from 'grpc'
import * as grpc from '@grpc/grpc-js'
import { loadProto } from './proto'
import { sleep } from '../helpers'
import * as sha from 'js-sha256'
import * as crypto from 'crypto'
Expand All @@ -16,7 +17,6 @@ import libhsmd from './libhsmd'
import { get_greenlight_grpc_uri } from './greenlight'
import { Req } from '../types'

// var protoLoader = require('@grpc/proto-loader')
const config = loadConfig()
const LND_IP = config.lnd_ip || 'localhost'
// const IS_LND = config.lightning_provider === "LND";
Expand Down Expand Up @@ -74,26 +74,24 @@ export async function loadLightning(

if (IS_GREENLIGHT) {
const credentials = loadGreenlightCredentials()
const descriptor = grpc.load('proto/greenlight.proto')
const greenlight: any = descriptor.greenlight
const descriptor = loadProto('greenlight')
const greenlight = descriptor.greenlight
const options = {
'grpc.ssl_target_name_override': 'localhost',
}
const uri = get_greenlight_grpc_uri().split('//')
if (!uri[1]) return
lightningClient = new greenlight.Node(uri[1], credentials, options)
return lightningClient
return lightningClient = new greenlight.Node(uri[1], credentials, options)
}

// LND
const credentials = loadCredentials()
const lnrpcDescriptor = grpc.load('proto/lightning.proto')
const lnrpc: any = lnrpcDescriptor.lnrpc
lightningClient = new lnrpc.Lightning(
const lnrpcDescriptor = loadProto('lightning')
const lnrpc = lnrpcDescriptor.lnrpc
return (lightningClient = new lnrpc.Lightning(
LND_IP + ':' + config.lnd_port,
credentials
)
return lightningClient
))
}

export function loadWalletUnlocker(): any {
Expand All @@ -102,8 +100,8 @@ export function loadWalletUnlocker(): any {
} else {
try {
const credentials = loadCredentials()
const lnrpcDescriptor = grpc.load('proto/walletunlocker.proto')
const lnrpc: any = lnrpcDescriptor.lnrpc
const lnrpcDescriptor = loadProto('walletunlocker')
const lnrpc = lnrpcDescriptor.lnrpc
walletUnlocker = new lnrpc.WalletUnlocker(
LND_IP + ':' + config.lnd_port,
credentials
Expand Down Expand Up @@ -389,8 +387,8 @@ export function loadRouter(): any {
return routerClient
} else {
const credentials = loadCredentials('router.macaroon')
const descriptor = grpc.load('proto/router.proto')
const router: any = descriptor.routerrpc
const descriptor = loadProto('router')
const router = descriptor.routerrpc
routerClient = new router.Router(
LND_IP + ':' + config.lnd_port,
credentials
Expand Down
28 changes: 28 additions & 0 deletions src/grpc/proto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as grpc from '@grpc/grpc-js'
import { loadSync, Options } from '@grpc/proto-loader'

process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA'

type ProtoName =
| 'greenlight'
| 'lightning'
| 'router'
| 'rpc_proxy'
| 'scheduler'
| 'signer'
| 'walletkit'
| 'walletunlocker'

const opts: Options = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
}

export function loadProto(name: ProtoName): any {
return grpc.loadPackageDefinition(
loadSync(`proto/${name}.proto`, opts)
)
}
2 changes: 1 addition & 1 deletion src/grpc/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function subscribeInvoices(
const lightning = await loadLightning(true, ownerPubkey) // try proxy

const cmd = interfaces.subscribeCommand()
const call = lightning[cmd]()
const call = lightning[cmd]({})
call.on('data', async function (response) {
// console.log("=> INVOICE RAW", response)
const inv = interfaces.subscribeResponse(response)
Expand Down
15 changes: 8 additions & 7 deletions src/utils/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs'
import * as grpc from 'grpc'
import * as grpc from '@grpc/grpc-js'
import { loadProto } from '../grpc/proto'
import { loadConfig } from './config'
import * as Lightning from '../grpc/lightning'
import { models, ContactRecord } from '../models'
Expand Down Expand Up @@ -172,8 +173,8 @@ export async function loadProxyLightning(ownerPubkey?: string) {
}
}
const credentials = await loadProxyCredentials(macname)
const lnrpcDescriptor = grpc.load('proto/rpc_proxy.proto')
const lnrpc: any = lnrpcDescriptor.lnrpc_proxy
const lnrpcDescriptor = loadProto('rpc_proxy')
const lnrpc = lnrpcDescriptor.lnrpc_proxy
const the = new lnrpc.Lightning(
PROXY_LND_IP + ':' + config.proxy_lnd_port,
credentials
Expand All @@ -194,8 +195,8 @@ export function getProxyRootPubkey(): Promise<string> {
}
// normal client, to get pubkey of LND
const credentials = Lightning.loadCredentials()
const lnrpcDescriptor = grpc.load('proto/lightning.proto')
const lnrpc: any = lnrpcDescriptor.lnrpc
const lnrpcDescriptor = loadProto('lightning')
const lnrpc = lnrpcDescriptor.lnrpc
const lc = new lnrpc.Lightning(LND_IP + ':' + config.lnd_port, credentials)
lc.getInfo({}, function (err, response) {
if (err == null) {
Expand All @@ -212,8 +213,8 @@ function getProxyLNDBalance(): Promise<number> {
return new Promise((resolve, reject) => {
// normal client, to get pubkey of LND
const credentials = Lightning.loadCredentials()
const lnrpcDescriptor = grpc.load('proto/lightning.proto')
const lnrpc: any = lnrpcDescriptor.lnrpc
const lnrpcDescriptor = loadProto('lightning')
const lnrpc = lnrpcDescriptor.lnrpc
const lc = new lnrpc.Lightning(LND_IP + ':' + config.lnd_port, credentials)
lc.channelBalance({}, function (err, response) {
if (err == null) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/signer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as grpc from 'grpc'
import { loadProto } from '../grpc/proto'
import * as Lightning from '../grpc/lightning'
import * as ByteBuffer from 'bytebuffer'
import { loadConfig } from './config'
Expand All @@ -16,8 +16,8 @@ export const loadSigner = () => {
} else {
try {
const credentials = Lightning.loadCredentials('signer.macaroon')
const lnrpcDescriptor = grpc.load('proto/signer.proto')
const signer: any = lnrpcDescriptor.signrpc
const lnrpcDescriptor = loadProto('signer')
const signer = lnrpcDescriptor.signrpc
signerClient = new signer.Signer(
LND_IP + ':' + config.lnd_port,
credentials
Expand Down
6 changes: 3 additions & 3 deletions src/utils/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as grpc from 'grpc'
import { loadProto } from '../grpc/proto'
import * as Lightning from '../grpc/lightning'
import { loadConfig } from './config'
import { sphinxLogger } from './logger'
Expand All @@ -14,8 +14,8 @@ export const loadWalletKit = () => {
} else {
try {
const credentials = Lightning.loadCredentials()
const lnrpcDescriptor = grpc.load('proto/walletkit.proto')
const walletkit: any = lnrpcDescriptor.walletrpc
const lnrpcDescriptor = loadProto('walletkit')
const walletkit = lnrpcDescriptor.walletrpc
walletClient = new walletkit.WalletKit(
LND_IP + ':' + config.lnd_port,
credentials
Expand Down

0 comments on commit 4399888

Please sign in to comment.