-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: generalize mirror channel in hopes of getting it working on web
- Loading branch information
Showing
16 changed files
with
118 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,25 @@ | ||
import { Client, credentials } from "@grpc/grpc-js"; | ||
|
||
/** | ||
* @internal | ||
* @abstract | ||
*/ | ||
export default class MirrorChannel { | ||
/** | ||
* @internal | ||
* @param {string} address | ||
*/ | ||
constructor(address) { | ||
/** | ||
* @type {Client} | ||
* @private | ||
*/ | ||
this._client = new Client(address, credentials.createInsecure()); | ||
} | ||
|
||
/** | ||
* @abstract | ||
* @returns {void} | ||
*/ | ||
close() { | ||
this._client.close(); | ||
throw new Error("not implemented"); | ||
} | ||
|
||
/** | ||
* @override | ||
* @abstract | ||
* @internal | ||
* @param {Uint8Array} requestData | ||
* @returns {import("@grpc/grpc-js").ClientReadableStream<Buffer>} | ||
* @param {(error: number?, data: Uint8Array?) => void} callback | ||
* @returns {() => void} | ||
*/ | ||
makeServerStreamRequest(requestData) { | ||
return this._client.makeServerStreamRequest( | ||
// `/proto.ConsensusService/SubscribeTopic`, | ||
"/com.hedera.mirror.api.proto.ConsensusService/subscribeTopic", | ||
(value) => value, | ||
(value) => value, | ||
Buffer.from(requestData) | ||
); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
makeServerStreamRequest(requestData, callback) { | ||
throw new Error("not implemented"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as grpc from "@grpc/grpc-js"; | ||
import MirrorChannel from "./MirrorChannel.js"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export default class NodeMirrorChannel extends MirrorChannel { | ||
/** | ||
* @internal | ||
* @param {string} address | ||
*/ | ||
constructor(address) { | ||
super(); | ||
|
||
/** | ||
* @type {grpc.Client} | ||
* @private | ||
*/ | ||
this._client = new grpc.Client( | ||
address, | ||
grpc.credentials.createInsecure() | ||
); | ||
} | ||
|
||
/** | ||
* @override | ||
* @returns {void} | ||
*/ | ||
close() { | ||
this._client.close(); | ||
} | ||
|
||
/** | ||
* @override | ||
* @internal | ||
* @param {Uint8Array} requestData | ||
* @param {(error: number?, data: Uint8Array?) => void} callback | ||
* @returns {() => void} | ||
*/ | ||
makeServerStreamRequest(requestData, callback) { | ||
let stream = this._client | ||
.makeServerStreamRequest( | ||
// `/proto.ConsensusService/SubscribeTopic`, | ||
"/com.hedera.mirror.api.proto.ConsensusService/subscribeTopic", | ||
(value) => value, | ||
(value) => value, | ||
Buffer.from(requestData) | ||
) | ||
.on("data", (/** @type {Uint8Array} */ data) => { | ||
callback(null, data); | ||
}) | ||
.on("status", (/** @type {grpc.StatusObject} */ status) => { | ||
callback(status.code, null); | ||
}); | ||
|
||
return () => { | ||
stream.cancel(); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters