Skip to content

Commit cedd1ea

Browse files
committed
feat: req id counter
1 parent f580edb commit cedd1ea

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

__tests__/config/jest.setup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ if (process.env.DEBUG === 'true') {
3838

3939
response(response) {
4040
const cloned = response.clone();
41-
cloned.json().then(({ result }) => {
42-
const match: any = combiner.find((it: any) => typeof it.result === 'undefined');
41+
cloned.json().then((res) => {
42+
const { result } = res;
43+
const match: any = combiner.find((it: any) => it.request.body.id === res.id);
4344
if (match && 'request' in match) {
4445
match.result = result;
4546
console.log(util.inspect(match, false, null, true /* enable colors */));

src/channel/rpc_0_6.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export class RpcChannel {
4242

4343
readonly retries: number;
4444

45+
private requestId: number;
46+
4547
readonly blockIdentifier: BlockIdentifier;
4648

4749
private chainId?: StarknetChainId;
@@ -65,6 +67,7 @@ export class RpcChannel {
6567
this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
6668
this.chainId = chainId;
6769
this.waitMode = waitMode || false;
70+
this.requestId = 0;
6871
}
6972

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

0 commit comments

Comments
 (0)