diff --git a/src/components/Indexer/processor.ts b/src/components/Indexer/processor.ts index a3a642357..40eafe275 100644 --- a/src/components/Indexer/processor.ts +++ b/src/components/Indexer/processor.ts @@ -141,8 +141,11 @@ class BaseEventProcessor { } protected checkDdoHash(decryptedDocument: any, documentHashFromContract: any): boolean { + INDEXER_LOGGER.logMessage(`decrypted document: ${JSON.stringify(decryptedDocument)}`) const utf8Bytes = toUtf8Bytes(JSON.stringify(decryptedDocument)) const expectedMetadata = hexlify(utf8Bytes) + INDEXER_LOGGER.logMessage(`hash: ${create256Hash(expectedMetadata.toString())}`) + INDEXER_LOGGER.logMessage(`ctr hash: ${documentHashFromContract}`) if (create256Hash(expectedMetadata.toString()) !== documentHashFromContract) { INDEXER_LOGGER.error(`DDO checksum does not match.`) return false @@ -372,6 +375,9 @@ export class MetadataEventProcessor extends BaseEventProcessor { ) return } + INDEXER_LOGGER.logMessage( + `decrypted document from contract: ${JSON.stringify(ddo)}` + ) // for unencrypted DDOs if (parseInt(flag) !== 2 && !this.checkDdoHash(updatedDdo, metadataHash)) { return diff --git a/src/components/Indexer/utils.ts b/src/components/Indexer/utils.ts index 18a9690d8..e004421fb 100644 --- a/src/components/Indexer/utils.ts +++ b/src/components/Indexer/utils.ts @@ -344,7 +344,91 @@ export function findServiceIdByDatatoken(ddo: any, datatokenAddress: string): st return serviceIdToFind } -export async function getPricingStatsForDddo(ddo: any, signer: Signer): Promise { +// export async function getPricingSchemas(datatoken: ethers.Contract, signer: Signer) { +// let dispensers = [] +// let fixedRates = [] +// const prices = [] +// try { +// dispensers = await datatoken.getDispensers() +// INDEXER_LOGGER.logMessage(`dt ctr call for disp: ${await datatoken.getDispensers()}`) +// INDEXER_LOGGER.logMessage(`dispensers: ${dispensers}`) +// } catch (e) { +// INDEXER_LOGGER.error(`Contract call fails when retrieving dispensers: ${e}`) +// } +// try { +// fixedRates = await datatoken.getFixedRates() +// INDEXER_LOGGER.logMessage(`dt ctr call for fre: ${await datatoken.getFixedRates()}`) +// } catch (e) { +// INDEXER_LOGGER.error(`Contract call fails when retrieving fixed rate exchanges: ${e}`) +// } +// if (dispensers.length === 0 && fixedRates.length === 0) { +// INDEXER_LOGGER.logMessage(`a intrat pe aici`) +// ddo.indexedMetadata.stats.push({ +// datatokenAddress: service.datatokenAddress, +// name: await datatoken.name(), +// serviceId: service.id, +// orders: 0, +// prices: [] +// }) +// INDEXER_LOGGER.logMessage( +// `ddo with indexedMetadata w/o disp and fre: ${JSON.stringify(ddo)}` +// ) +// } else { +// if (dispensers) { +// INDEXER_LOGGER.logMessage(`a intrat pe disp: ${dispensers}`) +// for (const dispenser of dispensers) { +// const dispenserContract = new ethers.Contract(dispenser, Dispenser.abi, signer) +// INDEXER_LOGGER.logMessage(`disp ctr: ${dispenserContract}`) +// if ((await dispenserContract.status())[0] === true) { +// INDEXER_LOGGER.logMessage(`disp ctr call: ${await dispenserContract.status()}`) +// ddo.indexedMetadata.stats.push({ +// datatokenAddress: service.datatokenAddress, +// name: await datatoken.name(), +// serviceId: service.id, +// orders: 0, +// prices: prices.push({ +// type: 'dispenser', +// price: '0', +// contract: dispenser +// }) +// }) +// } +// } +// } + +// if (fixedRates) { +// for (const fixedRate of fixedRates) { +// const fixedRateContract = new ethers.Contract( +// fixedRate.address, +// FixedRateExchange.abi, +// signer +// ) +// const exchange = await fixedRateContract.getExchange(fixedRate.id) +// if (exchange[6] === true) { +// ddo.indexedMetadata.stats.push({ +// datatokenAddress: service.datatokenAddress, +// name: await datatoken.name(), +// serviceId: service.id, +// orders: 0, // just created +// prices: prices.push({ +// type: 'fixedrate', +// price: exchange[5], +// token: exchange[3], +// contract: fixedRate, +// exchangeId: fixedRate.id +// }) +// }) +// } +// } +// } +// } +// } + +export async function getPricingStatsForDddo( + ddo: any, + signer: Signer, + datatokenAddress?: string +): Promise { if (!ddo.indexedMetadata) { ddo.indexedMetadata = {} } @@ -385,7 +469,7 @@ export async function getPricingStatsForDddo(ddo: any, signer: Signer): Promise< datatokenAddress: service.datatokenAddress, name: await datatoken.name(), serviceId: service.id, - orders: 0, // just created + orders: 0, prices: [] }) INDEXER_LOGGER.logMessage( @@ -405,7 +489,7 @@ export async function getPricingStatsForDddo(ddo: any, signer: Signer): Promise< datatokenAddress: service.datatokenAddress, name: await datatoken.name(), serviceId: service.id, - orders: 0, // just created + orders: 0, prices: prices.push({ type: 'dispenser', price: '0',