Skip to content

Commit a026723

Browse files
authored
fix: deduplicate env rpc endpoint and other minor improvements (#744)
1 parent db2ccad commit a026723

File tree

8 files changed

+56
-50
lines changed

8 files changed

+56
-50
lines changed

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
PORT=3000
22
URL=http://127.0.0.1:3000
33
DATABASE_URI=postgres://postgres:postgres@localhost:5432/postgres
4-
BLOCKCHAIN_ENDPOINT=wss://kilt-rpc.dwellir.com
4+
# while using the "...kilt.io" endpoints, please add a trailing "/" so that polkadot.js displays the right colors.
5+
BLOCKCHAIN_ENDPOINT=wss://kilt.ibp.network
56
DID=
67
SECRET_PAYER_MNEMONIC=
78
SECRET_AUTHENTICATION_MNEMONIC=
89
SECRET_ASSERTION_METHOD_MNEMONIC=
910
SECRET_KEY_AGREEMENT_MNEMONIC=
1011
GRAPHQL_ENDPOINT=https://indexer.kilt.io/
11-
# while using the "...kilt.io" endpoints, please add a trailing "/" so that polkadot.js displays the right colors.
12-
POLKADOT_RPC_ENDPOINT=kilt.ibp.network
12+

src/components/CTypeDetails/CTypeDetails.astro

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,22 @@ const schemaV1 = CType.fromProperties('', {}).$schema;
4646
const version = schema === schemaV1 ? 'V1' : 'draft-01';
4747
const kiltCType = CType.fromProperties(title, properties, version);
4848
49-
const { w3nOrigin, indexer } = configuration;
49+
const { w3nOrigin, blockchainEndpoint } = configuration;
50+
51+
const linkToW3N = new URL(w3nOrigin);
52+
linkToW3N.pathname = web3Name ?? creator;
53+
54+
const linkToBlock = new URL(`https://polkadot.js.org/apps/`);
55+
linkToBlock.searchParams.set('rpc', blockchainEndpoint);
56+
linkToBlock.hash = `/explorer/query/${block}`;
5057
---
5158

5259
<section class={containerStyles.bigContainer}>
5360
<h1 class="title">{title}</h1>
5461

5562
<fieldset>
5663
<legend>Creator</legend>
57-
{
58-
web3Name ? (
59-
<a href={`${w3nOrigin}/${web3Name}`}>w3n:{web3Name}</a>
60-
) : (
61-
<p>{creator}</p>
62-
)
63-
}
64+
{(<a href={linkToW3N}>{web3Name ? `w3n:${web3Name}` : creator}</a>)}
6465
</fieldset>
6566

6667
<fieldset>
@@ -98,9 +99,7 @@ const { w3nOrigin, indexer } = configuration;
9899
<fieldset>
99100
<legend>Registration Block</legend>
100101

101-
<a
102-
href={`https://polkadot.js.org/apps/?rpc=wss%3A%2F%2F${indexer.polkadotRPCEndpoint}#/explorer/query/${block}`}
103-
>
102+
<a href={linkToBlock}>
104103
{block}
105104
</a>
106105
</fieldset>

src/components/CTypeDetails/__snapshots__/CTypeDetails.test.ts.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ exports[`CTypeDetails > should handle kitchen sink CType 1`] = `
2727
<h1 class="title">Everything everywhere</h1>
2828
<fieldset>
2929
<legend>Creator</legend>
30-
<p>did:kilt:4rrkiRTZgsgxjJDFkLsivqqKTqdUTuxKk3FX3mKFAeMxsR5E</p>
30+
<a href="https://w3n.id/did:kilt:4rrkiRTZgsgxjJDFkLsivqqKTqdUTuxKk3FX3mKFAeMxsR5E">did:kilt:4rrkiRTZgsgxjJDFkLsivqqKTqdUTuxKk3FX3mKFAeMxsR5E</a>
3131
</fieldset>
3232
<fieldset>
3333
<legend>Number of attestations</legend>
@@ -121,7 +121,7 @@ exports[`CTypeDetails > should handle kitchen sink CType 1`] = `
121121
</fieldset>
122122
<fieldset>
123123
<legend>Registration Block</legend>
124-
<a href="https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fplaceholder#/explorer/query/456">456</a>
124+
<a href="https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A32769#/explorer/query/456">456</a>
125125
</fieldset>
126126
<fieldset>
127127
<legend>Technical Details</legend>
@@ -179,7 +179,7 @@ exports[`CTypeDetails > should handle nested CType 1`] = `
179179
<h1 class="title">Example nested CType</h1>
180180
<fieldset>
181181
<legend>Creator</legend>
182-
<p>did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY</p>
182+
<a href="https://w3n.id/did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY">did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY</a>
183183
</fieldset>
184184
<fieldset>
185185
<legend>Number of attestations</legend>
@@ -215,7 +215,7 @@ exports[`CTypeDetails > should handle nested CType 1`] = `
215215
</fieldset>
216216
<fieldset>
217217
<legend>Registration Block</legend>
218-
<a href="https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fplaceholder#/explorer/query/456">456</a>
218+
<a href="https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A32769#/explorer/query/456">456</a>
219219
</fieldset>
220220
<fieldset>
221221
<legend>Technical Details</legend>
@@ -245,7 +245,7 @@ exports[`CTypeDetails > should handle nested CType property 1`] = `
245245
<h1 class="title">Example nested CType property</h1>
246246
<fieldset>
247247
<legend>Creator</legend>
248-
<p>did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY</p>
248+
<a href="https://w3n.id/did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY">did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY</a>
249249
</fieldset>
250250
<fieldset>
251251
<legend>Number of attestations</legend>
@@ -281,7 +281,7 @@ exports[`CTypeDetails > should handle nested CType property 1`] = `
281281
</fieldset>
282282
<fieldset>
283283
<legend>Registration Block</legend>
284-
<a href="https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fplaceholder#/explorer/query/321">321</a>
284+
<a href="https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A32769#/explorer/query/321">321</a>
285285
</fieldset>
286286
<fieldset>
287287
<legend>Technical Details</legend>
@@ -311,7 +311,7 @@ exports[`CTypeDetails > should match snapshot 1`] = `
311311
<h1 class="title">Example CType</h1>
312312
<fieldset>
313313
<legend>Creator</legend>
314-
<p>did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY</p>
314+
<a href="https://w3n.id/did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY">did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY</a>
315315
</fieldset>
316316
<fieldset>
317317
<legend>Number of attestations</legend>
@@ -345,7 +345,7 @@ exports[`CTypeDetails > should match snapshot 1`] = `
345345
</fieldset>
346346
<fieldset>
347347
<legend>Registration Block</legend>
348-
<a href="https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fplaceholder#/explorer/query/123">123</a>
348+
<a href="https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A32769#/explorer/query/123">123</a>
349349
</fieldset>
350350
<fieldset>
351351
<legend>Tags</legend>

src/utilities/configuration.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,11 @@ class ConfigurationError extends Error {
1414
}
1515
const indexer = {
1616
graphqlEndpoint: import.meta.env.GRAPHQL_ENDPOINT as string,
17-
polkadotRPCEndpoint: import.meta.env.POLKADOT_RPC_ENDPOINT as string,
1817
};
1918
if (!indexer.graphqlEndpoint) {
2019
throw new ConfigurationError('No endpoint for the GraphQL server provided');
2120
}
22-
if (!indexer.polkadotRPCEndpoint) {
23-
throw new ConfigurationError(
24-
'No R.P.C. endpoint for the polkadot.js explorer provided',
25-
);
26-
}
21+
2722
const blockchainEndpoint = import.meta.env.BLOCKCHAIN_ENDPOINT as string;
2823
if (!blockchainEndpoint) {
2924
throw new ConfigurationError('No blockchain endpoint provided');
@@ -57,11 +52,16 @@ if (!payerMnemonic) {
5752
throw new ConfigurationError('SECRET_PAYER_MNEMONIC is not provided');
5853
}
5954

60-
const w3nOrigins: Record<string, string> = {
61-
'wss://peregrine.kilt.io': 'https://test.w3n.id',
62-
'wss://peregrine-stg.kilt.io/para': 'https://smoke.w3n.id',
63-
'wss://kilt-rpc.dwellir.com': 'https://w3n.id',
64-
};
55+
function deductW3nOrigin(blockchainEndpoint: string) {
56+
const endpoint = blockchainEndpoint.toLowerCase();
57+
if (endpoint.includes('peregrine-stg')) {
58+
return 'https://smoke.w3n.id';
59+
}
60+
if (endpoint.includes('peregrine')) {
61+
return 'https://test.w3n.id';
62+
}
63+
return 'https://w3n.id';
64+
}
6565

6666
export const configuration = {
6767
isProduction: import.meta.env.PROD,
@@ -76,6 +76,6 @@ export const configuration = {
7676
assertionMethodMnemonic,
7777
keyAgreementMnemonic,
7878
payerMnemonic,
79-
w3nOrigin: w3nOrigins[blockchainEndpoint] || 'https://w3n.id',
79+
w3nOrigin: deductW3nOrigin(blockchainEndpoint),
8080
indexer,
8181
};

src/utilities/indexer/fragments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// GraphQL provides reusable units called fragments.
22
// Fragments let you construct sets of fields, and then include them in queries where needed.
3-
// You can use the fragments by including them as fields prefixed by 3 points "...", like shown on 'wholeAttestation'.
3+
// You can use the fragments by including them as fields prefixed by 3 points "...".
44
// See documentation here: https://graphql.org/learn/queries/#fragments
55
// Try out yourself under https://indexer.kilt.io/ & https://dev-indexer.kilt.io/
66

src/utilities/indexer/queryCTypes.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,25 @@ export async function queryCTypes() {
7777
const { id: creator } = author;
7878
const { $schema, ...rest } = JSON.parse(definition) as Omit<ICType, '$id'>;
7979

80-
const newCType = await CTypeModel.upsert({
81-
id: cTypeId,
82-
schema: $schema,
83-
createdAt: new Date(registrationBlock.timeStamp + 'Z'),
84-
creator,
85-
block: registrationBlock.id,
86-
...rest,
87-
attestationsCreated,
88-
});
89-
logger.info(
90-
`Added new CType to data base: ${JSON.stringify(newCType, null, 2)}`,
91-
);
80+
try {
81+
const newCType = await CTypeModel.upsert({
82+
id: cTypeId,
83+
schema: $schema,
84+
createdAt: new Date(registrationBlock.timeStamp + 'Z'),
85+
creator,
86+
block: registrationBlock.id,
87+
...rest,
88+
attestationsCreated,
89+
});
90+
logger.info(
91+
`Added new CType to data base: ${JSON.stringify(newCType, null, 2)}`,
92+
);
93+
} catch (error) {
94+
logger.error(
95+
error,
96+
`Could not add cType ${cTypeId} to database. Probably bad formatted, see its definition: ${definition}`,
97+
);
98+
continue;
99+
}
92100
}
93101
}

src/utilities/indexer/queryFromIndexer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { sleep } from '../sleep';
66

77
const { indexer } = configuration;
88

9-
const QUERY_INTERVAL_MS = 1000;
10-
export const QUERY_SIZE = 50;
9+
const QUERY_INTERVAL_MS = 2000;
10+
export const QUERY_SIZE = 100;
1111

1212
// /** Example Query. */
1313
// const queryBlocks = `

testing/globalSetup.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
const env = {
1616
MODE: 'test',
1717
GRAPHQL_ENDPOINT: 'placeholder',
18-
POLKADOT_RPC_ENDPOINT: 'placeholder',
1918
BLOCKCHAIN_ENDPOINT: '',
2019
DATABASE_URI: '',
2120
DID: 'placeholder',

0 commit comments

Comments
 (0)