// Copyright 2017-2021 @polkadot/api authors & contributors // SPDX-License-Identifier: Apache-2.0 import { ApiPromise } from '@polkadot/api'; import { Option, StorageKey } from '@polkadot/types'; import { Bounty, BountyIndex } from '@polkadot/types/interfaces'; import { Codec, Constructor, InterfaceTypes, Registry } from '@polkadot/types/types'; export class BountyFactory { readonly #api: ApiPromise; readonly #registry: Registry; constructor (api: ApiPromise) { this.#api = api; this.#registry = this.#api.registry; } public storageKey = (index: number): StorageKey => { const key = new StorageKey(this.#registry, this.#api.query.bounties.bounties.key(this.bountyIndex(index))); return key.setMeta(this.#api.query.bounties.bounties.creator.meta); }; public bountyIndex = (index: number): BountyIndex => this.#registry.createType('BountyIndex', index); public defaultBounty = (): Bounty => this.#registry.createType('Bounty'); public optionOf = (value: T): Option => { const typeName = this.#registry.getClassName(value.constructor as Constructor); return new Option(this.#registry, typeName as keyof InterfaceTypes, value); }; public emptyOption = (typeName: keyof InterfaceTypes): Option => new Option(this.#registry, typeName); }