Skip to content

Commit

Permalink
allow reading from file for deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Nov 24, 2023
1 parent e95c0ef commit 8498cfe
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 10 deletions.
10 changes: 10 additions & 0 deletions examples/mud/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# web-demo

## 0.1.40

### Patch Changes

- Updated dependencies
- [email protected]
- [email protected]
- [email protected]
- [email protected]

## 0.1.39

### 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.39",
"version": "0.1.40",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
10 changes: 10 additions & 0 deletions examples/web-demo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# web-demo

## 0.1.40

### Patch Changes

- Updated dependencies
- [email protected]
- [email protected]
- [email protected]
- [email protected]

## 0.1.39

### 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.39",
"version": "0.1.40",
"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.13

### Patch Changes

- allow reading from file for deployments

## 0.6.12

### 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.12",
"version": "0.6.13",
"publishConfig": {
"access": "public"
},
Expand Down
19 changes: 17 additions & 2 deletions packages/ethereum-indexer-browser/src/storage/state/OnIndexedDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ function getStorageID<ProcessorConfig = undefined>(name: string, chainId: string

type StateData<ABI extends Abi, ProcessResultType, Extra> = AllData<ABI, ProcessResultType, Extra>;

export function keepStateOnIndexedDB<ABI extends Abi, ProcessResultType, ProcessorConfig>(name: string) {
export function keepStateOnIndexedDB<ABI extends Abi, ProcessResultType, ProcessorConfig>(name: string, remote?: string) {
return {
fetch: async (context: ProcessorContext<ABI, ProcessorConfig>) => {
const storageID = getStorageID(name, context.source.chainId, 'config' in context ? context.config : undefined);
const existingState = await get<StateData<ABI, ProcessResultType, unknown>>(storageID);

let remoteState: StateData<ABI, ProcessResultType, unknown> | undefined;
if (remote) {
try {
const response = await fetch(remote);
const json = await response.json();
remoteState = json;
} catch(err) {
console.error(`failed to fetch remote-state`, err);
}
}

if (!existingState) {
return undefined;
return remoteState;
} else {
if (remoteState && remoteState.lastSync.lastToBlock >= existingState.lastSync.lastToBlock) {
return remoteState;
}
return existingState;
}
},
Expand Down
7 changes: 7 additions & 0 deletions packages/ethereum-indexer-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# ethereum-indexer-cli

## 0.6.14

### Patch Changes

- Updated dependencies
- [email protected]

## 0.6.13

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ethereum-indexer-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethereum-indexer-cli",
"version": "0.6.13",
"version": "0.6.14",
"description": "",
"keywords": [],
"author": "",
Expand Down
7 changes: 7 additions & 0 deletions packages/ethereum-indexer-server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# ethereum-indexer-server

## 0.6.17

### Patch Changes

- Updated dependencies
- [email protected]

## 0.6.16

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ethereum-indexer-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethereum-indexer-server",
"version": "0.6.16",
"version": "0.6.17",
"description": "",
"keywords": [],
"author": "",
Expand Down
7 changes: 7 additions & 0 deletions packages/ethereum-indexer-streams/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# ethereum-indexer-server

## 0.6.16

### Patch Changes

- Updated dependencies
- [email protected]

## 0.6.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ethereum-indexer-streams/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethereum-indexer-streams",
"version": "0.6.15",
"version": "0.6.16",
"description": "",
"keywords": [],
"author": "",
Expand Down
6 changes: 6 additions & 0 deletions packages/ethereum-indexer-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ethereum-indexer-utils

## 0.6.9

### Patch Changes

- allow reading from file for deployments

## 0.6.8

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ethereum-indexer-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethereum-indexer-utils",
"version": "0.6.8",
"version": "0.6.9",
"description": "",
"publishConfig": {
"access": "public"
Expand Down
29 changes: 28 additions & 1 deletion packages/ethereum-indexer-utils/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,34 @@ function mergeABIs(abi1: any[], abi2: any[]): any[] {
return newABI;
}

export function loadContracts<ABI extends Abi>(folder: string): IndexingSource<ABI> {
export function loadContracts<ABI extends Abi>(folderOrFile: string): IndexingSource<ABI> {
if (fs.statSync(folderOrFile).isDirectory()) {
return loadContractsFromFolder(folderOrFile);
} else {
return loadContractsFromFile(folderOrFile)
}
}


export function loadContractsFromFile<ABI extends Abi>(file: string): IndexingSource<ABI> {

let contractSTR = fs.readFileSync(file, 'utf-8');
if (contractSTR.startsWith('export default {') && contractSTR.endsWith('} as const;')) {
contractSTR = contractSTR.slice(15, -10);
}
const contracts = JSON.parse(contractSTR);

return {
chainId: contracts.chainId,
contracts: Object.keys(contracts.contracts).map(
(name) => (contracts as any).contracts[name],
),
}
}



export function loadContractsFromFolder<ABI extends Abi>(folder: string): IndexingSource<ABI> {
const contractsAdded: {[address: string]: {index: number}} = {};
const contractsData: ContractData<ABI>[] = [];
const files = fs.readdirSync(folder);
Expand Down

0 comments on commit 8498cfe

Please sign in to comment.