Skip to content

Commit

Permalink
Send block as generic payload to be subscribed Ref: #31
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelpapineau committed Nov 16, 2023
1 parent 2f89e6d commit bebc08b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/websocket/parseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export function parseMessage(message: string|Buffer): { method: string, id: stri

if ( method === 'subscribe' ) {
if ( params === null || params === undefined) throw new Error('Missing required \'params\' in JSON request.');
const { moduleHash } = params;
if ( moduleHash === null || moduleHash === undefined) throw new Error('Missing required \'moduleHash\' in JSON request.');
}

return json;
Expand Down
8 changes: 7 additions & 1 deletion src/websocket/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import * as sqlite from "../sqlite.js";
import * as prometheus from "../prometheus.js";

export default function (ws: ServerWebSocket<ServerWebSocketData>, params: {[key: string]: any}, id?: string) {
const { moduleHash, chain } = params;
const { chain, block } = params;
let { moduleHash } = params;

if ( block === true ) {
moduleHash = sqlite.selectAll(db, "moduleHash")[0].key;
}

const topic = chain ? `${chain}:${moduleHash}` : moduleHash;
if ( ws.isSubscribed(topic) ) throw new Error(`Already subscribed to [${topic}] topic.`);

Expand Down

0 comments on commit bebc08b

Please sign in to comment.