Skip to content

Commit

Permalink
show response/error when logRequests == true
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Nov 25, 2023
1 parent 979c6ca commit 838da53
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 7 deletions.
7 changes: 7 additions & 0 deletions examples/mud/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# web-demo

## 0.1.48

### Patch Changes

- Updated dependencies
- ethereum-indexer-browser@0.6.20

## 0.1.47

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/mud/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mud-demo",
"private": true,
"version": "0.1.47",
"version": "0.1.48",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
7 changes: 7 additions & 0 deletions examples/web-demo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# web-demo

## 0.1.48

### Patch Changes

- Updated dependencies
- ethereum-indexer-browser@0.6.20

## 0.1.47

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/web-demo/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "web-demo",
"private": true,
"version": "0.1.47",
"version": "0.1.48",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
6 changes: 6 additions & 0 deletions packages/ethereum-indexer-browser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ethereum-indexer-browser

## 0.6.20

### Patch Changes

- show response/error when logRequests == true

## 0.6.19

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ethereum-indexer-browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethereum-indexer-browser",
"version": "0.6.19",
"version": "0.6.20",
"publishConfig": {
"access": "public"
},
Expand Down
34 changes: 30 additions & 4 deletions packages/ethereum-indexer-browser/src/IndexerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,50 @@ export function createIndexerState<ABI extends Abi, ProcessResultType, Processor
const config = {...{}, keepStream: options?.keepStream, ...(indexerSetup.config || {})};
const source = indexerSetup.source;

const provider = options?.trackNumRequests || options?.logRequests
? new Proxy(indexerSetup.provider, {
let provider: EIP1193ProviderWithoutEvents = indexerSetup.provider;


if (options?.trackNumRequests && !options.logRequests) {
// only trackNumRequest
provider = new Proxy(indexerSetup.provider, {
get(target, p, receiver) {
if (p === 'request') {
return (args: {method: string; params?: readonly unknown[]}) => {
if (options.trackNumRequests) {
setSyncing({numRequests: ($syncing.numRequests || 0) + 1});
}
return target[p](args as any);
};
}
return (target as any)[p];
},
})
} else if (options?.logRequests) {
provider = new Proxy(indexerSetup.provider, {
get(target, p, receiver) {
if (p === 'request') {
return async (args: {method: string; params?: readonly unknown[]}) => {
if (options.trackNumRequests) {
setSyncing({numRequests: ($syncing.numRequests || 0) + 1});
}
if (options.logRequests) {
console.log(JSON.stringify(args));
}
return target[p](args as any);
let response;
try {
response = await target[p](args as any);
console.log(` =>`, JSON.stringify(response))
} catch(err) {
console.error(` error:`, err);
throw err;
}
return response;
};
}
return (target as any)[p];
},
})
: indexerSetup.provider;
}
if (processor.configure && processorConfig) {
processor.configure(processorConfig);
}
Expand Down

0 comments on commit 838da53

Please sign in to comment.