Skip to content

Commit

Permalink
Change IPLD block structure
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh0 committed Oct 6, 2021
1 parent af4c6d4 commit 13dfd9e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
24 changes: 20 additions & 4 deletions packages/codegen/src/templates/hooks-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,25 @@ export async function handleBlock (indexer: Indexer, jobData: any): Promise<void
const block = event.block;
const contractAddress = event.contract;

const ipldBlockData: any = {};

const oldIpldBlock = await indexer.getIPLDBlock(block, contractAddress);

const ipldBlockData: any = {};
if (!oldIpldBlock) {
ipldBlockData.meta = {
id: contractAddress,
kind: 'diff',
parent: {
'/': null
}
};

ipldBlockData.ethBlock = {
cid: await indexer.getBlockCID(block.blockHash),
num: block.blockNumber
};
}

const eventData = indexer.getResultEvent(event);

switch (event.eventName) {
Expand All @@ -48,8 +64,8 @@ export async function handleBlock (indexer: Indexer, jobData: any): Promise<void
// }
// }
// }
_.set(ipldBlockData, `_balances[${from}]`, fromBalance);
_.set(ipldBlockData, `_balances[${to}]`, toBalance);
_.set(ipldBlockData, `state._balances[${from}]`, fromBalance);
_.set(ipldBlockData, `state._balances[${to}]`, toBalance);

break;
}
Expand All @@ -67,7 +83,7 @@ export async function handleBlock (indexer: Indexer, jobData: any): Promise<void
// }
// }
// }
_.set(ipldBlockData, `_allowances[${owner}][${spender}]`, allowance);
_.set(ipldBlockData, `state._allowances[${owner}][${spender}]`, allowance);

break;
}
Expand Down
18 changes: 18 additions & 0 deletions packages/codegen/src/templates/indexer-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,24 @@ export class Indexer {
return this._db.saveOrUpdateIPLDBlock(ipldBlock);
}

async getBlockCID (blockHash: string): Promise<string> {
assert(blockHash);

const {
allEthHeaderCids: {
nodes: [
{
cid
}
]
}
} = await this._postgraphileClient.getBlockWithTransactions({ blockHash });

assert(cid);

return cid;
}

async triggerIndexingOnEvent (event: Event): Promise<void> {
const resultEvent = this.getResultEvent(event);

Expand Down

0 comments on commit 13dfd9e

Please sign in to comment.