Sfoglia il codice sorgente

getHead, getCommitments, getCommitment. getProposalPosts

Joystream Stats 3 anni fa
parent
commit
8471dd04e9
2 ha cambiato i file con 25 aggiunte e 1 eliminazioni
  1. 18 1
      api.ts
  2. 7 0
      types.ts

+ 18 - 1
api.ts

@@ -3,7 +3,7 @@ import moment from "moment";
 
 // types
 import { AccountBalance, ElectionInfo, Round, ProposalDetail } from "./types";
-import { Option, u32, u64, Vec } from "@polkadot/types";
+import { Option, u32, u64, Vec, StorageKey } from "@polkadot/types";
 import type { Codec, Observable } from "@polkadot/types/types";
 import {
   AccountId,
@@ -67,6 +67,8 @@ export const getBlockHash = (
   }
 };
 
+export const getHead = (api: ApiPromise) => api.derive.chain.bestNumber();
+
 export const getTimestamp = async (
   api: ApiPromise,
   hash: Hash
@@ -223,6 +225,16 @@ 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,
@@ -456,6 +468,11 @@ export const getProposalPost = async (
     postId
   )) as DiscussionPost;
 
+export const getProposalPosts = (
+  api: ApiPromise
+): Promise<[StorageKey<any>, DiscussionPost][]> =>
+  api.query.proposalsDiscussion.postThreadIdByPostId.entries();
+
 export const getProposalPostCount = async (api: ApiPromise): Promise<number> =>
   Number((await api.query.proposalsDiscussion.postCount()) as u64);
 

+ 7 - 0
types.ts

@@ -53,6 +53,13 @@ export interface Round {
   end: number;
 }
 
+interface Vote {
+  voter: AccountId
+  commitment: Hash
+  stake: { new: number; transferred: number }
+  vote: AccountId
+}
+
 export class Bounty {
   constructor(
     public testnet: string,