1- import { createClient , SS58String } from "@polkadot-api/client" ;
2- import { getChain } from "@polkadot-api/node-polkadot-provider" ;
3- import { getSmProvider } from "@polkadot-api/sm-provider" ;
4- import {
5- polkadot ,
6- polkadot_collectives ,
7- } from "@substrate/connect-known-chains" ;
1+ import { collectives , polkadot } from "@polkadot-api/descriptors" ;
2+ import { Binary , createClient , SS58String } from "polkadot-api" ;
3+ import { chainSpec as polkadotChainSpec } from "polkadot-api/chains/polkadot" ;
4+ import { chainSpec as collectivesChainSpec } from "polkadot-api/chains/polkadot_collectives" ;
5+ import { getSmProvider } from "polkadot-api/sm-provider" ;
86import { start } from "smoldot" ;
97
10- import collectiveDescriptor from "./codegen/collectives" ;
11- import relayDescriptor from "./codegen/relay" ;
128import { ActionLogger } from "./github/types" ;
139
1410type FellowData = { address : string ; rank : number } ;
@@ -26,19 +22,15 @@ export const fetchAllFellows = async (
2622 const smoldot = start ( ) ;
2723
2824 try {
29- const relayChain = await smoldot . addChain ( {
30- chainSpec : polkadot ,
31- disableJsonRpc : true ,
25+ const smoldotRelayChain = await smoldot . addChain ( {
26+ chainSpec : polkadotChainSpec ,
3227 } ) ;
3328
29+ const jsonRpcProvider = getSmProvider ( smoldotRelayChain ) ;
3430 logger . info ( "Initializing the relay client" ) ;
35- const relayClient = createClient (
36- getChain ( {
37- provider : getSmProvider ( smoldot , polkadot ) ,
38- keyring : [ ] ,
39- } ) ,
40- ) ;
41- const relayApi = relayClient . getTypedApi ( relayDescriptor ) ;
31+ const polkadotClient = createClient ( jsonRpcProvider ) ;
32+
33+ const relayApi = polkadotClient . getTypedApi ( polkadot ) ;
4234
4335 const getGhHandle = async (
4436 address : SS58String ,
@@ -48,14 +40,26 @@ export const fetchAllFellows = async (
4840 await relayApi . query . Identity . IdentityOf . getValue ( address ) ;
4941
5042 if ( identity ) {
51- const handle = identity . info . additional
52- . find ( ( [ key ] ) => key . value ?. asText ( ) === "github" ) ?. [ 1 ]
53- . value ?. asText ( )
43+ const additional = identity [ 0 ] . info . additional . find (
44+ ( [ key ] ) => ( key . value as Binary ) ?. asText ( ) === "github" ,
45+ ) ;
46+
47+ if ( ! additional ) {
48+ logger . debug (
49+ `'${ address } ' does not have an additional field named 'github'` ,
50+ ) ;
51+ return ;
52+ }
53+
54+ const handle = ( additional [ 1 ] . value as Binary )
55+ . asText ( )
5456 . replace ( "@" , "" ) ;
57+
5558 if ( handle ) {
5659 logger . info ( `Found github handle for '${ address } ': '${ handle } '` ) ;
5760 } else {
5861 logger . debug ( `'${ address } ' does not have a GitHub handle` ) ;
62+ return ;
5963 }
6064 return handle ;
6165 }
@@ -80,21 +84,23 @@ export const fetchAllFellows = async (
8084 } ;
8185
8286 logger . info ( "Initializing the collectives client" ) ;
83- const collectivesClient = createClient (
84- getChain ( {
85- provider : getSmProvider ( smoldot , {
86- potentialRelayChains : [ relayChain ] ,
87- chainSpec : polkadot_collectives ,
88- } ) ,
89- keyring : [ ] ,
90- } ) ,
91- ) ;
92- const collectivesApi = collectivesClient . getTypedApi ( collectiveDescriptor ) ;
87+
88+ const collectiveRelayChain = await smoldot . addChain ( {
89+ chainSpec : collectivesChainSpec ,
90+ potentialRelayChains : [ smoldotRelayChain ] ,
91+ } ) ;
92+ const collectiveJsonRpcProvider = getSmProvider ( collectiveRelayChain ) ;
93+ logger . info ( "Initializing the relay client" ) ;
94+ const collectivesClient = createClient ( collectiveJsonRpcProvider ) ;
95+ const collectivesApi = collectivesClient . getTypedApi ( collectives ) ;
9396
9497 // Pull the members of the FellowshipCollective
9598 const memberEntries =
9699 await collectivesApi . query . FellowshipCollective . Members . getEntries ( ) ;
97100
101+ // We no longer need the collective client, so let's destroy it
102+ collectivesClient . destroy ( ) ;
103+
98104 // Build the Array of FellowData and filter out candidates (zero rank members)
99105 const fellows : FellowData [ ] = memberEntries
100106 . map ( ( { keyArgs : [ address ] , value : rank } ) => {
@@ -103,9 +109,6 @@ export const fetchAllFellows = async (
103109 . filter ( ( { rank } ) => rank > 0 ) ;
104110 logger . debug ( JSON . stringify ( fellows ) ) ;
105111
106- // We no longer need the collectives client, so let's destroy it
107- collectivesClient . destroy ( ) ;
108-
109112 // Let's now pull the GH handles of the fellows
110113 const users : FellowObject [ ] = await Promise . all (
111114 fellows . map ( async ( { address, rank } ) => {
@@ -119,7 +122,7 @@ export const fetchAllFellows = async (
119122 logger . info ( `Found users: ${ JSON . stringify ( Array . from ( users . entries ( ) ) ) } ` ) ;
120123
121124 // We are now done with the relay client
122- relayClient . destroy ( ) ;
125+ polkadotClient . destroy ( ) ;
123126
124127 return users ;
125128 } catch ( error ) {
0 commit comments