Przeglądaj źródła

Olympia: remove what broke

Joystream Stats 2 lat temu
rodzic
commit
18fd8a36a7
5 zmienionych plików z 61 dodań i 203 usunięć
  1. 45 121
      api.ts
  2. 0 31
      content.ts
  3. 1 19
      index.ts
  4. 9 20
      rewards.ts
  5. 6 12
      types.ts

+ 45 - 121
api.ts

@@ -13,43 +13,34 @@ import {
   BlockNumber,
   EraIndex,
   EventRecord,
+  Exposure,
   Hash,
   Moment,
 } from "@polkadot/types/interfaces";
 import { SignedBlock } from "@polkadot/types/interfaces/runtime";
 import { types } from "@joystream/types";
-import { PostId, ThreadId } from "@joystream/types/common";
+import { MemberId, PostId, ThreadId } from "@joystream/types/common";
 import { CategoryId, Category, Thread, Post } from "@joystream/types/forum";
 import {
-  ElectionStage,
-  ElectionStake,
-  SealedVote,
-  Seats,
+  Candidate,
+  CouncilMember,
+  CouncilStage,
 } from "@joystream/types/council";
-import {
-  MemberId,
-  Membership,
-  PaidMembershipTerms,
-  PaidTermId,
-} from "@joystream/types/members";
-import { Mint, MintId } from "@joystream/types/mint";
+import { Membership } from "@joystream/types/members";
 import {
   Proposal,
   ProposalId,
+  ProposalCreationParameters,
   DiscussionPost,
   SpendingParams,
   VoteKind,
 } from "@joystream/types/proposals";
-import { Stake, StakeId } from "@joystream/types/stake";
-import {
-  RewardRelationship,
-  RewardRelationshipId,
-} from "@joystream/types/recurring-rewards";
 import { WorkerId, Worker } from "@joystream/types/working-group";
 import { ProposalOf, ProposalDetailsOf } from "@joystream/types/augment/types";
-import { WorkerOf } from "@joystream/types/augment-codec/all";
 
