Skip to content

Commit

Permalink
feat: decouple blockListener and blockProcessor into a new blockManager
Browse files Browse the repository at this point in the history
instance
  • Loading branch information
bassgeta committed Dec 3, 2024
1 parent 687545c commit 796783e
Show file tree
Hide file tree
Showing 20 changed files with 602 additions and 513 deletions.
2 changes: 2 additions & 0 deletions apps/main-chain/src/amplifyClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ const amplifyClient = new AmplifyClient(
process.env.AWS_APPSYNC_KEY || '',
);

// @TODO stop exporting mutate and query like this because "this.methodName" loses context
const { mutate, query } = amplifyClient;
export { mutate, query };
export default amplifyClient;
65 changes: 0 additions & 65 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);

export default blockManager;
225 changes: 0 additions & 225 deletions apps/main-chain/src/blockProcessor.ts

This file was deleted.

3 changes: 2 additions & 1 deletion apps/main-chain/src/eventManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EventManager } from '@joincolony/blocks';
import rpcProvider from '~provider';

const eventManager = new EventManager();
const eventManager = new EventManager(rpcProvider);

export default eventManager;
5 changes: 3 additions & 2 deletions apps/main-chain/src/handlers/colonies/colonyAdded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
import { coloniesSet } from '~stats';
import { ContractEvent, ContractEventsSignatures } from '~types';
import {
updateStats,
createColonyFounderInitialRoleEntry,
getAllRoleEventsFromTransaction,
} from '~utils';
import statsManager from '~statsManager';
import { getColonyContributorId } from '~utils/contributors';
import { tryFetchGraphqlQuery } from '~utils/graphql';
import { createUniqueColony } from './helpers/createUniqueColony';
Expand Down Expand Up @@ -50,8 +50,9 @@ export default async (event: ContractEvent): Promise<void> => {
/*
* Add it to the Set
*/
// @NOTE seems to not be working, is it borken on master too?
coloniesSet.add(JSON.stringify({ colonyAddress, tokenAddress }));
await updateStats({ trackedColonies: coloniesSet.size });
await statsManager.updateStats({ trackedColonies: coloniesSet.size });

output(
'Found new Colony:',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { utils } from 'ethers';
import { ExtensionEventListener } from '~eventListeners';
import { ColonyActionType } from '@joincolony/graphql';
import { getInterfaceByListener } from '~interfaces';
import rpcProvider from '~provider';
import { ContractEventsSignatures, EventHandler } from '~types';
import {
Expand All @@ -12,6 +11,7 @@ import {
toNumber,
writeActionFromEvent,
} from '~utils';
import eventManager from '~eventManager';

export const handleStagedPaymentReleased: EventHandler = async (
event,
Expand Down Expand Up @@ -47,7 +47,7 @@ export const handleStagedPaymentReleased: EventHandler = async (
topics: [utils.id(ContractEventsSignatures.StagedPaymentReleased)],
});

const iface = getInterfaceByListener(listener);
const iface = eventManager.getInterfaceByListener(listener);
if (!iface) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions apps/main-chain/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'cross-fetch/polyfill';
import { utils } from 'ethers';

import { startBlockListener } from '~blockListener';
import '~amplifyClient';
import '~statsManager';
import '~eventManager';
import blockManager from '~blockManager';
import { startStatsServer } from '~stats';
import {
setupListenersForColonies,
Expand All @@ -16,6 +17,7 @@ import { setupNotificationsClient } from '~utils/notifications';
utils.Logger.setLogLevel(utils.Logger.levels.ERROR);

const start = async (): Promise<void> => {
await rpcProvider.initialiseProvider();
/**
* Setup the notifications provider so that notifications can be sent when needed
*/
Expand All @@ -36,9 +38,7 @@ const start = async (): Promise<void> => {
/**
* Start the main block listener
*/
startBlockListener();

await rpcProvider.initialiseProvider();
blockManager.startBlockListener();

/**
* In development, where both the chain and the DB gets reset everytime,
Expand Down
Loading

0 comments on commit 796783e

Please sign in to comment.