Move api-derive to correct location (#4343)

* Move api-derive to correct location

* Adjust (linting ok)

* No composite

* ApiDerive split

* Adjust

* Still WIP, getting closer

* It lints

* derive build issues sorted

* It builds :)

* Add system_health to mock

* api-augment usage

* Cleanups

* Adjust paths

* linting

* Some <'s

* Revert <>'s

* linting

* ordering

* Augmentation tweaks

* yarn.lock

* export
This commit is contained in:
Jaco
2021-12-18 09:18:55 +02:00
committed by GitHub
parent 7b8a6e89d9
commit 4913cf65fd
178 changed files with 720 additions and 685 deletions
@@ -0,0 +1,38 @@
// 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 = <T extends Codec>(value: T): Option<T> => {
const typeName = this.#registry.getClassName(value.constructor as Constructor<T>);
return new Option<T>(this.#registry, typeName as keyof InterfaceTypes, value);
};
public emptyOption = <T extends Codec>(typeName: keyof InterfaceTypes): Option<T> =>
new Option<T>(this.#registry, typeName);
}
@@ -0,0 +1,15 @@
// Copyright 2017-2021 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Bytes } from '@polkadot/types';
import { Registry } from '@polkadot/types/types';
export class BytesFactory {
#registry: Registry;
constructor (registry: Registry) {
this.#registry = registry;
}
public bytes = (value: string): Bytes => this.#registry.createType('Bytes', value);
}
+22
View File
@@ -0,0 +1,22 @@
// Copyright 2017-2021 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Metadata, TypeRegistry } from '@polkadot/types';
import metaStatic from '@polkadot/types-support/metadata/static-substrate';
export function createApiWithAugmentations (): ApiPromise {
const registry = new TypeRegistry();
const metadata = new Metadata(registry, metaStatic);
registry.setMetadata(metadata);
const api = new ApiPromise({
provider: new WsProvider('ws://', false),
registry
});
api.injectMetadata(metadata, true, registry);
return api;
}
@@ -0,0 +1,26 @@
// Copyright 2017-2021 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiPromise } from '@polkadot/api';
import type { SubmittableExtrinsic } from '@polkadot/api-base/types';
import { Proposal, ProposalIndex } from '@polkadot/types/interfaces';
import { Registry } from '@polkadot/types/types';
export class ProposalFactory {
readonly #api: ApiPromise;
readonly #registry: Registry;
constructor (api: ApiPromise) {
this.#api = api;
this.#registry = this.#api.registry;
}
public createProposal = (method: SubmittableExtrinsic<'promise'>): Proposal => {
return this.#registry.createType('Proposal', method);
};
public proposalIndex = (index: number): ProposalIndex => {
return this.#registry.createType('ProposalIndex', index);
};
}