diff --git a/packages/plugins/packages/payloadset/packages/crypto/packages/nft/src/Diviner.ts b/packages/plugins/packages/payloadset/packages/crypto/packages/nft/src/Diviner.ts index cc438c6865a..d0b0dd091dc 100644 --- a/packages/plugins/packages/payloadset/packages/crypto/packages/nft/src/Diviner.ts +++ b/packages/plugins/packages/payloadset/packages/crypto/packages/nft/src/Diviner.ts @@ -1,4 +1,5 @@ import { AbstractDiviner } from '@xyo-network/abstract-diviner' +import { PayloadHasher } from '@xyo-network/core' import { isNftInfoPayload, NftScoreDivinerConfig, @@ -23,6 +24,14 @@ export const isNftScorePayload = (payload: Payload): payload is NftScorePayload export class NftScoreDiviner extends AbstractDiviner { static override configSchemas = [NftScoreDivinerConfigSchema] - protected override divineHandler = async (payloads?: Payload[]): Promise => - (await Promise.all(payloads?.filter(isNftInfoPayload).map(analyzeNft) ?? [])).map(toNftScorePayload) + protected override divineHandler = async (payloads?: Payload[]): Promise => { + const nfts = payloads?.filter(isNftInfoPayload) ?? [] + const results = await Promise.all( + nfts.map>(async (p) => { + const [score, sourceHash] = await Promise.all([toNftScorePayload(await analyzeNft(p)), PayloadHasher.hashAsync(p)]) + return { ...score, sources: [sourceHash] } + }), + ) + return results + } } diff --git a/packages/plugins/packages/payloadset/packages/crypto/packages/nft/src/spec/Diviner.spec.ts b/packages/plugins/packages/payloadset/packages/crypto/packages/nft/src/spec/Diviner.spec.ts index 2393e32b21f..f42d45d867e 100644 --- a/packages/plugins/packages/payloadset/packages/crypto/packages/nft/src/spec/Diviner.spec.ts +++ b/packages/plugins/packages/payloadset/packages/crypto/packages/nft/src/spec/Diviner.spec.ts @@ -21,13 +21,17 @@ describe('NftScoreDiviner', () => { }) test('divine', async () => { const diviner = await NftScoreDiviner.create({ account: await HDWallet.random() }) - const result = await diviner.divine(data) - const scores = result.filter(isNftScorePayload) - expect(scores.length).toBeGreaterThan(0) - expect(result.length).toEqual(scores.length) - for (const score of scores) { + const scores = (await diviner.divine(data)).filter(isNftScorePayload) + expect(scores).toBeArrayOfSize(data.length) + for (let i = 0; i < scores.length; i++) { + const score = scores[i] const wrapped = PayloadWrapper.wrap(score) expect(await wrapped.getValid()).toBe(true) + const payload = wrapped.payload() + expect(payload?.sources).toBeArrayOfSize(1) + expect(payload?.sources?.[0]).toBeString() + const sourceHash = await PayloadWrapper.wrap(data[i]).hashAsync() + expect(payload?.sources?.[0]).toBe(sourceHash) } }) })