Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace subscan with kilt-indexer #743

Merged
merged 107 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
0378f7f
feat: empty file
kilted-andres Jul 24, 2024
f913ef1
feat: apollo client dependency
kilted-andres Jul 24, 2024
bc9aeed
feat: first query
kilted-andres Jul 24, 2024
00a578b
fix: stop using subscan
kilted-andres Jul 24, 2024
8d845a8
feat: graphQL endpoint as environment variable
kilted-andres Jul 24, 2024
93825fb
fix: move and rename file
kilted-andres Jul 24, 2024
879894d
fix: remove dummy string
kilted-andres Jul 24, 2024
3b03439
feat: good generic query
kilted-andres Jul 24, 2024
5208f19
chore: save end of day
kilted-andres Jul 24, 2024
90cea11
feat: handle "nodes" missing from query
kilted-andres Jul 29, 2024
a02a990
feat: handle error by bad query
kilted-andres Jul 29, 2024
d641a0e
Revert "feat: handle error by bad query"
kilted-andres Jul 29, 2024
aa9945e
feat: file with some fragments for the queries
kilted-andres Jul 30, 2024
3925261
feat: first version of queryCTypes.ts
kilted-andres Jul 30, 2024
6387a24
fix: rename function and improve comments/logs
kilted-andres Jul 30, 2024
505fb54
feat: watchIndexer
kilted-andres Jul 30, 2024
ad3521f
feat: save attestationsCount directly from initial query
kilted-andres Jul 30, 2024
08f4773
chore: clean up some commented code
kilted-andres Jul 30, 2024
abdfca5
chore: delete some commented code
kilted-andres Jul 30, 2024
e5f113b
fix: interpret timeStamp as UTC
kilted-andres Jul 30, 2024
87e4a1d
fix: delete unnecessary Attestations Model
kilted-andres Jul 30, 2024
ba21bef
fix: delete attestations migration
kilted-andres Jul 30, 2024
5de26bf
fix: delete watchSubscan()
kilted-andres Jul 30, 2024
780aae5
feat: comment on query about order
kilted-andres Jul 30, 2024
69cbf11
feat: function to update Attestation count
kilted-andres Jul 30, 2024
4a5c2be
fix: delete unnecessary snippet
kilted-andres Jul 30, 2024
80782fe
fix: a filter searching on our database
kilted-andres Jul 30, 2024
efed667
feat: updateAttestationsCount in watchIndexer
kilted-andres Jul 30, 2024
29d9bf5
fix: delete other remanence of Subscan
kilted-andres Jul 30, 2024
253d674
chore: add todo
kilted-andres Jul 30, 2024
1f88c60
feat: function to write queries
kilted-andres Aug 6, 2024
ef6f286
fix: make function way more dynamic
kilted-andres Aug 6, 2024
2abf449
feat: matchesGenerator() takes parameter instead of written query
kilted-andres Aug 6, 2024
bbfdee0
fix: use date instead of block to filter
kilted-andres Aug 6, 2024
8cf0f3f
chore: delete completed TODO
kilted-andres Aug 6, 2024
74e7e3e
feat: some explainers
kilted-andres Aug 6, 2024
bef1bdb
fix: a log
kilted-andres Aug 6, 2024
1379038
fix: generic type parameter for matchesGenerator()
kilted-andres Aug 6, 2024
3a66578
fix: set production values for some constants again
kilted-andres Aug 6, 2024
d54f999
chore: delete old explicit query texts
kilted-andres Aug 6, 2024
2253dae
fix: display registration block instead of transaction
kilted-andres Aug 6, 2024
d237871
fix: delete extrinsicHash from ctype model
kilted-andres Aug 6, 2024
54d70c4
fix: remove residuals of Attestation Model
kilted-andres Aug 6, 2024
8f35e54
fix: delete other residuals of attestations
kilted-andres Aug 6, 2024
59a1ef1
fix: rescue the old migrations from main
kilted-andres Aug 7, 2024
8befb7d
chore: make prettier
kilted-andres Aug 7, 2024
04d0810
feat: migration to drop attestations
kilted-andres Aug 7, 2024
b4f79b7
fix: remove property extrinsicHash from cTypes table
kilted-andres Aug 7, 2024
d0c51c5
fix: make attestationsCount on cType Model a number
kilted-andres Aug 7, 2024
0d3c93a
fix: remove tracks of extrinsicHash
kilted-andres Aug 7, 2024
6e1e426
fix: remove unused import
kilted-andres Aug 7, 2024
3492af4
feat: make polkadot.js rpc endpoint dynamic
kilted-andres Aug 8, 2024
ba7a804
fix: reduce lines by one
kilted-andres Aug 8, 2024
8ac7a3e
fix: rename from attestationsCount to attestationsCreated
kilted-andres Aug 8, 2024
beec543
feat: migration to add attestationsCreated field on cTypes table
kilted-andres Aug 8, 2024
73919aa
feat: POLKADOT_RPC_ENDPOINT on env example
kilted-andres Aug 9, 2024
1960db3
fix: delete unnecessary casting
kilted-andres Aug 9, 2024
863f616
fix: move all interfaces outside of functions
kilted-andres Aug 9, 2024
4722af4
fix: use update() instead of findOne() and save()
kilted-andres Aug 9, 2024
aa94ed3
fix: delete unused dependency "apollo"
kilted-andres Aug 9, 2024
aa4a8af
fix: rename T to ExpectedQueryResults
kilted-andres Aug 9, 2024
5080cb0
fix: add comment to impossible case
kilted-andres Aug 9, 2024
ba596a4
fix: replace an "else" with a "return"
kilted-andres Aug 9, 2024
c56ad4b
fix: use semantic syntax
kilted-andres Aug 9, 2024
56aba0d
fix: exclude default value from creation form
kilted-andres Aug 9, 2024
53927a9
fix: use less confusing naming
kilted-andres Aug 9, 2024
0f80f20
fix: delete Attestation from a test
kilted-andres Aug 9, 2024
9c835f1
fix: improve comment
kilted-andres Aug 9, 2024
355f261
fix: delete unused variable
kilted-andres Aug 9, 2024
67b97bc
fix: delete commented out code
kilted-andres Aug 9, 2024
efb96c9
chore: attend some pnpm complains
kilted-andres Aug 9, 2024
1eab054
chore: try to update all dependencies to the latest
kilted-andres Aug 9, 2024
972506e
fix: replace eslint-config-standard-with-typescript with eslint-confi…
kilted-andres Aug 9, 2024
f581b1c
fix: eslint error
kilted-andres Aug 9, 2024
472e9cb
fix: Rename .eslintrc.json to .eslintrc.cjs
kilted-andres Aug 9, 2024
7d78566
fix: go back to github formatter
kilted-andres Aug 9, 2024
3ee5e3c
fix: use stylelint-actions-formatter and .json
kilted-andres Aug 9, 2024
fa929e7
fix: turn .eslintrc.json into .eslintrc.js
kilted-andres Aug 9, 2024
e6a7951
fix: use esm syntax on .eslintrc.js
kilted-andres Aug 9, 2024
5574b4f
fix: add --no-ignore flag to include .astro files
kilted-andres Aug 9, 2024
6378267
fix: explicitly include 'src/**/*.astro' files
kilted-andres Aug 9, 2024
11a2f9a
feat: eslint.config.js
kilted-andres Aug 9, 2024
5cc4599
Big Reversion from 11a2f9 to efb96c.
kilted-andres Aug 9, 2024
ca0217e
feat: default value for GRAPHQL_ENDPOINT
kilted-andres Aug 12, 2024
e86f6db
fix: remove subscan from configuration
kilted-andres Aug 12, 2024
472df34
fix: usage of indexer.polkadotRPCEndpoint
kilted-andres Aug 12, 2024
ffc107b
try: to make attestationsCreated optional on creation
kilted-andres Aug 12, 2024
21a96db
Revert "try: to make attestationsCreated optional on creation"
kilted-andres Aug 12, 2024
2cd7cc4
fix: migrations
kilted-andres Aug 12, 2024
b33aa56
fix: migration to remove extrinsicHash
kilted-andres Aug 12, 2024
b87d4e1
fix: exclude isHidden from search field
kilted-andres Aug 12, 2024
a0459ad
fix: remove line regarding old computed attestations count
kilted-andres Aug 12, 2024
51e5a91
feat: make attestationsCreated optional on creation
kilted-andres Aug 12, 2024
97a68c7
chore: remove unused dependency graphql
kilted-andres Aug 12, 2024
032a855
feat: intolerance while querying
kilted-andres Aug 12, 2024
f7b1bef
fix: remove default query
kilted-andres Aug 12, 2024
2c10647
reverted changes for old migrations
arty-name Aug 13, 2024
63f0347
explicit query
arty-name Aug 13, 2024
75d040c
fix: add missing s
kilted-andres Aug 13, 2024
78aec74
feat: move query definitions to same scope as their corresponding int…
kilted-andres Aug 13, 2024
4e5522a
Revert "fix: use update() instead of findOne() and save()"
kilted-andres Aug 13, 2024
942092c
fix: add a default for extrinsicHashes during down migration
kilted-andres Aug 14, 2024
09016e7
fix: snapshot for test
kilted-andres Aug 14, 2024
ec608af
fix: other snapshot for test
kilted-andres Aug 14, 2024
d469992
feat: allow comments on the .env.example file
kilted-andres Aug 14, 2024
2589965
fix: add missing } on explicit query
kilted-andres Aug 14, 2024
168737c
fix: hidden ctypes on the tag search
kilted-andres Aug 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
PORT=3000
URL=http://127.0.0.1:3000
DATABASE_URI=postgres://postgres:postgres@localhost:5432/postgres
SUBSCAN_NETWORK=spiritnet
SECRET_SUBSCAN=
BLOCKCHAIN_ENDPOINT=wss://kilt-rpc.dwellir.com
DID=
SECRET_PAYER_MNEMONIC=
SECRET_AUTHENTICATION_MNEMONIC=
SECRET_ASSERTION_METHOD_MNEMONIC=
SECRET_KEY_AGREEMENT_MNEMONIC=
GRAPHQL_ENDPOINT=https://indexer.kilt.io/
# while using the "...kilt.io" endpoints, please add a trailing "/" so that polkadot.js displays the right colors.
POLKADOT_RPC_ENDPOINT=kilt.ibp.network
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"stop-db": "docker rm -f postgres",
"migrate": "sequelize-cli db:migrate",
"seed": "sequelize-cli db:seed:all || exit 0",
"build": "export $(cat .env.example) && astro build",
"build": "export $(grep -v '^#' .env.example | xargs) && astro build",
"start": "pnpm migrate && pnpm seed && node --enable-source-maps dist/server/entry.mjs"
},
"dependencies": {
Expand Down
14 changes: 7 additions & 7 deletions src/components/CTypeDetails/CTypeDetails.astro
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const {
title,
creator,
properties,
block,
createdAt,
description,
extrinsicHash,
schema,
attestationsCount,
attestationsCreated,
tags,
} = Astro.props.cTypeData;

Expand All @@ -46,7 +46,7 @@ const schemaV1 = CType.fromProperties('', {}).$schema;
const version = schema === schemaV1 ? 'V1' : 'draft-01';
const kiltCType = CType.fromProperties(title, properties, version);

const { subscan, w3nOrigin } = configuration;
const { w3nOrigin, indexer } = configuration;
---

<section class={containerStyles.bigContainer}>
Expand All @@ -65,7 +65,7 @@ const { subscan, w3nOrigin } = configuration;

<fieldset>
<legend>Number of attestations</legend>
<p>{attestationsCount}</p>
<p>{attestationsCreated}</p>
</fieldset>

{
Expand Down Expand Up @@ -96,12 +96,12 @@ const { subscan, w3nOrigin } = configuration;
}

<fieldset>
<legend>Transaction</legend>
<legend>Registration Block</legend>

<a
href={`https://${subscan.network}.subscan.io/extrinsic/${extrinsicHash}`}
href={`https://polkadot.js.org/apps/?rpc=wss%3A%2F%2F${indexer.polkadotRPCEndpoint}#/explorer/query/${block}`}
>
{extrinsicHash}
{block}
</a>
</fieldset>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ exports[`CTypeDetails > should handle kitchen sink CType 1`] = `
</dl>
</fieldset>
<fieldset>
<legend>Transaction</legend>
<a href="https://example.subscan.io/extrinsic/0xexamplehash">0xexamplehash</a>
<legend>Registration Block</legend>
<a href="https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fplaceholder#/explorer/query/456">456</a>
</fieldset>
<fieldset>
<legend>Technical Details</legend>
Expand Down Expand Up @@ -214,8 +214,8 @@ exports[`CTypeDetails > should handle nested CType 1`] = `
</dl>
</fieldset>
<fieldset>
<legend>Transaction</legend>
<a href="https://example.subscan.io/extrinsic/0xexamplehash">0xexamplehash</a>
<legend>Registration Block</legend>
<a href="https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fplaceholder#/explorer/query/456">456</a>
</fieldset>
<fieldset>
<legend>Technical Details</legend>
Expand Down Expand Up @@ -280,8 +280,8 @@ exports[`CTypeDetails > should handle nested CType property 1`] = `
</dl>
</fieldset>
<fieldset>
<legend>Transaction</legend>
<a href="https://example.subscan.io/extrinsic/0xexamplenestedhash">0xexamplenestedhash</a>
<legend>Registration Block</legend>
<a href="https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fplaceholder#/explorer/query/321">321</a>
</fieldset>
<fieldset>
<legend>Technical Details</legend>
Expand Down Expand Up @@ -344,8 +344,8 @@ exports[`CTypeDetails > should match snapshot 1`] = `
</dl>
</fieldset>
<fieldset>
<legend>Transaction</legend>
<a href="https://example.subscan.io/extrinsic/0xexamplehash">0xexamplehash</a>
<legend>Registration Block</legend>
<a href="https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fplaceholder#/explorer/query/123">123</a>
</fieldset>
<fieldset>
<legend>Tags</legend>
Expand Down
4 changes: 2 additions & 2 deletions src/components/CTypeOverview/CTypeOverview.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface Props {
cTypeData: CTypeData;
}

const { title, id, description, attestationsCount, tags } =
const { title, id, description, attestationsCreated, tags } =
Astro.props.cTypeData;
---

Expand All @@ -36,7 +36,7 @@ const { title, id, description, attestationsCount, tags } =

<p class="attestations">
<span>Number of Attestations:</span>
<span>{attestationsCount}</span>
<span>{attestationsCreated}</span>
</p>
</li>

Expand Down
34 changes: 15 additions & 19 deletions src/components/CreateForm/CreateForm.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import {
connect,
CType,
Did,
disconnect,
type KiltAddress,
} from '@kiltprotocol/sdk-js';
import { web3FromSource } from '@polkadot/extension-dapp';
import {
type FocusEvent,
type FormEvent,
Expand All @@ -6,28 +14,19 @@ import {
useCallback,
useState,
} from 'react';
import { web3FromSource } from '@polkadot/extension-dapp';
import {
Blockchain,
connect,
CType,
Did,
disconnect,
type KiltAddress,
} from '@kiltprotocol/sdk-js';

import styles from './CreateForm.module.css';

import { generatePath, paths } from '../../paths';
import { getBlockchainEndpoint } from '../../utilities/getBlockchainEndpoint';
import { offsets } from '../../utilities/offsets';
import { Modal } from '../Modal/Modal';
import { PropertyFields } from '../PropertyFields/PropertyFields';
import { getProperties } from '../PropertyFields/getProperties';
import {
type InjectedAccount,
SelectAccount,
} from '../SelectAccount/SelectAccount';
import { Modal } from '../Modal/Modal';
import { PropertyFields } from '../PropertyFields/PropertyFields';
import { getProperties } from '../PropertyFields/getProperties';
import { offsets } from '../../utilities/offsets';
import { getBlockchainEndpoint } from '../../utilities/getBlockchainEndpoint';
import { generatePath, paths } from '../../paths';

import { useSupportedExtensions } from './useSupportedExtensions';

Expand Down Expand Up @@ -139,15 +138,12 @@ export function CreateForm() {
const authorizedTx = api.tx(authorized.signed);

const injected = await web3FromSource(account.meta.source);
const signed = await authorizedTx.signAsync(account.address, injected);
await Blockchain.submitSignedTx(signed);
await authorizedTx.signAndSend(account.address, injected);

const extrinsicHash = signed.hash.toHex();
arty-name marked this conversation as resolved.
Show resolved Hide resolved
const response = await fetch(paths.ctypes, {
method: 'POST',
body: JSON.stringify({
cType,
extrinsicHash,
creator,
description,
tags,
Expand Down
13 changes: 4 additions & 9 deletions src/components/ctype.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe('endpoint /ctype', () => {
const properties = {};
const cType = CType.fromProperties('New CType', properties);
const creator = 'did:kilt:4rrkiRTZgsgxjJDFkLsivqqKTqdUTuxKk3FX3mKFAeMxsR5E';
const extrinsicHash = '0x1234';
const description = 'A CType';

const response = await fetch(endpoint, {
Expand All @@ -21,7 +20,6 @@ describe('endpoint /ctype', () => {
body: JSON.stringify({
cType,
creator,
extrinsicHash,
description,
tags: ['test', 'example'],
}),
Expand All @@ -44,7 +42,7 @@ describe('endpoint /ctype', () => {
title: cType.title,
properties,
creator,
extrinsicHash,
attestationsCreated: 0,
description,
block: null,
isHidden: false,
Expand All @@ -63,9 +61,8 @@ describe('endpoint /ctype', () => {
const properties = {};
const cType = CType.fromProperties('New CType', properties);
const creator = 'did:kilt:4rrkiRTZgsgxjJDFkLsivqqKTqdUTuxKk3FX3mKFAeMxsR5E';
const extrinsicHash = '0x1234';
const tags = [] as string[];
const body = JSON.stringify({ cType, creator, extrinsicHash, tags });
const body = JSON.stringify({ cType, creator, tags });

const created = await fetch(endpoint, { method, headers, body });
expect(created.status).toBe(StatusCodes.CREATED);
Expand All @@ -78,9 +75,8 @@ describe('endpoint /ctype', () => {
const properties = {};
const cType = CType.fromProperties('New CType', properties);
const creator = 'invalid';
const extrinsicHash = '0x1234';
const tags = [] as string[];
const body = JSON.stringify({ cType, creator, extrinsicHash, tags });
const body = JSON.stringify({ cType, creator, tags });

const response = await fetch(endpoint, { method, headers, body });
expect(response.status).toBe(StatusCodes.UNPROCESSABLE_ENTITY);
Expand All @@ -89,9 +85,8 @@ describe('endpoint /ctype', () => {
it('should return an error if the CType is not valid', async () => {
const cType = { invalid: 'CType' };
const creator = 'did:kilt:4rrkiRTZgsgxjJDFkLsivqqKTqdUTuxKk3FX3mKFAeMxsR5E';
const extrinsicHash = '0x1234';
const tags = [] as string[];
const body = JSON.stringify({ cType, creator, extrinsicHash, tags });
const body = JSON.stringify({ cType, creator, tags });

const response = await fetch(endpoint, { method, headers, body });
expect(response.status).toBe(StatusCodes.UNPROCESSABLE_ENTITY);
Expand Down
6 changes: 3 additions & 3 deletions src/components/index/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports[`index.astro > should render all CTypes except hidden ones 1`] = `
This is an example of a CType with a nested property
</p>
<p class="attestations">
<span>Number of Attestations:</span><span>2</span>
<span>Number of Attestations:</span><span>22</span>
</p>
</li>
<li class="_container container">
Expand Down Expand Up @@ -77,7 +77,7 @@ exports[`index.astro > should render search results 1`] = `
This is an example of a CType with a nested property
</p>
<p class="attestations">
<span>Number of Attestations:</span><span>2</span>
<span>Number of Attestations:</span><span>22</span>
</p>
</li>
</ul>
Expand Down Expand Up @@ -124,7 +124,7 @@ exports[`index.astro > should render tag results 1`] = `
This is an example of a CType with a nested property
</p>
<p class="attestations">
<span>Number of Attestations:</span><span>2</span>
<span>Number of Attestations:</span><span>22</span>
</p>
</li>
<li class="_container container">
Expand Down
3 changes: 0 additions & 3 deletions src/components/index/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { beforeEach, describe, expect, it } from 'vitest';

import { getSnapshotHtmlForPath } from '../../../testing/getSnapshotHtmlForPath';
import { CType as CTypeModel } from '../../models/ctype';
import { Attestation as AttestationModel } from '../../models/attestation';
import { mockCTypes } from '../../utilities/mockCTypes';
import { mockAttestations } from '../../utilities/mockAttestations';
import { initializeDatabase } from '../../utilities/sequelize';
import { resetDatabase } from '../../../testing/resetDatabase';
import { Tag } from '../../models/tag';
Expand All @@ -18,7 +16,6 @@ beforeEach(async () => {
mockCTypes.hidden,
]);
await Tag.create({ tagName: 'example', cTypeId: mockCTypes.example.id });
await AttestationModel.bulkCreate(mockAttestations);
});

describe('index.astro', () => {
Expand Down
68 changes: 68 additions & 0 deletions src/migrations/20240807132131-dropAttestations.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface) {
/**
* Reverts (combines `down` functions of) following migrations:
* - `20230712145719-foreignKeys.cjs`
* - `20230711125237-attestations.cjs`
*/
await queryInterface.removeConstraint(
'Attestations',
'Attestations_cTypeId_fkey',
);

await queryInterface.dropTable('Attestations');
},

async down(queryInterface, Sequelize) {
const { sequelize } = queryInterface;

/**
* Recreates (combines `up` functions of) following migrations:
* - `20230712145719-foreignKeys.cjs`
* - `20230711125237-attestations.cjs`
*/
sequelize.define(
'Attestation',
{
claimHash: {
type: Sequelize.STRING,
primaryKey: true,
},
cTypeId: {
type: Sequelize.STRING,
allowNull: false,
},
owner: {
type: Sequelize.STRING,
allowNull: false,
},
delegationId: {
type: Sequelize.STRING,
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
},
extrinsicHash: {
type: Sequelize.STRING,
allowNull: false,
},
block: {
type: Sequelize.STRING,
},
},
{ indexes: [{ fields: ['cTypeId'] }] },
);
await sequelize.sync();

await queryInterface.addConstraint('Attestations', {
type: 'foreign key',
name: 'Attestations_cTypeId_fkey',
fields: ['cTypeId'],
references: { table: 'CTypes', field: 'id' },
});
},
};
Loading