Skip to content

Commit

Permalink
initial caching event fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
vibern0 committed May 21, 2020
1 parent f9fc716 commit 0ff356b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/loaders/subscribers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ import CommunityService from '../services/community';
export default async (): Promise<void> => {
const provider = new ethers.providers.JsonRpcProvider(config.jsonRpcUrl);
const startFrom = await startFromBlock(provider, config.impactMarketContractBlockNumber);
await updateImpactMarketCache(provider, startFrom);
const fromLogs = await updateImpactMarketCache(provider, startFrom);
fromLogs.forEach((community) => updateCommunityCache(
community.block === undefined
? startFrom
: community.block,
provider,
community.address
));
// Because we are filtering events by address
// when the community is created, the first coordinator
// is actually added by impactmarket in an internal transaction.
Expand Down
4 changes: 2 additions & 2 deletions src/subscribers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async function subscribeChainEvents(
) => {
addToTransactionCache(event);
// it's necessary to get CoordinatorAdded here!
updateCommunityCache(event.blockNumber - 1, provider, config.impactMarketContractAddress);
updateCommunityCache(event.blockNumber - 1, provider, _addr);
communitiesCallbackFn(_addr);
});
impactMarketInstance.on('CommunityRemoved', async (_addr, event) => addToTransactionCache(event));
Expand Down Expand Up @@ -182,7 +182,7 @@ async function updateImpactMarketCache(
return communitiesAdded;
}

async function updateCommunityCache(
function updateCommunityCache(
startFromBlock: number,
provider: ethers.providers.JsonRpcProvider,
contractAddress: string,
Expand Down

0 comments on commit 0ff356b

Please sign in to comment.