Skip to content

Commit

Permalink
fix: deduplicate env rpc endpoint and other minor improvements (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
kilted-andres authored Aug 16, 2024
1 parent db2ccad commit a026723
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 50 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PORT=3000
URL=http://127.0.0.1:3000
DATABASE_URI=postgres://postgres:postgres@localhost:5432/postgres
BLOCKCHAIN_ENDPOINT=wss://kilt-rpc.dwellir.com
# while using the "...kilt.io" endpoints, please add a trailing "/" so that polkadot.js displays the right colors.
BLOCKCHAIN_ENDPOINT=wss://kilt.ibp.network
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

21 changes: 10 additions & 11 deletions src/components/CTypeDetails/CTypeDetails.astro
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,22 @@ const schemaV1 = CType.fromProperties('', {}).$schema;
const version = schema === schemaV1 ? 'V1' : 'draft-01';
const kiltCType = CType.fromProperties(title, properties, version);
const { w3nOrigin, indexer } = configuration;
const { w3nOrigin, blockchainEndpoint } = configuration;
const linkToW3N = new URL(w3nOrigin);
linkToW3N.pathname = web3Name ?? creator;
const linkToBlock = new URL(`https://polkadot.js.org/apps/`);
linkToBlock.searchParams.set('rpc', blockchainEndpoint);
linkToBlock.hash = `/explorer/query/${block}`;
---

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

<fieldset>
<legend>Creator</legend>
{
web3Name ? (
<a href={`${w3nOrigin}/${web3Name}`}>w3n:{web3Name}</a>
) : (
<p>{creator}</p>
)
}
{(<a href={linkToW3N}>{web3Name ? `w3n:${web3Name}` : creator}</a>)}
</fieldset>

<fieldset>
Expand Down Expand Up @@ -98,9 +99,7 @@ const { w3nOrigin, indexer } = configuration;
<fieldset>
<legend>Registration Block</legend>

<a
href={`https://polkadot.js.org/apps/?rpc=wss%3A%2F%2F${indexer.polkadotRPCEndpoint}#/explorer/query/${block}`}
>
<a href={linkToBlock}>
{block}
</a>
</fieldset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exports[`CTypeDetails > should handle kitchen sink CType 1`] = `
<h1 class="title">Everything everywhere</h1>
<fieldset>
<legend>Creator</legend>
<p>did:kilt:4rrkiRTZgsgxjJDFkLsivqqKTqdUTuxKk3FX3mKFAeMxsR5E</p>
<a href="https://w3n.id/did:kilt:4rrkiRTZgsgxjJDFkLsivqqKTqdUTuxKk3FX3mKFAeMxsR5E">did:kilt:4rrkiRTZgsgxjJDFkLsivqqKTqdUTuxKk3FX3mKFAeMxsR5E</a>
</fieldset>
<fieldset>
<legend>Number of attestations</legend>
Expand Down Expand Up @@ -121,7 +121,7 @@ exports[`CTypeDetails > should handle kitchen sink CType 1`] = `
</fieldset>
<fieldset>
<legend>Registration Block</legend>
<a href="https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fplaceholder#/explorer/query/456">456</a>
<a href="https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A32769#/explorer/query/456">456</a>
</fieldset>
<fieldset>
<legend>Technical Details</legend>
Expand Down Expand Up @@ -179,7 +179,7 @@ exports[`CTypeDetails > should handle nested CType 1`] = `
<h1 class="title">Example nested CType</h1>
<fieldset>
<legend>Creator</legend>
<p>did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY</p>
<a href="https://w3n.id/did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY">did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY</a>
</fieldset>
<fieldset>
<legend>Number of attestations</legend>
Expand Down Expand Up @@ -215,7 +215,7 @@ exports[`CTypeDetails > should handle nested CType 1`] = `
</fieldset>
<fieldset>
<legend>Registration Block</legend>
<a href="https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fplaceholder#/explorer/query/456">456</a>
<a href="https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A32769#/explorer/query/456">456</a>
</fieldset>
<fieldset>
<legend>Technical Details</legend>
Expand Down Expand Up @@ -245,7 +245,7 @@ exports[`CTypeDetails > should handle nested CType property 1`] = `
<h1 class="title">Example nested CType property</h1>
<fieldset>
<legend>Creator</legend>
<p>did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY</p>
<a href="https://w3n.id/did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY">did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY</a>
</fieldset>
<fieldset>
<legend>Number of attestations</legend>
Expand Down Expand Up @@ -281,7 +281,7 @@ exports[`CTypeDetails > should handle nested CType property 1`] = `
</fieldset>
<fieldset>
<legend>Registration Block</legend>
<a href="https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fplaceholder#/explorer/query/321">321</a>
<a href="https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A32769#/explorer/query/321">321</a>
</fieldset>
<fieldset>
<legend>Technical Details</legend>
Expand Down Expand Up @@ -311,7 +311,7 @@ exports[`CTypeDetails > should match snapshot 1`] = `
<h1 class="title">Example CType</h1>
<fieldset>
<legend>Creator</legend>
<p>did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY</p>
<a href="https://w3n.id/did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY">did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY</a>
</fieldset>
<fieldset>
<legend>Number of attestations</legend>
Expand Down Expand Up @@ -345,7 +345,7 @@ exports[`CTypeDetails > should match snapshot 1`] = `
</fieldset>
<fieldset>
<legend>Registration Block</legend>
<a href="https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fplaceholder#/explorer/query/123">123</a>
<a href="https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A32769#/explorer/query/123">123</a>
</fieldset>
<fieldset>
<legend>Tags</legend>
Expand Down
24 changes: 12 additions & 12 deletions src/utilities/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ class ConfigurationError extends Error {
}
const indexer = {
graphqlEndpoint: import.meta.env.GRAPHQL_ENDPOINT as string,
polkadotRPCEndpoint: import.meta.env.POLKADOT_RPC_ENDPOINT as string,
};
if (!indexer.graphqlEndpoint) {
throw new ConfigurationError('No endpoint for the GraphQL server provided');
}
if (!indexer.polkadotRPCEndpoint) {
throw new ConfigurationError(
'No R.P.C. endpoint for the polkadot.js explorer provided',
);
}

const blockchainEndpoint = import.meta.env.BLOCKCHAIN_ENDPOINT as string;
if (!blockchainEndpoint) {
throw new ConfigurationError('No blockchain endpoint provided');
Expand Down Expand Up @@ -57,11 +52,16 @@ if (!payerMnemonic) {
throw new ConfigurationError('SECRET_PAYER_MNEMONIC is not provided');
}

const w3nOrigins: Record<string, string> = {
'wss://peregrine.kilt.io': 'https://test.w3n.id',
'wss://peregrine-stg.kilt.io/para': 'https://smoke.w3n.id',
'wss://kilt-rpc.dwellir.com': 'https://w3n.id',
};
function deductW3nOrigin(blockchainEndpoint: string) {
const endpoint = blockchainEndpoint.toLowerCase();
if (endpoint.includes('peregrine-stg')) {
return 'https://smoke.w3n.id';
}
if (endpoint.includes('peregrine')) {
return 'https://test.w3n.id';
}
return 'https://w3n.id';
}

export const configuration = {
isProduction: import.meta.env.PROD,
Expand All @@ -76,6 +76,6 @@ export const configuration = {
assertionMethodMnemonic,
keyAgreementMnemonic,
payerMnemonic,
w3nOrigin: w3nOrigins[blockchainEndpoint] || 'https://w3n.id',
w3nOrigin: deductW3nOrigin(blockchainEndpoint),
indexer,
};
2 changes: 1 addition & 1 deletion src/utilities/indexer/fragments.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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 "...", like shown on 'wholeAttestation'.
// 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/

Expand Down
32 changes: 20 additions & 12 deletions src/utilities/indexer/queryCTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,25 @@ export async function queryCTypes() {
const { id: creator } = author;
const { $schema, ...rest } = JSON.parse(definition) as Omit<ICType, '$id'>;

const newCType = await CTypeModel.upsert({
id: cTypeId,
schema: $schema,
createdAt: new Date(registrationBlock.timeStamp + 'Z'),
creator,
block: registrationBlock.id,
...rest,
attestationsCreated,
});
logger.info(
`Added new CType to data base: ${JSON.stringify(newCType, null, 2)}`,
);
try {
const newCType = await CTypeModel.upsert({
id: cTypeId,
schema: $schema,
createdAt: new Date(registrationBlock.timeStamp + 'Z'),
creator,
block: registrationBlock.id,
...rest,
attestationsCreated,
});
logger.info(
`Added new CType to data base: ${JSON.stringify(newCType, null, 2)}`,
);
} catch (error) {
logger.error(
error,
`Could not add cType ${cTypeId} to database. Probably bad formatted, see its definition: ${definition}`,
);
continue;
}
}
}
4 changes: 2 additions & 2 deletions src/utilities/indexer/queryFromIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { sleep } from '../sleep';

const { indexer } = configuration;

const QUERY_INTERVAL_MS = 1000;
export const QUERY_SIZE = 50;
const QUERY_INTERVAL_MS = 2000;
export const QUERY_SIZE = 100;

// /** Example Query. */
// const queryBlocks = `
Expand Down
1 change: 0 additions & 1 deletion testing/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
const env = {
MODE: 'test',
GRAPHQL_ENDPOINT: 'placeholder',
POLKADOT_RPC_ENDPOINT: 'placeholder',
BLOCKCHAIN_ENDPOINT: '',
DATABASE_URI: '',
DID: 'placeholder',
Expand Down

0 comments on commit a026723

Please sign in to comment.