|
@@ -1,11 +1,6 @@
|
|
-// @ts-check
|
|
|
|
-
|
|
|
|
-import {ApiPromise, WsProvider} from '@polkadot/api'
|
|
|
|
-import {types as joyTypes} from '@joystream/types'
|
|
|
|
-import {Hash, Moment} from '@polkadot/types/interfaces'
|
|
|
|
|
|
+import {ApiPromise} from "@polkadot/api";
|
|
import {
|
|
import {
|
|
- BlockRange,
|
|
|
|
- CouncilMemberInfo,
|
|
|
|
|
|
+ BlockRange, CouncilMemberInfo,
|
|
CouncilRoundInfo,
|
|
CouncilRoundInfo,
|
|
ProposalFailedReason,
|
|
ProposalFailedReason,
|
|
ProposalInfo,
|
|
ProposalInfo,
|
|
@@ -13,45 +8,17 @@ import {
|
|
ProposalType,
|
|
ProposalType,
|
|
ReportData
|
|
ReportData
|
|
} from "./types";
|
|
} from "./types";
|
|
|
|
+import {StorageKey, U32, u32, Vec} from "@polkadot/types";
|
|
import {Seats} from "@joystream/types/council";
|
|
import {Seats} from "@joystream/types/council";
|
|
import {MemberId, Membership} from "@joystream/types/members";
|
|
import {MemberId, Membership} from "@joystream/types/members";
|
|
-import {StorageKey, u32, U32, Vec} from "@polkadot/types";
|
|
|
|
import {Mint, MintId} from "@joystream/types/mint";
|
|
import {Mint, MintId} from "@joystream/types/mint";
|
|
import {ProposalDetailsOf, ProposalOf} from "@joystream/types/augment/types";
|
|
import {ProposalDetailsOf, ProposalOf} from "@joystream/types/augment/types";
|
|
-
|
|
|
|
-const fsSync = require('fs')
|
|
|
|
-const fs = fsSync.promises
|
|
|
|
|
|
+import {Moment} from "@polkadot/types/interfaces";
|
|
|
|
|
|
const PROPOSAL_URL = 'https://testnet.joystream.org/#/proposals/';
|
|
const PROPOSAL_URL = 'https://testnet.joystream.org/#/proposals/';
|
|
const ELECTION_OFFSET = 1;
|
|
const ELECTION_OFFSET = 1;
|
|
|
|
|
|
-async function main() {
|
|
|
|
- const args = process.argv.slice(2);
|
|
|
|
- if (args.length != 2) {
|
|
|
|
- console.error('Usage: [start bock number] [end block number]');
|
|
|
|
- process.exit(1);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const startCouncilBlock = Number(args[0]);
|
|
|
|
- const endCouncilBlock = Number(args[1]);
|
|
|
|
-
|
|
|
|
- const provider = new WsProvider('ws://localhost:9944');
|
|
|
|
-
|
|
|
|
- const api = new ApiPromise({provider, types: joyTypes});
|
|
|
|
- await api.isReady;
|
|
|
|
-
|
|
|
|
- const startHash = (await api.rpc.chain.getBlockHash(startCouncilBlock)) as Hash;
|
|
|
|
- const endHash = (await api.rpc.chain.getBlockHash(endCouncilBlock)) as Hash;
|
|
|
|
- const blockRange = new BlockRange(startCouncilBlock, startHash, endCouncilBlock, endHash);
|
|
|
|
-
|
|
|
|
- const reportData = await generateReportData(api, blockRange)
|
|
|
|
- const reportGenerationResult = await generateReport(reportData);
|
|
|
|
- await fs.writeFile('report.md', reportGenerationResult);
|
|
|
|
-
|
|
|
|
- api.disconnect()
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-async function generateReportData(api: ApiPromise, blockRange: BlockRange){
|
|
|
|
|
|
+export async function generateReportData(api: ApiPromise, blockRange: BlockRange){
|
|
const averageBlockProductionTime = await computeAverageBlockProductionTime(api, blockRange);
|
|
const averageBlockProductionTime = await computeAverageBlockProductionTime(api, blockRange);
|
|
|
|
|
|
const proposals = await getProposals(api, blockRange);
|
|
const proposals = await getProposals(api, blockRange);
|
|
@@ -172,25 +139,6 @@ async function generateReportData(api: ApiPromise, blockRange: BlockRange){
|
|
return reportData;
|
|
return reportData;
|
|
}
|
|
}
|
|
|
|
|
|
-async function generateReport(data: ReportData) {
|
|
|
|
- try {
|
|
|
|
- let fileData = await fs.readFile(__dirname + '/../report-template.md', {
|
|
|
|
- encoding: "utf8"
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- let entries = Object.entries(data);
|
|
|
|
-
|
|
|
|
- for (let entry of entries) {
|
|
|
|
- let regex = new RegExp('{' + entry[0] + '}', "g");
|
|
|
|
- fileData = fileData.replace(regex, entry[1].toString());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return fileData;
|
|
|
|
- } catch (e) {
|
|
|
|
- console.error(e);
|
|
|
|
- }
|
|
|
|
- return "";
|
|
|
|
-}
|
|
|
|
|
|
|
|
async function getCouncilMembersInfo(api: ApiPromise, range: BlockRange, proposals: Array<ProposalInfo>) {
|
|
async function getCouncilMembersInfo(api: ApiPromise, range: BlockRange, proposals: Array<ProposalInfo>) {
|
|
const seats = await api.query.council.activeCouncil.at(range.startBlockHash) as Seats;
|
|
const seats = await api.query.council.activeCouncil.at(range.startBlockHash) as Seats;
|
|
@@ -307,9 +255,9 @@ async function getProposals(api: ApiPromise, range: BlockRange) {
|
|
function getCouncilSecretary(proposals: ProposalInfo[]) {
|
|
function getCouncilSecretary(proposals: ProposalInfo[]) {
|
|
let filteredProposals = proposals.filter(((proposal) => {
|
|
let filteredProposals = proposals.filter(((proposal) => {
|
|
return proposal.status == ProposalStatus.Executed
|
|
return proposal.status == ProposalStatus.Executed
|
|
- && proposal.name.toLowerCase().includes('council')
|
|
|
|
- && proposal.name.toLowerCase().includes('secretary')
|
|
|
|
- && !proposal.name.toLowerCase().includes('deputy')
|
|
|
|
|
|
+ && proposal.name.toLowerCase().includes('council')
|
|
|
|
+ && proposal.name.toLowerCase().includes('secretary')
|
|
|
|
+ && !proposal.name.toLowerCase().includes('deputy')
|
|
}));
|
|
}));
|
|
|
|
|
|
if (filteredProposals.length != 1) {
|
|
if (filteredProposals.length != 1) {
|
|
@@ -322,7 +270,7 @@ function getCouncilSecretary(proposals: ProposalInfo[]) {
|
|
function getCouncilSecretaryDeputy(proposals: ProposalInfo[]) {
|
|
function getCouncilSecretaryDeputy(proposals: ProposalInfo[]) {
|
|
let filteredProposals = proposals.filter(((proposal) => {
|
|
let filteredProposals = proposals.filter(((proposal) => {
|
|
return proposal.status == ProposalStatus.Executed
|
|
return proposal.status == ProposalStatus.Executed
|
|
- && proposal.name.toLowerCase().includes('secretary') && proposal.name.toLowerCase().includes('deputy')
|
|
|
|
|
|
+ && proposal.name.toLowerCase().includes('secretary') && proposal.name.toLowerCase().includes('deputy')
|
|
}));
|
|
}));
|
|
|
|
|
|
if (filteredProposals.length != 1) {
|
|
if (filteredProposals.length != 1) {
|
|
@@ -349,6 +297,4 @@ async function computeAverageBlockProductionTime(api: ApiPromise, range: BlockRa
|
|
let endTimestamp = await api.query.timestamp.now.at(range.endBlockHash) as Moment;
|
|
let endTimestamp = await api.query.timestamp.now.at(range.endBlockHash) as Moment;
|
|
let newBlocks = range.endBlockHeight - range.startBlockHeight;
|
|
let newBlocks = range.endBlockHeight - range.startBlockHeight;
|
|
return (((Number(endTimestamp.toBigInt()) - Number(startTimestamp.toBigInt())) / 1000) / newBlocks);
|
|
return (((Number(endTimestamp.toBigInt()) - Number(startTimestamp.toBigInt())) / 1000) / newBlocks);
|
|
-}
|
|
|
|
-
|
|
|
|
-main()
|
|
|
|
|
|
+}
|