Skip to content

Commit

Permalink
calles format
Browse files Browse the repository at this point in the history
  • Loading branch information
Egge21M committed Jun 17, 2024
1 parent 2bb4cfb commit baad729
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/WSConnection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MessageQueue } from './utils';
import { JsonRpcErrorObject, JsonRpcMessage, RpcSubId } from './model/types';
import { JsonRpcErrorObject, JsonRpcMessage, JsonRpcReqParams, RpcSubId } from './model/types';

type Command = 'check_quote' | 'check_proof';

Expand Down Expand Up @@ -46,10 +46,10 @@ export class WSConnection {
});
}

sendRequest(cmd: Command, subId: string, params: any) {
sendRequest(params: JsonRpcReqParams) {
const id = this.rpcId;
this.rpcId++;
this.ws?.send(JSON.stringify({ jsonrpc: '2.0', method: cmd, params: { subId }, id: id }));
this.ws?.send(JSON.stringify({ jsonrpc: '2.0', method: 'sub', params, id: id }));
}

closeSubscription(subId: string) {
Expand Down Expand Up @@ -124,8 +124,7 @@ export class WSConnection {
}

createSubscription(
cmd: 'check_proof' | 'check_quote',
params: any,
params: JsonRpcReqParams,
callback: () => any,
errorCallback: (e: Error) => any
) {
Expand All @@ -143,6 +142,6 @@ export class WSConnection {
this.rpcId
);
this.rpcId++;
this.sendRequest(cmd, subId, params);
this.sendRequest(params);
}
}
12 changes: 10 additions & 2 deletions src/model/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,18 @@ export type InvoiceData = {
expiry?: number;
};

type RpcSubKinds = 'bolt11_mint_quote' | 'bolt11_melt_quote' | 'proof_state';

export type RpcSubId = string | number | null;

type JsonRpcParams = any;

export type JsonRpcReqParams = {
kind: RpcSubKinds;
filter: Array<string>;
subId: string;
};

type JsonRpcSuccess<T = any> = {
jsonrpc: '2.0';
result: T;
Expand All @@ -564,8 +572,8 @@ type JsonRpcError = {

type JsonRpcRequest = {
jsonrpc: '2.0';
method: string;
params?: JsonRpcParams;
method: 'sub';
params: JsonRpcReqParams;
id: Exclude<RpcSubId, null>;
};

Expand Down

0 comments on commit baad729

Please sign in to comment.