|
@@ -4,7 +4,6 @@ import moment from "moment";
|
|
// types
|
|
// types
|
|
import { AccountBalance, ElectionInfo, Round, ProposalDetail } from "./types";
|
|
import { AccountBalance, ElectionInfo, Round, ProposalDetail } from "./types";
|
|
import { Option, u32, u64, Vec, StorageKey } from "@polkadot/types";
|
|
import { Option, u32, u64, Vec, StorageKey } from "@polkadot/types";
|
|
-import type { Codec, Observable } from "@polkadot/types/types";
|
|
|
|
import {
|
|
import {
|
|
AccountId,
|
|
AccountId,
|
|
AccountInfo,
|
|
AccountInfo,
|
|
@@ -13,43 +12,22 @@ import {
|
|
BlockNumber,
|
|
BlockNumber,
|
|
EraIndex,
|
|
EraIndex,
|
|
EventRecord,
|
|
EventRecord,
|
|
|
|
+ Exposure,
|
|
Hash,
|
|
Hash,
|
|
- Moment,
|
|
|
|
} from "@polkadot/types/interfaces";
|
|
} from "@polkadot/types/interfaces";
|
|
import { SignedBlock } from "@polkadot/types/interfaces/runtime";
|
|
import { SignedBlock } from "@polkadot/types/interfaces/runtime";
|
|
import { types } from "@joystream/types";
|
|
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 { 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 { WorkerId, Worker } from "@joystream/types/working-group";
|
|
import { ProposalOf, ProposalDetailsOf } from "@joystream/types/augment/types";
|
|
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);
|
|
const provider = new WsProvider(url);
|
|
return await ApiPromise.create({ provider, types });
|
|
return await ApiPromise.create({ provider, types });
|
|
};
|
|
};
|
|
@@ -97,13 +75,16 @@ export const getEraStake = async (
|
|
): Promise<number> =>
|
|
): Promise<number> =>
|
|
(await api.query.staking.erasTotalStake.at(hash, era)).toNumber();
|
|
(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 (
|
|
export const getCouncils = async (
|
|
api: ApiPromise,
|
|
api: ApiPromise,
|
|
head: number
|
|
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.at(hash)) as u32).toNumber()
|
|
: ((await api.query.councilElection.round()) 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,
|
|
api: ApiPromise,
|
|
hash: Hash
|
|
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 (
|
|
export const getCouncilTermEnd = async (
|
|
api: ApiPromise,
|
|
api: ApiPromise,
|
|
@@ -172,7 +155,7 @@ export const getCouncilElectionStatus = async (
|
|
): Promise<ElectionInfo> => {
|
|
): Promise<ElectionInfo> => {
|
|
const durations = await getCouncilElectionDurations(api, hash);
|
|
const durations = await getCouncilElectionDurations(api, hash);
|
|
const round = await getCouncilRound(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 stageEndsAt: number = Number(stage.value as BlockNumber);
|
|
const termEndsAt: number = await getCouncilTermEnd(api, hash);
|
|
const termEndsAt: number = await getCouncilTermEnd(api, hash);
|
|
return { round, stageEndsAt, termEndsAt, stage, durations };
|
|
return { round, stageEndsAt, termEndsAt, stage, durations };
|
|
@@ -187,14 +170,7 @@ export const getCouncilSize = async (
|
|
export const getCouncilApplicants = (
|
|
export const getCouncilApplicants = (
|
|
api: ApiPromise,
|
|
api: ApiPromise,
|
|
hash: Hash
|
|
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 = (
|
|
export const getCouncilCommitments = (
|
|
api: ApiPromise,
|
|
api: ApiPromise,
|
|
@@ -215,7 +191,7 @@ const getCouncilElectionPeriod = (
|
|
api: ApiPromise,
|
|
api: ApiPromise,
|
|
hash: Hash,
|
|
hash: Hash,
|
|
period: string
|
|
period: string
|
|
-): Promise<BlockNumber> => api.query.councilElection[period].at(hash);
|
|
|
|
|
|
+): Promise<BlockNumber> => api.query.council[period].at(hash);
|
|
|
|
|
|
export const getCouncilElectionDurations = async (
|
|
export const getCouncilElectionDurations = async (
|
|
api: ApiPromise,
|
|
api: ApiPromise,
|
|
@@ -234,16 +210,6 @@ export const getCouncilElectionDurations = async (
|
|
return durations;
|
|
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
|
|
// working groups
|
|
export const getNextWorker = async (
|
|
export const getNextWorker = async (
|
|
api: ApiPromise,
|
|
api: ApiPromise,
|
|
@@ -257,7 +223,7 @@ export const getWorker = (
|
|
group: string,
|
|
group: string,
|
|
hash: Hash,
|
|
hash: Hash,
|
|
id: number
|
|
id: number
|
|
-): Promise<WorkerOf> => api.query[group].workerById.at(hash, id);
|
|
|
|
|
|
+): Promise<Worker> => api.query[group].workerById.at(hash, id);
|
|
|
|
|
|
export const getWorkers = async (
|
|
export const getWorkers = async (
|
|
api: ApiPromise,
|
|
api: ApiPromise,
|
|
@@ -265,42 +231,6 @@ export const getWorkers = async (
|
|
hash: Hash
|
|
hash: Hash
|
|
): Promise<number> => Number(await api.query[group].activeWorkerCount.at(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
|
|
// members
|
|
export const getAccounts = async (
|
|
export const getAccounts = async (
|
|
api: ApiPromise
|
|
api: ApiPromise
|
|
@@ -350,7 +280,7 @@ export const getMemberHandle = async (
|
|
api: ApiPromise,
|
|
api: ApiPromise,
|
|
id: MemberId
|
|
id: MemberId
|
|
): Promise<string> =>
|
|
): 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 (
|
|
export const getMemberHandleByAccount = async (
|
|
api: ApiPromise,
|
|
api: ApiPromise,
|
|
@@ -434,39 +364,31 @@ export const getProposal = async (
|
|
id: ProposalId
|
|
id: ProposalId
|
|
): Promise<ProposalDetail> => {
|
|
): Promise<ProposalDetail> => {
|
|
const proposal: ProposalOf = await getProposalInfo(api, id);
|
|
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 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 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 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 message = formatProposalMessage(args);
|
|
- const created: number = Number(proposal.createdAt);
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
id: Number(id),
|
|
id: Number(id),
|
|
- title,
|
|
|
|
- created,
|
|
|
|
- finalizedAt,
|
|
|
|
|
|
+ activatedAt: +activatedAt,
|
|
|
|
+ executedAt: +exactExecutionBlock,
|
|
parameters: JSON.stringify(parameters),
|
|
parameters: JSON.stringify(parameters),
|
|
message,
|
|
message,
|
|
- stage,
|
|
|
|
- result,
|
|
|
|
- exec,
|
|
|
|
- description: description.toHuman(),
|
|
|
|
|
|
+ status,
|
|
votes: votingResults,
|
|
votes: votingResults,
|
|
type,
|
|
type,
|
|
author,
|
|
author,
|
|
@@ -539,25 +461,14 @@ export const getValidators = async (
|
|
return snapshot.isSome ? snapshot.unwrap() : [];
|
|
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 {
|
|
export {
|
|
getChannel,
|
|
getChannel,
|
|
getChannelCategory,
|
|
getChannelCategory,
|
|
getCuratorGroup,
|
|
getCuratorGroup,
|
|
- getPerson,
|
|
|
|
- getPlaylist,
|
|
|
|
- getSeries,
|
|
|
|
getVideo,
|
|
getVideo,
|
|
getVideoCategory,
|
|
getVideoCategory,
|
|
getNextChannel,
|
|
getNextChannel,
|
|
getNextChannelCategory,
|
|
getNextChannelCategory,
|
|
- getNextChannelOwnershipTransferRequestId,
|
|
|
|
getNextCuratorGroup,
|
|
getNextCuratorGroup,
|
|
getNextPerson,
|
|
getNextPerson,
|
|
getNextPlaylist,
|
|
getNextPlaylist,
|