Skip to content

Commit

Permalink
Obtain fellows from People Chain (#30)
Browse files Browse the repository at this point in the history
- Migrated the chain from polkadot to `People Chain`.
  - Resolves #29 and resolves polkadot-fellows/runtimes#394
- Updated PAPI to latest (it now has a `.papi` directory).
  - Removed slim node docker image and bundled everything together
- Polkadot-API depends on some dependencies that `ncc` is not bundling
together so we need to keep the `node_modules` (like
`@polkadot-api/metadata-compatibility`)
 - Updated to version `1.2.0`

---------

Co-authored-by: cornholio <0@mcornholio.ru>
  • Loading branch information
Bullrich and mutantcornholio authored Jul 29, 2024
1 parent 523c199 commit 4505976
Show file tree
Hide file tree
Showing 14 changed files with 650 additions and 570 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/javascript-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install --immutable
run: yarn install --immutable --mode skip-build
- run: yarn run postinstall
- run: yarn run ${{ matrix.command }}

conclude:
Expand Down
3 changes: 3 additions & 0 deletions .papi/descriptors/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!package.json
24 changes: 24 additions & 0 deletions .papi/descriptors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.1.0-autogenerated.14257783844949306470",
"name": "@polkadot-api/descriptors",
"files": [
"dist"
],
"exports": {
".": {
"module": "./dist/index.mjs",
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"browser": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"sideEffects": false,
"peerDependencies": {
"polkadot-api": "*"
}
}
Binary file added .papi/metadata/collectives.scale
Binary file not shown.
Binary file added .papi/metadata/people.scale
Binary file not shown.
14 changes: 14 additions & 0 deletions .papi/polkadot-api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 0,
"descriptorPath": ".papi/descriptors",
"entries": {
"collectives": {
"wsUrl": "wss://polkadot-collectives-rpc.polkadot.io",
"metadata": ".papi/metadata/collectives.scale"
},
"people": {
"wsUrl": "wss://polkadot-people-rpc.polkadot.io",
"metadata": ".papi/metadata/people.scale"
}
}
}
8 changes: 2 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ WORKDIR /action
COPY .yarn/ ./.yarn/
COPY package.json yarn.lock .yarnrc.yml ./

COPY collectives.scale polkadot.scale polkadot-api.json ./
COPY .papi ./.papi

RUN yarn install --immutable

COPY . .

RUN yarn run build

FROM node:22-slim

COPY --from=Builder /action/dist /action

ENTRYPOINT ["node", "/action/index.js"]
ENTRYPOINT ["node", "/action/dist/index.js"]
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ outputs:

runs:
using: 'docker'
image: 'docker://ghcr.io/paritytech/get-fellows-action/action:1.1.4'
image: 'docker://ghcr.io/paritytech/get-fellows-action/action:1.2.0'
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "get-fellows-action",
"version": "1.1.4",
"version": "1.2.0",
"description": "Fetch all the GitHub handles from the Fellows",
"main": "src/index.ts",
"scripts": {
Expand All @@ -25,13 +25,17 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^5.1.1",
"polkadot-api": "^0.9.0",
"@polkadot-api/descriptors": "file:.papi/descriptors",
"polkadot-api": "^0.12.0",
"smoldot": "2.0.29"
},
"devDependencies": {
"@eng-automation/js-style": "^3.1.0",
"@vercel/ncc": "^0.38.1",
"typescript": "^5.5.3",
"vitest": "^1.6.0"
},
"resolutions": {
"@polkadot-api/descriptors": "portal:./.papi/descriptors"
}
}
Binary file added people.scale
Binary file not shown.
10 changes: 0 additions & 10 deletions polkadot-api.json

This file was deleted.

Binary file removed polkadot.scale
Binary file not shown.
43 changes: 25 additions & 18 deletions src/fellows.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { collectives, polkadot } from "@polkadot-api/descriptors";
import { Binary, createClient, SS58String } from "polkadot-api";
import { collectives, people } from "@polkadot-api/descriptors";
import { createClient, SS58String } from "polkadot-api";
import { chainSpec as polkadotChainSpec } from "polkadot-api/chains/polkadot";
import { chainSpec as collectivesChainSpec } from "polkadot-api/chains/polkadot_collectives";
import { chainSpec as peopleChainSpec } from "polkadot-api/chains/polkadot_people";
import { getSmProvider } from "polkadot-api/sm-provider";
import { start } from "smoldot";

Expand All @@ -22,38 +23,44 @@ export const fetchAllFellows = async (
const smoldot = start();

try {
// Create smoldot chain with Polkadot Relay Chain
const smoldotRelayChain = await smoldot.addChain({
chainSpec: polkadotChainSpec,
});

const jsonRpcProvider = getSmProvider(smoldotRelayChain);
logger.info("Initializing the relay client");
const polkadotClient = createClient(jsonRpcProvider);
// Add the people chain to smoldot
const peopleRelayChain = await smoldot.addChain({
chainSpec: peopleChainSpec,
potentialRelayChains: [smoldotRelayChain],
});

const relayApi = polkadotClient.getTypedApi(polkadot);
// Initialize the smoldot provider
const jsonRpcProvider = getSmProvider(peopleRelayChain);
logger.info("Initializing the people client");
const peopleClient = createClient(jsonRpcProvider);

// Get the types for the people client
const peopleApi = peopleClient.getTypedApi(people);

const getGhHandle = async (
address: SS58String,
): Promise<string | undefined> => {
logger.debug(`Fetching identity of '${address}'`);
const identity =
await relayApi.query.Identity.IdentityOf.getValue(address);
const identityOf =
await peopleApi.query.Identity.IdentityOf.getValue(address);

if (identity) {
const additional = identity[0].info.additional.find(
([key]) => (key.value as Binary)?.asText() === "github",
);
if (identityOf) {
const [identity] = identityOf;
const github = identity.info.github.value;

if (!additional) {
if (!github) {
logger.debug(
`'${address}' does not have an additional field named 'github'`,
);
return;
}

const handle = (additional[1].value as Binary)
.asText()
.replace("@", "");
const handle = github.asText().replace("@", "") as string;

if (handle) {
logger.info(`Found github handle for '${address}': '${handle}'`);
Expand All @@ -69,7 +76,7 @@ export const fetchAllFellows = async (
);

const superIdentityAddress = (
await relayApi.query.Identity.SuperOf.getValue(address)
await peopleApi.query.Identity.SuperOf.getValue(address)
)?.[0];

if (superIdentityAddress) {
Expand Down Expand Up @@ -122,7 +129,7 @@ export const fetchAllFellows = async (
logger.info(`Found users: ${JSON.stringify(Array.from(users.entries()))}`);

// We are now done with the relay client
polkadotClient.destroy();
peopleClient.destroy();

return users;
} catch (error) {
Expand Down
Loading

0 comments on commit 4505976

Please sign in to comment.