Skip to content

Commit

Permalink
feat: req id counter
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Dec 20, 2023
1 parent f580edb commit cedd1ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions __tests__/config/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ if (process.env.DEBUG === 'true') {

response(response) {
const cloned = response.clone();
cloned.json().then(({ result }) => {
const match: any = combiner.find((it: any) => typeof it.result === 'undefined');
cloned.json().then((res) => {
const { result } = res;
const match: any = combiner.find((it: any) => it.request.body.id === res.id);
if (match && 'request' in match) {
match.result = result;
console.log(util.inspect(match, false, null, true /* enable colors */));
Expand Down
5 changes: 4 additions & 1 deletion src/channel/rpc_0_6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export class RpcChannel {

readonly retries: number;

private requestId: number;

readonly blockIdentifier: BlockIdentifier;

private chainId?: StarknetChainId;
Expand All @@ -65,6 +67,7 @@ export class RpcChannel {
this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
this.chainId = chainId;
this.waitMode = waitMode || false;
this.requestId = 0;
}

public fetch(method: string, params?: object, id: string | number = 0) {
Expand Down Expand Up @@ -102,7 +105,7 @@ export class RpcChannel {
params?: RPC.Methods[T]['params']
): Promise<RPC.Methods[T]['result']> {
try {
const rawResult = await this.fetch(method, params);
const rawResult = await this.fetch(method, params, (this.requestId += 1));
const { error, result } = await rawResult.json();
this.errorHandler(method, params, error);
return result as RPC.Methods[T]['result'];
Expand Down

0 comments on commit cedd1ea

Please sign in to comment.