Skip to content

Commit

Permalink
fix(storage): in memory indexer metadata (#1234)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjlevesque authored Nov 10, 2023
1 parent 3786eba commit 9088c79
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
31 changes: 17 additions & 14 deletions packages/data-access/src/combined-data-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ export abstract class CombinedDataAccess implements DataAccessTypes.IDataAccess
constructor(
protected reader: DataAccessTypes.IDataRead,
protected writer: DataAccessTypes.IDataWrite,
) {
this.getTransactionsByChannelId = this.reader.getTransactionsByChannelId.bind(this.reader);
this.getChannelsByTopic = this.reader.getChannelsByTopic.bind(this.reader);
this.getChannelsByMultipleTopics = this.reader.getChannelsByMultipleTopics.bind(this.reader);
this.persistTransaction = this.writer.persistTransaction.bind(this.writer);
}
) {}

async initialize(): Promise<void> {
await this.reader.initialize();
Expand All @@ -21,22 +16,30 @@ export abstract class CombinedDataAccess implements DataAccessTypes.IDataAccess
await this.reader.close();
}

getTransactionsByChannelId: (
async getTransactionsByChannelId(
channelId: string,
updatedBetween?: DataAccessTypes.ITimestampBoundaries | undefined,
) => Promise<DataAccessTypes.IReturnGetTransactions>;
): Promise<DataAccessTypes.IReturnGetTransactions> {
return await this.reader.getTransactionsByChannelId(channelId, updatedBetween);
}

getChannelsByTopic: (
async getChannelsByTopic(
topic: string,
updatedBetween?: DataAccessTypes.ITimestampBoundaries | undefined,
) => Promise<DataAccessTypes.IReturnGetChannelsByTopic>;
getChannelsByMultipleTopics: (
): Promise<DataAccessTypes.IReturnGetChannelsByTopic> {
return await this.reader.getChannelsByTopic(topic, updatedBetween);
}
async getChannelsByMultipleTopics(
topics: string[],
updatedBetween?: DataAccessTypes.ITimestampBoundaries,
) => Promise<DataAccessTypes.IReturnGetChannelsByTopic>;
persistTransaction: (
): Promise<DataAccessTypes.IReturnGetChannelsByTopic> {
return await this.reader.getChannelsByMultipleTopics(topics, updatedBetween);
}
async persistTransaction(
transactionData: DataAccessTypes.ITransaction,
channelId: string,
topics?: string[] | undefined,
) => Promise<DataAccessTypes.IReturnPersistTransaction>;
): Promise<DataAccessTypes.IReturnPersistTransaction> {
return await this.writer.persistTransaction(transactionData, channelId, topics);
}
}
10 changes: 5 additions & 5 deletions packages/data-access/src/in-memory-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ export class InMemoryIndexer implements StorageTypes.IIndexer {
.flat()
.map(
(item): StorageTypes.IIndexedTransaction => ({
blockNumber: 0,
blockTimestamp: 0,
blockNumber: item.meta.ethereum?.blockNumber ?? 0,
blockTimestamp: item.meta.ethereum?.blockTimestamp ?? 0,
channelId: item.channelId,
hash: item.locationId,
size: '0',
smartContractAddress: '',
size: String(item.meta.ipfs?.size ?? 0),
smartContractAddress: item.meta.ethereum?.smartContractAddress ?? '',
topics: [],
transactionHash: '',
transactionHash: item.meta.ethereum?.transactionHash ?? '',
data: item.transaction.data,
encryptedData: item.transaction.encryptedData,
encryptionMethod: item.transaction.encryptionMethod,
Expand Down
5 changes: 1 addition & 4 deletions packages/request-client.js/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,6 @@ describe('request-client.js', () => {

// This test checks that 2 payments with reference `c19da4923539c37f` have reached 0xc12F17Da12cd01a9CDBB216949BA0b41A6Ffc4EB
it('can get the balance of an ETH request', async () => {
jest.useFakeTimers();
const etherscanMock = new EtherscanProviderMock();
ethers.providers.EtherscanProvider.prototype.getHistory = jest
.fn()
Expand Down Expand Up @@ -1350,8 +1349,8 @@ describe('request-client.js', () => {
requestInfo,
signer: TestData.payee.identity,
});
await request.waitForConfirmation();

jest.advanceTimersByTime(150);
const data = await request.refresh();

// Payment reference should be fixed
Expand All @@ -1363,7 +1362,6 @@ describe('request-client.js', () => {
),
).toBe('efce79375b2db9f7');

jest.advanceTimersByTime(150);
const dataAfterRefresh = await request.refresh();

expect(dataAfterRefresh.balance?.balance).toBe('12300000000');
Expand All @@ -1374,7 +1372,6 @@ describe('request-client.js', () => {
expect(dataAfterRefresh.balance?.events[0].parameters!.txHash).toBe(
'0x06d95c3889dcd974106e82fa27358549d9392d6fee6ea14fe1acedadc1013114',
);
jest.useRealTimers();
});

it('can disable and enable the get the balance of a request', async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/thegraph-data-access/src/data-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class TheGraphDataAccess extends CombinedDataAccess {
}

/** intercept events so that confirmation is emitted only once the transaction is indexed */
persistTransaction = async (
async persistTransaction(
transactionData: DataAccessTypes.ITransaction,
channelId: string,
topics?: string[] | undefined,
): Promise<DataAccessTypes.IReturnPersistTransaction> => {
): Promise<DataAccessTypes.IReturnPersistTransaction> {
const eventEmitter = new EventEmitter() as DataAccessTypes.PersistTransactionEmitter;
const result = await this.writer.persistTransaction(transactionData, channelId, topics);
result.on('confirmed', (receipt) => {
Expand All @@ -48,7 +48,7 @@ export class TheGraphDataAccess extends CombinedDataAccess {
});
result.on('error', (e) => eventEmitter.emit('error', e));
return Object.assign(eventEmitter, { meta: result.meta, result: result.result });
};
}

/**
* We wait until the data is indexed on TheGraph
Expand Down

0 comments on commit 9088c79

Please sign in to comment.