Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libraries/fabric-shim/lib/chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ class Shim {
return Logger.getLogger(name);
}

/**
* @interface GRPCOptions
* @description ChannelOptions on "@grpc/grpc-js". For a complete list, refer to <a href=https://www.npmjs.com/package/@grpc/grpc-js#supported-channel-options>@grpc/grpc-js Documentation</a>
* @property {unknown[]} ['grpc.${string}'] Connection options defined on "@grpc/grpc-js"
*/
/**
* @interface ChaincodeServerTLSProperties
* @property {Buffer} key Private key for TLS
Expand All @@ -207,6 +212,7 @@ class Shim {
*/
/**
* @interface ChaincodeServerOpts
* @extends GRPCOptions
* @property {string} ccid Chaincode ID
* @property {string} address Listen address for the server
* @property {ChaincodeServerTLSProperties} [tlsProps] TLS properties if TLS is required.
Expand Down
6 changes: 5 additions & 1 deletion libraries/fabric-shim/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ class ChaincodeServer {
this._credentials = grpc.ServerCredentials.createInsecure();
}

const grpcOptions = Object.fromEntries(
Object.entries(serverOpts).filter(([key]) => key.startsWith('grpc.'))
);

// Create GRPC Server and register RPC handler
this._server = new grpc.Server();
this._server = new grpc.Server(grpcOptions);
this._server.addService(peer.ChaincodeService, this);

this._serverOpts = serverOpts;
Expand Down
10 changes: 7 additions & 3 deletions libraries/fabric-shim/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
declare module 'fabric-shim' {

import { EventEmitter } from 'events';
import { Logger } from 'winston';
import { ChannelOptions } from '@grpc/grpc-js'

import {
ChaincodeInterface,
Expand Down Expand Up @@ -53,7 +53,11 @@ declare module 'fabric-shim' {
start(): Promise<void>;
}

export interface ChaincodeServerOpts {
type GRPCOptions = {
[K in keyof ChannelOptions as string extends K ? never : K]?: ChannelOptions[K];
}

export interface ChaincodeServerOpts extends GRPCOptions {
ccid: string;
address: string;
tlsProps: ChaincodeServerTLSProperties;
Expand Down Expand Up @@ -140,7 +144,7 @@ declare module 'fabric-shim' {
constructor(policy?: Uint8Array);
getPolicy(): Uint8Array;
addOrgs(role: string, ...newOrgs: string[]): void;
delOrgs(...delOrgs: string[]):void;
delOrgs(...delOrgs: string[]): void;
listOrgs(): string[];
}

Expand Down