|
@@ -4,7 +4,6 @@ import moment from "moment";
|
|
|
// types
|
|
|
import { AccountBalance, ElectionInfo, Round, ProposalDetail } from "./types";
|
|
|
import { Option, u32, u64, Vec, StorageKey } from "@polkadot/types";
|
|
|
-import type { Codec, Observable } from "@polkadot/types/types";
|
|
|
import {
|
|
|
AccountId,
|
|
|
AccountInfo,
|
|
@@ -13,43 +12,22 @@ 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,
|
|
|
-} from "@joystream/types/council";
|
|
|
-import {
|
|
|
- MemberId,
|
|
|
- Membership,
|
|
|
- PaidMembershipTerms,
|
|
|
- PaidTermId,
|
|
|
-} from "@joystream/types/members";
|
|
|
-import { Mint, MintId } from "@joystream/types/mint";
|
|
|
-import {
|
|
|
- Proposal,
|
|
|
- ProposalId,
|
|
|
- DiscussionPost,
|
|
|
- SpendingParams,
|
|
|
- VoteKind,
|
|
|
-} from "@joystream/types/proposals";
|
|
|
-import { Stake, StakeId } from "@joystream/types/stake";
|
|
|
-import {
|
|
|
- RewardRelationship,
|
|
|
- RewardRelationshipId,
|
|
|
-} from "@joystream/types/recurring-rewards";
|
|
|
+import { CouncilStage } from "@joystream/types/council";
|
|
|
+import { Membership } from "@joystream/types/members";
|
|
|
+import { ProposalId, DiscussionPost } from "@joystream/types/proposals";
|
|
|
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 +75,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 +135,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 +155,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 +170,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 +191,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 +210,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 +223,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 +231,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 +280,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 +364,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 +461,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,
|