generated from Bullrich/parity-action-template
-
Notifications
You must be signed in to change notification settings - Fork 2
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
updated library to use PAPI #11
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9bfb13e
added papi dependencies
Bullrich 62084d9
downloaded chain info
Bullrich fc45dbd
added code to generate types
Bullrich 90e42d5
added smoldot dependencies
Bullrich d518c48
ported method to work with papi
Bullrich 59dee61
removed old code block
Bullrich fa90996
removed old log
Bullrich c72ea79
added scale files to docker image
Bullrich cb9e5be
removed polkadot-api
Bullrich 2ec90aa
fixed comments
Bullrich d550fbf
linted project
Bullrich 3d05853
added deleted comment
Bullrich e4ca9ae
removed websocked provider
Bullrich fde2709
updated test timeout
Bullrich 0d516c1
fixed required import from substrate/connect-known-chains
Bullrich 3c7ee1a
Removed residual log
Bullrich c265087
added timeout limit
Bullrich 36d7ab2
added `--forceExit` to jest
Bullrich eaad5d6
removed type transformation
Bullrich 37444e5
added process.exit to when the app finishes
Bullrich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules | ||
dist | ||
.git | ||
|
||
src/codegen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ jobs: | |
command: [lint, build, test] | ||
runs-on: ubuntu-latest | ||
name: running ${{ matrix.command }} | ||
timeout-minutes: 5 | ||
steps: | ||
- uses: actions/[email protected] | ||
- uses: actions/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ | |
!.vscode/extensions.json | ||
!.vscode/settings.json | ||
.idea | ||
|
||
# Papi | ||
src/codegen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"collectives": { | ||
"outputFolder": "src/codegen", | ||
"wsUrl": "wss://polkadot-collectives-rpc.polkadot.io", | ||
"metadata": "collectives.scale" | ||
}, | ||
"relay": { | ||
"outputFolder": "src/codegen", | ||
"wsUrl": "wss://rpc.polkadot.io", | ||
"metadata": "relay.scale" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
import { ApiPromise, WsProvider } from "@polkadot/api"; | ||
import { createClient } from "@polkadot-api/client"; | ||
import { getChain } from "@polkadot-api/node-polkadot-provider"; | ||
import { getSmProvider } from "@polkadot-api/sm-provider"; | ||
import { | ||
polkadot, | ||
polkadot_collectives, | ||
} from "@substrate/connect-known-chains"; | ||
import { start } from "smoldot"; | ||
|
||
import collectiveDescriptor from "./codegen/collectives"; | ||
import relayDescriptor from "./codegen/relay"; | ||
import { ActionLogger } from "./github/types"; | ||
|
||
type FellowData = { address: string; rank: number }; | ||
|
@@ -14,44 +22,73 @@ export type FellowObject = { | |
export const fetchAllFellows = async ( | ||
logger: ActionLogger, | ||
): Promise<FellowObject[]> => { | ||
let api: ApiPromise; | ||
logger.debug("Connecting to collective parachain"); | ||
// we connect to the collective rpc node | ||
const wsProvider = new WsProvider( | ||
"wss://polkadot-collectives-rpc.polkadot.io", | ||
); | ||
api = await ApiPromise.create({ provider: wsProvider }); | ||
logger.info("Initializing smoldot"); | ||
const smoldot = start(); | ||
const SmProvider = getSmProvider(smoldot); | ||
let polkadotClient: ReturnType<typeof createClient> | null = null; | ||
|
||
try { | ||
// We fetch all the members | ||
const membersObj = await api.query.fellowshipCollective.members.entries(); | ||
const relayChain = await smoldot.addChain({ | ||
chainSpec: polkadot, | ||
}); | ||
logger.debug("Connecting to collective parachain"); | ||
await smoldot.addChain({ | ||
chainSpec: polkadot_collectives, | ||
potentialRelayChains: [relayChain], | ||
}); | ||
|
||
logger.info("Initializing PAPI"); | ||
polkadotClient = createClient( | ||
getChain({ | ||
provider: SmProvider({ | ||
potentialRelayChains: [relayChain], | ||
chainSpec: polkadot_collectives, | ||
}), | ||
keyring: [], | ||
}), | ||
); | ||
|
||
// We fetch all the members from the collective | ||
const collectivesApi = polkadotClient.getTypedApi(collectiveDescriptor); | ||
const memberEntries = | ||
await collectivesApi.query.FellowshipCollective.Members.getEntries(); | ||
|
||
// We iterate over the fellow data and convert them into usable values | ||
const fellows: FellowData[] = []; | ||
for (const [key, rank] of membersObj) { | ||
// @ts-ignore | ||
const [address]: [string] = key.toHuman(); | ||
fellows.push({ address, ...(rank.toHuman() as object) } as FellowData); | ||
for (const member of memberEntries) { | ||
const [address] = member.keyArgs; | ||
fellows.push({ address, rank: member.value }); | ||
} | ||
logger.debug(JSON.stringify(fellows)); | ||
|
||
// Once we obtained this information, we disconnect this api. | ||
await api.disconnect(); | ||
polkadotClient.destroy(); | ||
|
||
logger.debug("Connecting to relay parachain."); | ||
// We connect to the relay chain | ||
api = await ApiPromise.create({ | ||
provider: new WsProvider("wss://rpc.polkadot.io"), | ||
}); | ||
|
||
// We iterate over the different members and extract their data | ||
// We move into the relay chain | ||
polkadotClient = createClient( | ||
getChain({ | ||
Bullrich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
provider: SmProvider({ | ||
potentialRelayChains: [relayChain], | ||
chainSpec: polkadot, | ||
}), | ||
keyring: [], | ||
}), | ||
); | ||
const relayApi = polkadotClient.getTypedApi(relayDescriptor); | ||
|
||
const users: FellowObject[] = []; | ||
|
||
// We iterate over the different members and extract their data | ||
for (const fellow of fellows) { | ||
logger.debug( | ||
`Fetching identity of '${fellow.address}', rank: ${fellow.rank}`, | ||
); | ||
const fellowData = ( | ||
await api.query.identity.identityOf(fellow.address) | ||
).toHuman() as Record<string, unknown> | undefined; | ||
|
||
const fellowData = await relayApi.query.Identity.IdentityOf.getValue( | ||
fellow.address, | ||
); | ||
|
||
let data: FellowObject = { address: fellow.address, rank: fellow.rank }; | ||
|
||
|
@@ -61,12 +98,10 @@ export const fetchAllFellows = async ( | |
continue; | ||
} | ||
|
||
// @ts-ignore | ||
const additional = fellowData.info.additional as | ||
| [{ Raw: string }, { Raw: string }][] | ||
| undefined; | ||
const additional = fellowData.info.additional; | ||
|
||
// If it does not have additional data (GitHub handle goes here) we ignore it | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (!additional || additional.length < 1) { | ||
logger.debug("Additional data is null. Skipping"); | ||
Comment on lines
+106
to
107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't trust that this will always not be null, so I'll keep the check from before |
||
continue; | ||
|
@@ -76,27 +111,27 @@ export const fetchAllFellows = async ( | |
const [key, value] = additionalData; | ||
// We verify that they have an additional data of the key "github" | ||
// If it has a handle defined, we push it into the array | ||
if ( | ||
key?.Raw && | ||
key?.Raw === "github" && | ||
value?.Raw && | ||
value?.Raw.length > 0 | ||
) { | ||
logger.debug(`Found handles: '${value.Raw}'`); | ||
const fieldName = key.value?.asText(); | ||
logger.debug(`Analyzing: ${fieldName ?? "unknown field"}`); | ||
const fieldValue = value.value?.asText(); | ||
if (fieldName === "github" && fieldValue && fieldValue.length > 0) { | ||
logger.debug(`Found handles: '${fieldValue}`); | ||
// We add it to the array and remove the @ if they add it to the handle | ||
data = { ...data, githubHandle: value.Raw.replace("@", "") }; | ||
data = { ...data, githubHandle: fieldValue.replace("@", "") }; | ||
} | ||
users.push(data); | ||
} | ||
users.push(data); | ||
} | ||
|
||
logger.info(`Found users: ${JSON.stringify(Array.from(users.entries()))}`); | ||
|
||
return users; | ||
} catch (error) { | ||
logger.error(error as Error); | ||
throw error; | ||
} finally { | ||
await api.disconnect(); | ||
if (polkadotClient) { | ||
polkadotClient.destroy(); | ||
} | ||
await smoldot.terminate(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dependencies for the
postinstall
script