-export const connectApi = async (url: string = "ws://localhost:9944"): Promise<ApiPromise> => {
+export const connectApi = async (
+  url: string = "ws://localhost:9944"
+): Promise<ApiPromise> => {
   const provider = new WsProvider(url);
   return await ApiPromise.create({ provider, types });
 };
@@ -97,13 +88,16 @@ export const getEraStake = async (
 ): Promise<number> =>
   (await api.query.staking.erasTotalStake.at(hash, era)).toNumber();
 
-// council
-export const getCouncil = async (api: ApiPromise): Promise<Seats> =>
-  (await api.query.council.activeCouncil()) as Seats;
-
-export const getCouncilAt = (api: ApiPromise, hash: Hash): Promise<Seats> =>
-  api.query.council.activeCouncil.at(hash);
+export const getStake = async (
+  api: ApiPromise,
+  accountId: AccountId,
+  hash?: Hash
+): Promise<Exposure> =>
+  (await (hash
+    ? api.query.staking.erasStakers.at(hash, accountId)
+    : api.query.staking.erasStakers(accountId))) as Exposure;
 
+// council
 export const getCouncils = async (
   api: ApiPromise,
   head: number
@@ -154,11 +148,13 @@ export const getCouncilRound = async (
     ? ((await api.query.councilElection.round.at(hash)) as u32).toNumber()
     : ((await api.query.councilElection.round()) as u32).toNumber();
 
-export const getCouncilElectionStage = async (
+export const getCouncilElectionStage = (api: ApiPromise, hash: Hash) =>
+  getCouncilStage(api, hash); // deprecated
+export const getCouncilStage = async (
   api: ApiPromise,
   hash: Hash
-): Promise<ElectionStage> =>
-  (await api.query.councilElection.stage.at(hash)) as ElectionStage;
+): Promise<CouncilStage> =>
+  (await api.query.councilElection.stage.at(hash)) as CouncilStage;
 
 export const getCouncilTermEnd = async (
   api: ApiPromise,
@@ -172,7 +168,7 @@ export const getCouncilElectionStatus = async (
 ): Promise<ElectionInfo> => {
   const durations = await getCouncilElectionDurations(api, hash);
   const round = await getCouncilRound(api, hash);
-  const stage: ElectionStage = await getCouncilElectionStage(api, hash);
+  const stage: CouncilStage = await getCouncilStage(api, hash);
   const stageEndsAt: number = Number(stage.value as BlockNumber);
   const termEndsAt: number = await getCouncilTermEnd(api, hash);
   return { round, stageEndsAt, termEndsAt, stage, durations };
@@ -187,14 +183,7 @@ export const getCouncilSize = async (
 export const getCouncilApplicants = (
   api: ApiPromise,
   hash: Hash
-): Promise<Vec<AccountId>> => api.query.councilElection.applicants.at(hash);
-
-export const getCouncilApplicantStakes = (
-  api: ApiPromise,
-  hash: Hash,
-  applicant: AccountId
-): Promise<ElectionStake> =>
-  api.query.councilElection.applicantStakes.at(hash, applicant);
+): Promise<Vec<AccountId>> => api.query.council.applicants.at(hash);
 
 export const getCouncilCommitments = (
   api: ApiPromise,
@@ -215,7 +204,7 @@ const getCouncilElectionPeriod = (
   api: ApiPromise,
   hash: Hash,
   period: string
-): Promise<BlockNumber> => api.query.councilElection[period].at(hash);
+): Promise<BlockNumber> => api.query.council[period].at(hash);
 
 export const getCouncilElectionDurations = async (
   api: ApiPromise,
@@ -234,16 +223,6 @@ export const getCouncilElectionDurations = async (
   return durations;
 };
 
-export const getCommitments = (api: ApiPromise, hash: Hash): Promise<Hash[]> =>
-  api.query.councilElection.commitments.at(hash);
-
-export const getCommitment = (
-  api: ApiPromise,
-  blockHash: Hash,
-  voteHash: Hash
-): Promise<SealedVote> =>
-  api.query.councilElection.votes.at(blockHash, voteHash);
-
 // working groups
 export const getNextWorker = async (
   api: ApiPromise,
@@ -257,7 +236,7 @@ export const getWorker = (
   group: string,
   hash: Hash,
   id: number
-): Promise<WorkerOf> => api.query[group].workerById.at(hash, id);
+): Promise<Worker> => api.query[group].workerById.at(hash, id);
 
 export const getWorkers = async (
   api: ApiPromise,
@@ -265,42 +244,6 @@ export const getWorkers = async (
   hash: Hash
 ): Promise<number> => Number(await api.query[group].activeWorkerCount.at(hash));
 
-export const getStake = async (
-  api: ApiPromise,
-  id: StakeId | number,
-  hash?: Hash
-): Promise<Stake> =>
-  (await (hash
-    ? api.query.stake.stakes.at(hash, id)
-    : api.query.stake.stakes(id))) as Stake;
-
-export const getWorkerReward = (
-  api: ApiPromise,
-  hash: Hash,
-  id: RewardRelationshipId | number
-): Promise<RewardRelationship> =>
-  api.query.recurringRewards.rewardRelationships.at(hash, id);
-
-// mints
-export const getCouncilMint = (api: ApiPromise, hash: Hash): Promise<MintId> =>
-  api.query.council.councilMint.at(hash);
-
-export const getGroupMint = async (
-  api: ApiPromise,
-  group: string
-): Promise<MintId> => (await api.query[group].mint()) as MintId;
-
-export const getMintsCreated = async (
-  api: ApiPromise,
-  hash: Hash
-): Promise<number> => parseInt(await api.query.minting.mintsCreated.at(hash));
-
-export const getMint = (
-  api: ApiPromise,
-  hash: Hash,
-  id: MintId | number
-): Promise<Mint> => api.query.minting.mints.at(hash, id);
-
 // members
 export const getAccounts = async (
   api: ApiPromise
@@ -350,7 +293,7 @@ export const getMemberHandle = async (
   api: ApiPromise,
   id: MemberId
 ): Promise<string> =>
-  getMember(api, id).then((member: Membership) => String(member.handle));
+  getMember(api, id).then((member: Membership) => String(member.handle_hash));
 
 export const getMemberHandleByAccount = async (
   api: ApiPromise,
@@ -434,39 +377,31 @@ export const getProposal = async (
   id: ProposalId
 ): Promise<ProposalDetail> => {
   const proposal: ProposalOf = await getProposalInfo(api, id);
-  const status: { [key: string]: any } = proposal.status;
+  const {
+    parameters,
+    proposerId,
+    activatedAt,
+    status,
+    votingResults,
+    exactExecutionBlock,
+    nrOfCouncilConfirmations,
+    stakingAccountId,
+  } = proposal;
   const stage: string = status.isActive ? "Active" : "Finalized";
-  const { finalizedAt, proposalStatus } = status[`as${stage}`];
-  const result: string = proposalStatus
-    ? (proposalStatus.isApproved && "Approved") ||
-      (proposalStatus.isCanceled && "Canceled") ||
-      (proposalStatus.isExpired && "Expired") ||
-      (proposalStatus.isRejected && "Rejected") ||
-      (proposalStatus.isSlashed && "Slashed") ||
-      (proposalStatus.isVetoed && "Vetoed")
-    : "Pending";
-  const exec = proposalStatus ? proposalStatus["Approved"] : null;
-
-  const { description, parameters, proposerId, votingResults } = proposal;
   const member: Membership = await getMember(api, proposerId);
-  const author = String(member ? member.handle : proposerId);
-  const title = String(proposal.title.toHuman());
+  const author = String(member ? member.handle_hash : proposerId);
+  //const title = String(proposal.title.toHuman());
   const type: string = await getProposalType(api, id);
-  const args: string[] = [String(id), title, type, stage, result, author];
+  const args: string[] = [String(id), ``, type, stage, ``, author];
   const message = formatProposalMessage(args);
-  const created: number = Number(proposal.createdAt);
 
   return {
     id: Number(id),
-    title,
-    created,
-    finalizedAt,
+    activatedAt: +activatedAt,
+    executedAt: +exactExecutionBlock,
     parameters: JSON.stringify(parameters),
     message,
-    stage,
-    result,
-    exec,
-    description: description.toHuman(),
+    status,
     votes: votingResults,
     type,
     author,
@@ -539,25 +474,14 @@ export const getValidators = async (
   return snapshot.isSome ? snapshot.unwrap() : [];
 };
 
-export const getPaidMembershipTermsById = (
-  api: ApiPromise,
-  hash: Hash,
-  id: PaidTermId | number
-): Promise<PaidMembershipTerms> =>
-  api.query.members.paidMembershipTermsById.at(hash, id);
-
 export {
   getChannel,
   getChannelCategory,
   getCuratorGroup,
-  getPerson,
-  getPlaylist,
-  getSeries,
   getVideo,
   getVideoCategory,
   getNextChannel,
   getNextChannelCategory,
-  getNextChannelOwnershipTransferRequestId,
   getNextCuratorGroup,
   getNextPerson,
   getNextPlaylist,

+ 0 - 31
content.ts

@@ -5,14 +5,6 @@ import {
   Channel,
   ChannelCategory,
   ChannelCategoryId,
-  ChannelOwnershipTransferRequest,
-  ChannelOwnershipTransferRequestId,
-  Person,
-  PersonId,
-  Playlist,
-  PlaylistId,
-  Series,
-  SeriesId,
   Video,
   VideoId,
   VideoCategory,
@@ -48,21 +40,6 @@ export const getVideoCategory = (
   id: VideoId | number
 ): Promise<Video> => api.query.content.videoCategoryById(id) as Promise<Video>;
 
-export const getPerson = (
-  api: ApiPromise,
-  id: PersonId | number
-): Promise<Person> => api.query.content.personById(id) as Promise<Person>;
-
-export const getPlaylist = (
-  api: ApiPromise,
-  id: PlaylistId | number
-): Promise<Playlist> => api.query.content.playlistById(id) as Promise<Playlist>;
-
-export const getSeries = (
-  api: ApiPromise,
-  id: SeriesId | number
-): Promise<Series> => api.query.content.seriesById(id) as Promise<Series>;
-
 export const getNextChannel = (
   api: ApiPromise,
   hash?: Hash
@@ -79,14 +56,6 @@ export const getNextChannelCategory = (
     ? api.query.content.nextChannelCategoryId.at(hash)
     : (api.query.content.nextChannelCategoryId() as Promise<ChannelCategoryId>);
 
-export const getNextChannelOwnershipTransferRequestId = (
-  api: ApiPromise,
-  hash?: Hash
-): Promise<ChannelOwnershipTransferRequestId> =>
-  hash
-    ? api.query.content.nextChannelOwnershipTransferRequestId.at(hash)
-    : (api.query.content.nextChannelOwnershipTransferRequestId() as Promise<ChannelOwnershipTransferRequestId>);
-
 export const getNextCuratorGroup = (
   api: ApiPromise,
   hash?: Hash

+ 1 - 19
index.ts

@@ -1,5 +1,4 @@
 import { CacheEvent } from "./types";
-import { Mint, MintId } from "@joystream/types/mint";
 import { Moment } from "@polkadot/types/interfaces";
 
 export const sum = (a: number[]) =>
@@ -13,9 +12,6 @@ export const getPercent = (value1: number, value2: number): number => {
 export const momentToString = (timestamp: number) =>
   new Date(timestamp).toLocaleDateString("en-US");
 
-export const getTotalMinted = (mint: Mint) =>
-  Number(mint.getField("total_minted").toString());
-
 export const eventStats = (blockEventsCache: Map<number, CacheEvent[]>) => {
   let sections: {
     [key: string]: { [key: string]: [{ key: number; data: any }] };
@@ -47,31 +43,22 @@ export {
   getEvents,
   getEra,
   getEraStake,
-  getCouncil,
-  getCouncilAt,
   getCouncils,
   getCouncilRound,
+  getCouncilStage,
   getCouncilElectionStage,
   getCouncilTermEnd,
   getCouncilElectionStatus,
   getCouncilSize,
   getCouncilApplicants,
-  getCouncilApplicantStakes,
   getCouncilCommitments,
   getCouncilPayoutInterval,
   getCouncilPayout,
   getCouncilElectionDurations,
-  getCommitments,
-  getCommitment,
   getNextWorker,
   getWorker,
   getWorkers,
   getStake,
-  getWorkerReward,
-  getCouncilMint,
-  getGroupMint,
-  getMintsCreated,
-  getMint,
   getAccounts,
   getAccount,
   getNextMember,
@@ -98,21 +85,16 @@ export {
   getProposalThreadCount,
   getValidatorCount,
   getValidators,
-  getPaidMembershipTermsById,
 } from "./api";
 
 export {
   getChannel,
   getChannelCategory,
   getCuratorGroup,
-  getPerson,
-  getPlaylist,
-  getSeries,
   getVideo,
   getVideoCategory,
   getNextChannel,
   getNextChannelCategory,
-  getNextChannelOwnershipTransferRequestId,
   getNextCuratorGroup,
   getNextPerson,
   getNextPlaylist,

+ 9 - 20
rewards.ts

@@ -5,36 +5,28 @@ import { Bounty, CacheEvent, WorkerReward, SpendingProposal } from "./types";
 import { AccountId, Balance } from "@polkadot/types/interfaces";
 import { Hash } from "@polkadot/types/interfaces";
 import { Membership } from "@joystream/types/members";
-import { Mint, MintId } from "@joystream/types/mint";
 import {
   Proposal,
   ProposalId,
   SpendingParams,
 } from "@joystream/types/proposals";
 import { ProposalDetails, ProposalOf } from "@joystream/types/augment/types";
-import { Stake } from "@joystream/types/stake";
-import {
-  RewardRelationship,
-  RewardRelationshipId,
-} from "@joystream/types/recurring-rewards";
 
 // lib
-import { getPercent, getTotalMinted } from "./";
+import { getPercent } from "./";
 import {
   getBlock,
   getBlockHash,
-  getMint,
   getNextWorker,
   getMember,
   getWorker,
-  getWorkerReward,
   getProposalInfo,
   getProposalDetails,
   getStake,
   getValidators,
   getValidatorCount,
 } from "./api";
-import { WorkerOf } from "@joystream/types/augment-codec/all";
+import { Worker } from "@joystream/types/augment-codec/all";
 import { ProposalDetailsOf } from "@joystream/types/augment/types";
 
 export const filterMethods = {
@@ -57,16 +49,17 @@ export const getWorkerRewards = async (
   const nextWorkerId = await getNextWorker(api, group, hash);
 
   for (let id = 0; id < nextWorkerId; ++id) {
-    const worker: WorkerOf = await getWorker(api, group, hash, id);
+    const worker: Worker = await getWorker(api, group, hash, id);
 
     const account = worker.role_account_id as AccountId;
     const memberId = worker.member_id;
     const member: Membership = await getMember(api, memberId, hash);
-    const handle = member ? String(member.handle) : account.toString();
+    const handle = member ? String(member.handle_hash) : account.toString();
     const status = worker.is_active ? `active` : `inactive`;
 
     // fetch reward and stake
     const w: WorkerReward = { id, status, handle, account, memberId };
+    /**
     if (worker.role_stake_profile.isSome) {
       const roleStakeProfile = worker.role_stake_profile.unwrap();
       w.stake = await getStake(api, roleStakeProfile.stake_id);
@@ -75,7 +68,7 @@ export const getWorkerRewards = async (
     if (worker.reward_relationship.isSome) {
       const id: RewardRelationshipId = worker.reward_relationship.unwrap();
       w.reward = await getWorkerReward(api, hash, id);
-    }
+    } **/
     workers.push(w);
   }
   return workers;
@@ -128,18 +121,14 @@ export const getFinalizedSpendingProposals = async (
       const proposalId = event.data[0] as ProposalId;
       const id = +proposalId;
       const proposalInfo: ProposalOf = await getProposalInfo(api, proposalId);
-      const finalizedData = proposalInfo.status.asFinalized;
       const details: ProposalDetailsOf = await getProposalDetails(
         api,
         proposalId
       );
-      if (!finalizedData.proposalStatus.isApproved || !details.isSpending)
-        continue;
-      let approvedData = finalizedData.proposalStatus.asApproved;
-      if (!approvedData.isExecuted) continue;
+      if (!proposalInfo.status || !details.isFundingRequest) continue;
       if (spendingProposals.some((proposal) => +proposal.id === +id)) continue;
-      const title = String(proposalInfo.title.toHuman());
-      const amount = +details.asSpending[0];
+      const title = ``; //String(proposalInfo.title.toHuman());
+      const amount = 0;
 
       console.log(`Spent ${amount.toFixed().padStart(8)} on ${id} ${title}`);
       spendingProposals.push({ id, title, amount });

+ 6 - 12
types.ts

@@ -1,8 +1,6 @@
 import { AccountId, AccountData } from "@polkadot/types/interfaces";
 import { GenericEventData } from "@polkadot/types/generic/Event";
-import { MemberId } from "@joystream/types/members";
-import { Stake } from "@joystream/types/stake";
-import { RewardRelationship } from "@joystream/types/recurring-rewards";
+import { MemberId } from "@joystream/types/common";
 import { VotingResults } from "@joystream/types/augment/all";
 
 export interface AccountBalance {
@@ -24,16 +22,12 @@ export interface Vote {
 }
 
 export interface ProposalDetail {
-  created: number;
-  finalizedAt: number;
+  activatedAt: number;
+  executedAt: number;
   message: { tg: string; discord: string };
   parameters: string; // ProposalParameters
-  stage: any;
-  result: string;
-  exec: any;
+  status: any;
   id: number;
-  title: string;
-  description: any;
   votes: VotingResults;
   type: string;
   votesByAccount?: Vote[];
@@ -84,8 +78,8 @@ export interface WorkerReward {
   memberId: MemberId;
   account: AccountId;
   handle: string;
-  stake?: Stake;
-  reward?: RewardRelationship;
+  stake?: any;
+  reward?: any;
   status: string;
 }