123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- import BN from 'bn.js'
- import { ElectionStage, Seat } from '@joystream/types/council'
- import { Option } from '@polkadot/types'
- import { Codec } from '@polkadot/types/types'
- import { BlockNumber, Balance, AccountId } from '@polkadot/types/interfaces'
- import { DeriveBalancesAll } from '@polkadot/api-derive/types'
- import { KeyringPair } from '@polkadot/keyring/types'
- import { WorkerId, OpeningType } from '@joystream/types/working-group'
- import { Membership, MemberId } from '@joystream/types/members'
- import { Opening, StakingPolicy, ApplicationStageKeys } from '@joystream/types/hiring'
- import { Validator } from 'inquirer'
- import {
- VideoMetadata,
- ChannelMetadata,
- ChannelCategoryMetadata,
- VideoCategoryMetadata,
- } from '@joystream/content-metadata-protobuf'
- import { ContentId, ContentParameters } from '@joystream/types/storage'
- import { JSONSchema7, JSONSchema7Definition } from 'json-schema'
- // KeyringPair type extended with mandatory "meta.name"
- // It's used for accounts/keys management within CLI.
- // If not provided in the account json file, the meta.name value is set to "Unnamed Account"
- export type NamedKeyringPair = KeyringPair & {
- meta: {
- name: string
- }
- }
- // Summary of the account information fetched from the api for "account:current" purposes (currently just balances)
- export type AccountSummary = {
- balances: DeriveBalancesAll
- }
- // This function allows us to easily transform the tuple into the object
- // and simplifies the creation of consitent Object and Tuple types (seen below).
- export function createCouncilInfoObj(
- activeCouncil: Seat[],
- termEndsAt: BlockNumber,
- autoStart: boolean,
- newTermDuration: BN,
- candidacyLimit: BN,
- councilSize: BN,
- minCouncilStake: Balance,
- minVotingStake: Balance,
- announcingPeriod: BlockNumber,
- votingPeriod: BlockNumber,
- revealingPeriod: BlockNumber,
- round: BN,
- stage: Option<ElectionStage>
- ) {
- return {
- activeCouncil,
- termEndsAt,
- autoStart,
- newTermDuration,
- candidacyLimit,
- councilSize,
- minCouncilStake,
- minVotingStake,
- announcingPeriod,
- votingPeriod,
- revealingPeriod,
- round,
- stage,
- }
- }
- // Object/Tuple containing council/councilElection information (council:info).
- // The tuple is useful, because that's how api.queryMulti returns the results.
- export type CouncilInfoTuple = Parameters<typeof createCouncilInfoObj>
- export type CouncilInfoObj = ReturnType<typeof createCouncilInfoObj>
- // Object with "name" and "value" properties, used for rendering simple CLI tables like:
- // Total balance: 100 JOY
- // Free calance: 50 JOY
- export type NameValueObj = { name: string; value: string }
- // Working groups related types
- export enum WorkingGroups {
- StorageProviders = 'storageProviders',
- Curators = 'curators',
- Operations = 'operations',
- Gateway = 'gateway',
- }
- // In contrast to Pioneer, currently only StorageProviders group is available in CLI
- export const AvailableGroups: readonly WorkingGroups[] = [
- WorkingGroups.StorageProviders,
- WorkingGroups.Curators,
- WorkingGroups.Operations,
- ] as const
- export type Reward = {
- totalRecieved: Balance
- value: Balance
- interval?: number
- nextPaymentBlock: number // 0 = no incoming payment
- }
- // Compound working group types
- export type GroupMember = {
- workerId: WorkerId
- memberId: MemberId
- roleAccount: AccountId
- profile: Membership
- stake?: Balance
- reward?: Reward
- }
- export type GroupApplication = {
- wgApplicationId: number
- applicationId: number
- wgOpeningId: number
- member: Membership | null
- roleAccout: AccountId
- stakes: {
- application: number
- role: number
- }
- humanReadableText: string
- stage: ApplicationStageKeys
- }
- export enum OpeningStatus {
- WaitingToBegin = 'WaitingToBegin',
- AcceptingApplications = 'AcceptingApplications',
- InReview = 'InReview',
- Complete = 'Complete',
- Cancelled = 'Cancelled',
- Unknown = 'Unknown',
- }
- export type GroupOpeningStage = {
- status: OpeningStatus
- block?: number
- date?: Date
- }
- export type GroupOpeningStakes = {
- application?: StakingPolicy
- role?: StakingPolicy
- }
- export const stakingPolicyUnstakingPeriodKeys = [
- 'crowded_out_unstaking_period_length',
- 'review_period_expired_unstaking_period_length',
- ] as const
- export type StakingPolicyUnstakingPeriodKey = typeof stakingPolicyUnstakingPeriodKeys[number]
- export const openingPolicyUnstakingPeriodsKeys = [
- 'fill_opening_failed_applicant_application_stake_unstaking_period',
- 'fill_opening_failed_applicant_role_stake_unstaking_period',
- 'fill_opening_successful_applicant_application_stake_unstaking_period',
- 'terminate_application_stake_unstaking_period',
- 'terminate_role_stake_unstaking_period',
- 'exit_role_application_stake_unstaking_period',
- 'exit_role_stake_unstaking_period',
- ] as const
- export type OpeningPolicyUnstakingPeriodsKey = typeof openingPolicyUnstakingPeriodsKeys[number]
- export type UnstakingPeriodsKey =
- | OpeningPolicyUnstakingPeriodsKey
- | 'crowded_out_application_stake_unstaking_period_length'
- | 'crowded_out_role_stake_unstaking_period_length'
- | 'review_period_expired_application_stake_unstaking_period_length'
- | 'review_period_expired_role_stake_unstaking_period_length'
- export type UnstakingPeriods = {
- [k in UnstakingPeriodsKey]: number
- }
- export type GroupOpening = {
- wgOpeningId: number
- openingId: number
- stage: GroupOpeningStage
- opening: Opening
- stakes: GroupOpeningStakes
- applications: GroupApplication[]
- type: OpeningType
- unstakingPeriods: UnstakingPeriods
- }
- // Api-related
- // Additional options that can be passed to ApiCommandBase.promptForParam in order to override
- // its default behaviour, change param name, add validation etc.
- export type ApiParamOptions<ParamType = Codec> = {
- forcedName?: string
- value?: {
- default: ParamType
- locked?: boolean
- }
- validator?: Validator
- nestedOptions?: ApiParamsOptions // For more complex params, like structs
- }
- export type ApiParamsOptions = {
- [paramName: string]: ApiParamOptions
- }
- export type ApiMethodArg = Codec
- export type ApiMethodNamedArg = {
- name: string
- value: ApiMethodArg
- }
- export type ApiMethodNamedArgs = ApiMethodNamedArg[]
- // Content-related
- export enum AssetType {
- AnyAsset = 1,
- }
- export type InputAsset = {
- path: string
- contentId: ContentId
- }
- export type InputAssetDetails = InputAsset & {
- parameters: ContentParameters
- }
- export type VideoFFProbeMetadata = {
- width?: number
- height?: number
- codecName?: string
- codecFullName?: string
- duration?: number
- }
- export type VideoFileMetadata = VideoFFProbeMetadata & {
- size: number
- container: string
- mimeType: string
- }
- export type VideoInputParameters = Omit<VideoMetadata.AsObject, 'video' | 'thumbnailPhoto'> & {
- videoPath?: string
- thumbnailPhotoPath?: string
- }
- export type ChannelInputParameters = Omit<ChannelMetadata.AsObject, 'coverPhoto' | 'avatarPhoto'> & {
- coverPhotoPath?: string
- avatarPhotoPath?: string
- rewardAccount?: string
- }
- export type ChannelCategoryInputParameters = ChannelCategoryMetadata.AsObject
- export type VideoCategoryInputParameters = VideoCategoryMetadata.AsObject
- // JSONSchema utility types
- export type JSONTypeName<T> = T extends string
- ? 'string' | ['string', 'null']
- : T extends number
- ? 'number' | ['number', 'null']
- : T extends any[]
- ? 'array' | ['array', 'null']
- : T extends Record<string, unknown>
- ? 'object' | ['object', 'null']
- : T extends boolean
- ? 'boolean' | ['boolean', 'null']
- : never
- export type PropertySchema<P> = Omit<
- JSONSchema7Definition & {
- type: JSONTypeName<P>
- properties: P extends Record<string, unknown> ? JsonSchemaProperties<P> : never
- },
- P extends Record<string, unknown> ? '' : 'properties'
- >
- export type JsonSchemaProperties<T extends Record<string, unknown>> = {
- [K in keyof Required<T>]: PropertySchema<Required<T>[K]>
- }
- export type JsonSchema<T extends Record<string, unknown>> = JSONSchema7 & {
- type: 'object'
- properties: JsonSchemaProperties<T>
- }
|