Skip to content

Commit

Permalink
Debug DDO hashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariacarmina committed Dec 6, 2024
1 parent d2185dc commit c0998cd
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/components/Indexer/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
90 changes: 87 additions & 3 deletions src/components/Indexer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,91 @@ export function findServiceIdByDatatoken(ddo: any, datatokenAddress: string): st
return serviceIdToFind
}

export async function getPricingStatsForDddo(ddo: any, signer: Signer): Promise<any> {
// 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<any> {
if (!ddo.indexedMetadata) {
ddo.indexedMetadata = {}
}
Expand Down Expand Up @@ -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(
Expand All @@ -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',
Expand Down

0 comments on commit c0998cd

Please sign in to comment.