Skip to content

Commit

Permalink
tmp: more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Nov 25, 2023
1 parent 8c62663 commit 6ead5cc
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 45 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.54

### Patch Changes

- Updated dependencies
- ethereum-indexer-browser@0.6.24

## 0.1.53

### 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.53",
"version": "0.1.54",
"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.54

### Patch Changes

- Updated dependencies
- ethereum-indexer-browser@0.6.24

## 0.1.53

### 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.53",
"version": "0.1.54",
"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.24

### Patch Changes

- tmp: more logs

## 0.6.23

### 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.23",
"version": "0.6.24",
"publishConfig": {
"access": "public"
},
Expand Down
92 changes: 50 additions & 42 deletions packages/ethereum-indexer-browser/src/IndexerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,51 +111,55 @@ export function createIndexerState<ABI extends Abi, ProcessResultType, Processor

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));
}
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];
},
})
}
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));
}
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];
},
})
}

const before_configure_frozen = Object.isFrozen(initialState);
console.log({before_configure_frozen});
if (processor.configure && processorConfig) {
processor.configure(processorConfig);
}
const after_configure_frozen = Object.isFrozen(initialState);
console.log({after_configure_frozen});
indexer = new EthereumIndexer<ABI, ProcessResultType>(provider, processor, source, config);
setSyncing({waitingForProvider: false});
}
Expand Down Expand Up @@ -185,6 +189,8 @@ export function createIndexerState<ABI extends Abi, ProcessResultType, Processor
}

async function setupIndexing(): Promise<LastSync<ABI>> {
const setupIndexing_frozen = Object.isFrozen(initialState);
console.log({setupIndexing_frozen});
if ($syncing.lastSync) {
return $syncing.lastSync;
}
Expand All @@ -207,6 +213,8 @@ export function createIndexerState<ABI extends Abi, ProcessResultType, Processor
await wait(0.001); // allow propagation if the whole proces is synchronous
};
indexer.onLastSyncUpdated = (lastSync) => {
const onLastSyncUpdated_frozen = Object.isFrozen(initialState);
console.log({onLastSyncUpdated_frozen});
// should we also wait ?
setLastSync(lastSync);
};
Expand Down

0 comments on commit 6ead5cc

Please sign in to comment.