Skip to content

Commit

Permalink
indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeal-eth committed Dec 8, 2024
1 parent 54a2fa4 commit be7a1f6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:18-alpine AS build
WORKDIR /app
ENV REDIS_URL ""
ENV IPFS_URL ""
ENV MAINNET_PROVIDER_URL ""
RUN apk update && apk add build-base
COPY --link . .
RUN npm i -g pnpm
RUN pnpm i
RUN pnpm run build

FROM node:18-alpine
WORKDIR /app
COPY --link --from=build /app/packages/*/dist dist
COPY --link --from=build /app/package.json package.json
COPY --link --from=build /app/pnpm-lock.json pnpm-lock.json
RUN npm i -g pnpm
RUN pnpm install --omit=dev
CMD ["node", "packages/indexer/dist/index.js"]
9 changes: 5 additions & 4 deletions packages/indexer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ ENV REDIS_URL ""
ENV IPFS_URL ""
ENV MAINNET_PROVIDER_URL ""
COPY --link . .
RUN npm i
RUN npm run build
RUN npm i -g pnpm
RUN pnpm i
RUN pnpm run build

FROM node:18-alpine
WORKDIR /app
COPY --link --from=build /app/dist dist
COPY --link --from=build /app/package.json package.json
COPY --link --from=build /app/package-lock.json package-lock.json
RUN npm install --omit=dev
RUN npm i -g pnpm
RUN pnpm install --omit=dev
CMD ["node", "dist/index.js"]
40 changes: 24 additions & 16 deletions packages/indexer/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@usecannon/builder';
import CannonRegistryAbi from '@usecannon/builder/dist/src/abis/CannonRegistry';
import _ from 'lodash';
import { RedisClientType, SchemaFieldTypes } from 'redis';
import { RedisClientType, SchemaFieldTypes, TimeSeriesDuplicatePolicies } from 'redis';
/* eslint no-console: "off" */
import * as viem from 'viem';
import * as viemChains from 'viem/chains';
Expand Down Expand Up @@ -245,16 +245,8 @@ export async function handleCannonPublish(

if (contract.deployTxnHash) {
// note: we dont include chainId in the index here because transaction ids are almost always unique
batch.hSetNX(rkey.RKEY_TRANSACTION_TO_PACKAGE, contract.deployTxnHash, packageRef);
batch.ts.incrBy(`${rkey.RKEY_TS_TRANSACTION_COUNT}:${chainId}`, 1, {
TIMESTAMP: timestamp - (timestamp % 3600000),
LABELS: { chainId: `${chainId}`, kind: rkey.RKEY_TS_TRANSACTION_COUNT },
});
batch.hSetNX(rkey.RKEY_TRANSACTION_TO_PACKAGE + ':' + chainId, contract.deployTxnHash, packageRef);
}
batch.ts.incrBy(`${rkey.RKEY_TS_CONTRACT_COUNT}:${chainId}`, 1, {
TIMESTAMP: timestamp - (timestamp % 3600000),
LABELS: { chainId: `${chainId}`, kind: rkey.RKEY_TS_CONTRACT_COUNT },
});

// process the contract abi as well
for (const abiItem of contract.abi) {
Expand All @@ -278,18 +270,34 @@ export async function handleCannonPublish(
}
}
for (const txn of Object.values(state.artifacts.txns || {})) {
batch.hSetNX(rkey.RKEY_TRANSACTION_TO_PACKAGE, txn.hash, packageRef);
batch.ts.incrBy(`${rkey.RKEY_TS_TRANSACTION_COUNT}:${chainId}`, 1, {
TIMESTAMP: timestamp - (timestamp % 3600000),
LABELS: { chainId: `${chainId}`, kind: rkey.RKEY_TS_TRANSACTION_COUNT },
});
batch.hSetNX(rkey.RKEY_TRANSACTION_TO_PACKAGE + ':' + chainId, txn.hash, packageRef);
}
batch.incr(`${rkey.RKEY_COUNTER_STEP_TYPE_PREFIX}:${type}`);
} else {
console.log('[warn] step data not found:', actionName);
}

await batch.exec();
batch.hLen(rkey.RKEY_ADDRESS_TO_PACKAGE + ':' + chainId);
batch.hLen(rkey.RKEY_TRANSACTION_TO_PACKAGE + ':' + chainId);

const result = await batch.exec();

const contractCount = result[result.length - 2] as number;
const transactionCount = result[result.length - 1] as number;

const tsBatch = redis.multi();

tsBatch.ts.add(`${rkey.RKEY_TS_CONTRACT_COUNT}:${chainId}`, timestamp, contractCount, {
LABELS: { chainId: `${chainId}`, kind: rkey.RKEY_TS_CONTRACT_COUNT },
ON_DUPLICATE: TimeSeriesDuplicatePolicies.LAST,
});

tsBatch.ts.add(`${rkey.RKEY_TS_TRANSACTION_COUNT}:${chainId}`, timestamp, transactionCount, {
LABELS: { chainId: `${chainId}`, kind: rkey.RKEY_TS_TRANSACTION_COUNT },
ON_DUPLICATE: TimeSeriesDuplicatePolicies.LAST,
});

await tsBatch.exec();
}
}

Expand Down

0 comments on commit be7a1f6

Please sign in to comment.