Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proxy colonies] Feat: create proxy chain block ingestor #298

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ module.exports = {
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json'],
project: [
'./tsconfig.base.json',
'./packages/*/tsconfig.json',
'./apps/*/tsconfig.json'
],
tsconfigRootDir: __dirname,
},
rules: {
semi: 'off',
'@typescript-eslint/semi': ['error', 'always'],
'@typescript-eslint/strict-boolean-expressions': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'comma-dangle': 'off',
'@typescript-eslint/comma-dangle': ['error', 'always-multiline'],
'@typescript-eslint/no-misused-promises': 'off',
Expand All @@ -25,6 +31,10 @@ module.exports = {
'no-useless-return': 'off',
'@typescript-eslint/member-delimiter-style': 'off',
'@typescript-eslint/indent': 'off',
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/return-await': 'off',
'@typescript-eslint/space-before-function-paren': [
'error',
{
Expand All @@ -34,5 +44,5 @@ module.exports = {
},
],
},
ignorePatterns: ['codegen.ts', 'src/graphql/generated.ts'],
ignorePatterns: ['packages/graphql/codegen.ts', 'packages/graphql/src/generated.ts'],
};
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typings/

# dotenv environment variables file
.env
.env.proxy-2
.env.test

# parcel-bundler cache (https://parceljs.org/)
Expand Down Expand Up @@ -102,5 +103,3 @@ dist

# TernJS port file
.tern-port

stats
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ COPY --from=build /workspace /workspace
WORKDIR /workspace/apps/main-chain
CMD ["pnpm", "--filter", "@joincolony/main-chain", "prod"]

# Proxy Chain Stage
FROM base AS proxy-chain
WORKDIR /workspace
COPY --from=build /workspace /workspace
WORKDIR /workspace/apps/proxy-chain
CMD ["pnpm", "--filter", "@joincolony/proxy-chain", "prod"]

1 change: 1 addition & 0 deletions apps/main-chain/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CHAIN_RPC_ENDPOINT=http://localhost:8545
CHAIN_NETWORK_CONTRACT=0x777760996135F0791E2e1a74aFAa060711197777
STATS_PORT=10001
22 changes: 0 additions & 22 deletions apps/main-chain/Dockerfile

This file was deleted.

30 changes: 16 additions & 14 deletions apps/main-chain/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "@joincolony/main-chain",
"version": "1.0.0",
"main": "src/index.ts",
"scripts": {
"build": "rm -rf dist/* && npx tsc",
"start": "node -r ts-node/register/transpile-only -r tsconfig-paths/register -r ./src/env.ts dist/index.js",
"dev": "NODE_ENV=development ts-node-dev -r tsconfig-paths/register -r ./src/env.ts src/index.ts",
"prod": "pnpm run build && NODE_ENV=production pnpm run start",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@joincolony/graphql": "workspace:*"
}
"name": "@joincolony/main-chain",
"version": "1.0.0",
"main": "src/index.ts",
"scripts": {
"build": "rm -rf dist/* && npx tsc",
"start": "node -r ts-node/register/transpile-only -r tsconfig-paths/register -r ./dist/env.js dist/index.js",
"dev": "NODE_ENV=development ts-node-dev -r tsconfig-paths/register -r ./src/env.ts src/index.ts",
"prod": "pnpm run build && NODE_ENV=production pnpm run start",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@joincolony/graphql": "workspace:*",
"@joincolony/clients": "workspace:*",
"@joincolony/blocks": "workspace:*",
"@joincolony/utils": "workspace:*"
}
}
65 changes: 6 additions & 59 deletions apps/main-chain/src/amplifyClient.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,8 @@
import { Amplify, API, graphqlOperation } from 'aws-amplify';
import { GraphQLQuery } from '@aws-amplify/api';
import { DocumentNode, isExecutableDefinitionNode } from 'graphql';
import { verbose } from '~utils';
import { AmplifyClient } from '@joincolony/clients';

export default (): void => {
Amplify.configure({
aws_appsync_graphqlEndpoint: `${process.env.AWS_APPSYNC_ENDPOINT}`,
aws_appsync_authenticationType: 'API_KEY',
aws_appsync_apiKey: process.env.AWS_APPSYNC_KEY,
});
};
const amplifyClient = new AmplifyClient(
process.env.AWS_APPSYNC_ENDPOINT || '',
process.env.AWS_APPSYNC_KEY || '',
);

export type GraphQLFnReturn<T> = Promise<
ReturnType<typeof API.graphql<GraphQLQuery<T>>> | undefined
>;

export const query = async <T, TVariables extends Record<string, unknown>>(
queryDocument: DocumentNode,
variables?: TVariables,
): GraphQLFnReturn<T> => {
try {
const result = await API.graphql<GraphQLQuery<T>>(
graphqlOperation(queryDocument, variables),
);

return result;
} catch (error) {
const definitionNode = queryDocument.definitions[0];
const queryName = isExecutableDefinitionNode(definitionNode)
? definitionNode.name?.value
: 'Unknown';
console.error(`Could not fetch query ${queryName}`, error);
return undefined;
}
};

export const mutate = async <
T,
TVariables extends Record<string, unknown> = {},
>(
mutationDocument: DocumentNode,
variables?: TVariables,
): GraphQLFnReturn<T> => {
try {
const result = await API.graphql<GraphQLQuery<T>>(
graphqlOperation(mutationDocument, variables),
);

return result;
} catch (error: any) {
const definitionNode = mutationDocument.definitions[0];
const mutationName = isExecutableDefinitionNode(definitionNode)
? definitionNode.name?.value
: 'Unknown';

const errMsg = 'errors' in error ? error.errors : error;
verbose(`Could not execute mutation ${mutationName}. Error: `, errMsg);
return undefined;
}
};
export default amplifyClient;
59 changes: 0 additions & 59 deletions apps/main-chain/src/blockListener.ts

This file was deleted.

8 changes: 8 additions & 0 deletions apps/main-chain/src/blockManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BlockManager } from '@joincolony/blocks';
import eventManager from '~eventManager';
import rpcProvider from '~provider';
import statsManager from '~statsManager';

const blockManager = new BlockManager(eventManager, rpcProvider, statsManager);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay this class setup is really nice when it leads to such nice simple files as this 😌


export default blockManager;
Loading