Skip to content

Commit

Permalink
feat: use the kilt indexer (#2211)
Browse files Browse the repository at this point in the history
## fixes KILTprotocol/ticket#3555


Replaces the Logic depending from [Subscan](https://spiritnet.subscan.io/) with Logic depending from the [KILT Indexer](https://indexer.kilt.io/).

Commits: 

* feat: code from cTypeHub

* feat: whole attestation fragment

* feat: interface to talk with indexer

* fix: use right environment constant

* chore: add development comment as help

* feat: indexer to configuration

* feat: block interface

* feat: queryExpiredAttestations

* feat: add createdAt to queried attestations

* feat: replace getExpiredAttestations with queryExpiredAttestations

* fix: parse attestations to old interface

* feat: explainer for attestationParser

* fix: wipe subscan files

* fix: tests to use new functions

* fix: delete unused file

* fix: an import

* chore: add To -dos

* feat: query filter for not-removed attestations

* fix: delete subscan from the configuration

* fix: make pretty with an extra line

* feat: export interface to use on tests

* fix: format the query

* fix: use function from kilt sdk instead

* feat: tests for queryFromIndexer.ts

* fix: make it more interesting

* feat: blockMocker and new test

* fix: a log

* refactor: parameter phobia

* Revert "refactor: parameter phobia"

This reverts commit e646c65.

* refactor: let the Indexer figure it out

* Revert "refactor: let the Indexer figure it out"

This reverts commit 614beca.

* refactor: no parameter for queryExpiredAttestations() & handle pending DID before filling Inventory

Fusuion of these two commits:

* refactor: let the Indexer figure it out

* suggestion

* feat: test for when there is no indexer endpoint

* fix: cleanup a bit

* try: to solve test on workflow

* fix: add an empty line

* feat: add assertions on some expected calls

* feat: import some stuff for the tests

* feat: some functioning tests for queryAttestation.ts

* feat: a broken test because time is hard to control

* try: another failed attempt

* Revert "try: another failed attempt"

This reverts commit 4d75044.

* fix: chronus the god of time

* fix: clean up a bit

* chore: show other problem

* fix: just use the real thing

* feat: test to check start value of `fromDate`

* feat: test to check the yield types

* fix: reword a test description

* fix: add some empty lines

* fix: reduce unnecessary variables

* fix: use shorthand

* fix: make more readable

* fix: remove unnecessary test setup line

* fix: only test once

* fix: shorten a hand

* feat: allow to specify the results structure for FetchedData

* chore: delete to-dos

* fix: move explainers from tests to real code

* fix: shorten another hand
  • Loading branch information
kilted-andres authored Sep 23, 2024
1 parent 193ab62 commit f4c1c5c
Show file tree
Hide file tree
Showing 17 changed files with 818 additions and 693 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
PORT=3000
URL=http://localhost:3000
BLOCKCHAIN_ENDPOINT=wss://peregrine.kilt.io
SUBSCAN_NETWORK=kilt-testnet
IS_TEST_ENV=false
AWS_REGION="eu-central-1"
AWS_ACCESS_KEY_ID=
Expand All @@ -28,4 +27,4 @@ SECRET_INSTAGRAM=
YOUTUBE_CLIENT_ID=
SECRET_YOUTUBE_CLIENT=
API_KEY_STEAM=
SECRET_SUBSCAN=
GRAPHQL_ENDPOINT=https://dev-indexer.kilt.io/
2 changes: 1 addition & 1 deletion src/backend/didConfiguration/wellKnownDidConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function handler(
logger.debug('DID configuration started');
const didConfigResource = await didConfigResourcePromise;

logger.debug('DID configuration started');
logger.debug('DID configuration resolved');
return h.response(didConfigResource);
}

Expand Down
12 changes: 7 additions & 5 deletions src/backend/revoker/expiredInventory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import { describe, it, expect, jest } from '@jest/globals';

import { getExpiredAttestations } from './getExpiredAttestations';
import { AttestationInfo } from './scanAttestations';
import {
AttestationInfo,
queryExpiredAttestations,
} from './indexer/queryAttestations';
import {
attestationsToRemove,
attestationsToRemoveLater,
Expand All @@ -17,8 +19,8 @@ import {
import { batchQueryRevoked } from './batchQueryRevoked';

jest.mock('../utilities/configuration', () => ({ configuration: {} }));
jest.mock('./getExpiredAttestations', () => ({
getExpiredAttestations: jest.fn(),
jest.mock('./indexer/queryAttestations', () => ({
queryExpiredAttestations: jest.fn(),
}));
jest.mock('./batchQueryRevoked');

Expand Down Expand Up @@ -57,7 +59,7 @@ const alreadyRevoked: AttestationInfo = {
revoked: true,
};

jest.mocked(getExpiredAttestations).mockImplementation(async function* () {
jest.mocked(queryExpiredAttestations).mockImplementation(async function* () {
yield toRemove;
yield toRevoke;
yield alreadyRevoked;
Expand Down
16 changes: 12 additions & 4 deletions src/backend/revoker/expiredInventory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { sleep } from '../utilities/sleep';
import { configuration } from '../utilities/configuration';

import { getExpiredAttestations } from './getExpiredAttestations';
import { AttestationInfo } from './scanAttestations';
import { shouldBeRemoved } from './shouldBeExpired';
import { batchQueryRevoked } from './batchQueryRevoked';
import {
AttestationInfo,
queryExpiredAttestations,
} from './indexer/queryAttestations';

import { shouldBeRemoved } from './shouldBeExpired';

const SCAN_INTERVAL_MS = 60 * 60 * 1000;

Expand Down Expand Up @@ -32,7 +36,7 @@ export async function fillExpiredInventory() {
attestationsToRemove.push(...expiredSinceLastRun);
attestationsToRemoveLater.splice(0, expiredSinceLastRun.length);

for await (const expiredAttestation of getExpiredAttestations()) {
for await (const expiredAttestation of queryExpiredAttestations()) {
if (shouldBeRemoved(expiredAttestation)) {
include(attestationsToRemove, expiredAttestation);
} else {
Expand All @@ -46,6 +50,10 @@ export async function fillExpiredInventory() {

export function initExpiredInventory() {
(async () => {
if (configuration.did === 'pending') {
return;
}

while (true) {
await fillExpiredInventory();
await sleep(SCAN_INTERVAL_MS);
Expand Down
67 changes: 0 additions & 67 deletions src/backend/revoker/getExpiredAttestations.test.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/backend/revoker/getExpiredAttestations.ts

This file was deleted.

38 changes: 38 additions & 0 deletions src/backend/revoker/indexer/fragments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// GraphQL provides reusable units called fragments.
// Fragments let you construct sets of fields, and then include them in queries where needed.
// You can use the fragments by including them as fields prefixed by 3 points "...".
// See documentation here: https://graphql.org/learn/queries/#fragments
// Try out yourself under https://indexer.kilt.io/ & https://dev-indexer.kilt.io/

export const wholeBlock = `
fragment wholeBlock on Block {
id
hash
timeStamp
}`;

export const DidNames = `
fragment DidNames on Did {
id
web3NameId
}`;

export const wholeAttestation = `
fragment wholeAttestation on Attestation {
id
claimHash
cTypeId
issuerId
payer
delegationID
valid
creationBlock {
...wholeBlock
}
revocationBlock {
...wholeBlock
}
removalBlock {
...wholeBlock
}
}`;
Loading

0 comments on commit f4c1c5c

Please sign in to comment.