Skip to content

Commit

Permalink
bnRevivier for snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Mar 20, 2024
1 parent d0c3db3 commit 711759e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 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.65

### Patch Changes

- Updated dependencies
- ethereum-indexer-browser@0.7.3

## 0.1.64

### 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.64",
"version": "0.1.65",
"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.65

### Patch Changes

- Updated dependencies
- ethereum-indexer-browser@0.7.3

## 0.1.64

### 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.64",
"version": "0.1.65",
"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.7.3

### Patch Changes

- bnRevivier for snapshots

## 0.7.2

### 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.7.2",
"version": "0.7.3",
"publishConfig": {
"access": "public"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ function getURL(remote: IndexedStateLocation | string, context: ProcessorContext
return url;
}

export function bnReviver(k: string, v: any): any {
if (
typeof v === 'string' &&
(v.startsWith('-') ? !isNaN(parseInt(v.charAt(1))) : !isNaN(parseInt(v.charAt(0)))) &&
v.charAt(v.length - 1) === 'n'
) {
return BigInt(v.slice(0, -1));
}
return v;
}


export function keepStateOnIndexedDB<ABI extends Abi, ProcessResultType, ProcessorConfig>(
name: string,
remote?: IndexedStateLocation | string | IndexedStateLocation[],
Expand All @@ -46,10 +58,13 @@ export function keepStateOnIndexedDB<ABI extends Abi, ProcessResultType, Process
const urlOfRemote = getURL(remote[i], context);
try {
const response = await fetch(urlOfRemote);
const text = await response.text();

const json: {
state: ProcessResultType;
lastSync: LastSync<ABI>;
} = await response.json();
} = JSON.parse(text, bnReviver);

if (!latest || !latest.lastSync || (json.lastSync && json.lastSync.lastToBlock > latest.lastSync.lastToBlock)) {
latest = {
index: i,
Expand Down

0 comments on commit 711759e

Please sign in to comment.