Support for contracts metadata V2 (#4289)
* Support for contracts metadata V2 * Add & use latest * Build interfaces * conversion of V1 -> Latest * spreads * Use V2 in creation, aka s/name/label/ * Extract -> latest conversion * Flatten * Add V2 test contracts (tests are failing) * V2, V1 & V1 catered for in Abi.spec.ts * Explicit v0/v1 -> Latest conversions * Adjust V2/V1/V0 check order * Cleanup type assertions * Save * Remove eslint unsafe * Flatten test exports * Entries... last non-critical, OCD-driven change... * tsc check fixes * Conversion tests * v1ToLatest renames * Text[] * Split conversion (ease of future change) * V2 in V2 conversion * Dedupe? * Additional cleanups * Adjust * Flatten types * Adjust * filter versions adjustments * additional, get it done.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AnyJson, Registry } from '@polkadot/types/types';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -14,6 +14,7 @@ import { Abi } from '.';
|
||||
|
||||
interface SpecDef {
|
||||
messages: {
|
||||
label: string;
|
||||
name: string[] | string
|
||||
}[]
|
||||
}
|
||||
@@ -28,6 +29,9 @@ interface JSONAbi {
|
||||
spec: SpecDef;
|
||||
V1: {
|
||||
spec: SpecDef;
|
||||
},
|
||||
V2: {
|
||||
spec: SpecDef;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,11 +51,19 @@ function stringifyJson (registry: Registry): string {
|
||||
|
||||
describe('Abi', (): void => {
|
||||
describe('ABI', (): void => {
|
||||
Object.entries(abis).forEach(([abiName, abi]: [string, JSONAbi]) => {
|
||||
Object.entries(abis).forEach(([abiName, _abi]) => {
|
||||
const abi = _abi as unknown as JSONAbi;
|
||||
|
||||
it(`initializes from a contract ABI (${abiName})`, (): void => {
|
||||
try {
|
||||
const messageIds = (abi.V1 ? abi.V1 : abi).spec.messages.map(({ name }) => Array.isArray(name) ? name[0] : name);
|
||||
const inkAbi = new Abi(abis[abiName] as AnyJson);
|
||||
const messageIds = (abi.V2 || abi.V1 || abi).spec.messages.map(({ label, name }) =>
|
||||
label || (
|
||||
Array.isArray(name)
|
||||
? name[0]
|
||||
: name
|
||||
)
|
||||
);
|
||||
const inkAbi = new Abi(abis[abiName]);
|
||||
|
||||
expect(inkAbi.messages.map(({ identifier }) => identifier)).toEqual(messageIds);
|
||||
} catch (error) {
|
||||
@@ -66,7 +78,7 @@ describe('Abi', (): void => {
|
||||
describe('TypeDef', (): void => {
|
||||
Object.keys(abis).forEach((abiName) => {
|
||||
it(`initializes from a contract ABI (${abiName})`, (): void => {
|
||||
const abi = new Abi(abis[abiName] as AnyJson);
|
||||
const abi = new Abi(abis[abiName]);
|
||||
const json = stringifyJson(abi.registry);
|
||||
const cmpPath = path.join(__dirname, `../../test/compare/${abiName}.test.json`);
|
||||
|
||||
@@ -87,8 +99,8 @@ describe('Abi', (): void => {
|
||||
});
|
||||
|
||||
it('has the correct hash for the source', (): void => {
|
||||
const bundle = abis.ink_v0_flipperBundle as JSONAbi;
|
||||
const abi = new Abi(bundle as unknown as AnyJson);
|
||||
const abi = new Abi(abis.ink_v0_flipperBundle);
|
||||
const bundle = abis.ink_v0_flipperBundle as unknown as JSONAbi;
|
||||
|
||||
// manual
|
||||
expect(bundle.source.hash).toEqual(blake2AsHex(bundle.source.wasm));
|
||||
|
||||
@@ -2,24 +2,14 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Bytes, PortableRegistry } from '@polkadot/types';
|
||||
import type { ChainProperties, ContractConstructorSpec, ContractEventSpec, ContractMessageParamSpec, ContractMessageSpec, ContractMetadataLatest, ContractProjectInfo } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson, Codec, Registry } from '@polkadot/types/types';
|
||||
import type { ChainProperties, ContractConstructorSpecLatest, ContractEventSpecLatest, ContractMessageParamSpecLatest, ContractMessageSpecLatest, ContractMetadataLatest, ContractProjectInfo } from '@polkadot/types/interfaces';
|
||||
import type { Codec, Registry } from '@polkadot/types/types';
|
||||
import type { AbiConstructor, AbiEvent, AbiMessage, AbiParam, DecodedEvent, DecodedMessage } from '../types';
|
||||
|
||||
import { TypeDefInfo, TypeRegistry } from '@polkadot/types';
|
||||
import { assert, assertReturn, compactAddLength, compactStripLength, isNumber, isObject, isString, logger, stringCamelCase, stringify, u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { toLatest } from './toLatest';
|
||||
|
||||
interface V0AbiJson {
|
||||
metadataVersion: string;
|
||||
spec: {
|
||||
constructors: unknown[];
|
||||
events: unknown[];
|
||||
messages: unknown[];
|
||||
};
|
||||
types: unknown[];
|
||||
}
|
||||
import { v0ToLatest, v1ToLatest } from './toLatest';
|
||||
|
||||
const l = logger('Abi');
|
||||
|
||||
@@ -35,16 +25,29 @@ function findMessage <T extends AbiMessage> (list: T[], messageOrId: T | string
|
||||
return assertReturn(message, () => `Attempted to call an invalid contract interface, ${stringify(messageOrId)}`);
|
||||
}
|
||||
|
||||
function parseJson (json: AnyJson, chainProperties?: ChainProperties): [AnyJson, Registry, ContractMetadataLatest, ContractProjectInfo] {
|
||||
// FIXME: This is still workable with V0, V1 & V2, but certainly is not a scalable
|
||||
// approach (right at this point don't quite have better ideas that is not as complex
|
||||
// as the conversion tactics in the runtime Metadata)
|
||||
function getLatestMeta (registry: Registry, json: Record<string, unknown>): ContractMetadataLatest {
|
||||
const metadata = registry.createType('ContractMetadata',
|
||||
isObject(json.V2)
|
||||
? { V2: json.V2 }
|
||||
: isObject(json.V1)
|
||||
? { V1: json.V1 }
|
||||
: { V0: json }
|
||||
);
|
||||
|
||||
return metadata.isV2
|
||||
? metadata.asV2
|
||||
: metadata.isV1
|
||||
? v1ToLatest(registry, metadata.asV1)
|
||||
: v0ToLatest(registry, metadata.asV0);
|
||||
}
|
||||
|
||||
function parseJson (json: Record<string, unknown>, chainProperties?: ChainProperties): [Record<string, unknown>, Registry, ContractMetadataLatest, ContractProjectInfo] {
|
||||
const registry = new TypeRegistry();
|
||||
const info = registry.createType('ContractProjectInfo', json);
|
||||
const metadata = registry.createType('ContractMetadata', isString((json as unknown as V0AbiJson).metadataVersion)
|
||||
? { V0: json }
|
||||
: { V1: (json as Record<string, AnyJson>).V1 }
|
||||
);
|
||||
const latest = metadata.isV0
|
||||
? toLatest(registry, metadata.asV0)
|
||||
: metadata.asV1;
|
||||
const latest = getLatestMeta(registry, json);
|
||||
const lookup = registry.createType<PortableRegistry>('PortableRegistry', { types: latest.types });
|
||||
|
||||
// attach the lookup to the registry - now the types are known
|
||||
@@ -69,7 +72,7 @@ export class Abi {
|
||||
|
||||
public readonly info: ContractProjectInfo;
|
||||
|
||||
public readonly json: AnyJson;
|
||||
public readonly json: Record<string, unknown>;
|
||||
|
||||
public readonly messages: AbiMessage[];
|
||||
|
||||
@@ -77,22 +80,22 @@ export class Abi {
|
||||
|
||||
public readonly registry: Registry;
|
||||
|
||||
constructor (abiJson: AnyJson, chainProperties?: ChainProperties) {
|
||||
constructor (abiJson: Record<string, unknown> | string, chainProperties?: ChainProperties) {
|
||||
[this.json, this.registry, this.metadata, this.info] = parseJson(
|
||||
isString(abiJson)
|
||||
? JSON.parse(abiJson) as AnyJson
|
||||
? JSON.parse(abiJson) as Record<string, unknown>
|
||||
: abiJson,
|
||||
chainProperties
|
||||
);
|
||||
this.constructors = this.metadata.spec.constructors.map((spec: ContractConstructorSpec, index) =>
|
||||
this.constructors = this.metadata.spec.constructors.map((spec: ContractConstructorSpecLatest, index) =>
|
||||
this.#createMessage(spec, index, {
|
||||
isConstructor: true
|
||||
})
|
||||
);
|
||||
this.events = this.metadata.spec.events.map((spec: ContractEventSpec, index) =>
|
||||
this.events = this.metadata.spec.events.map((spec: ContractEventSpecLatest, index) =>
|
||||
this.#createEvent(spec, index)
|
||||
);
|
||||
this.messages = this.metadata.spec.messages.map((spec: ContractMessageSpec, index): AbiMessage => {
|
||||
this.messages = this.metadata.spec.messages.map((spec: ContractMessageSpecLatest, index): AbiMessage => {
|
||||
const typeSpec = spec.returnType.unwrapOr(null);
|
||||
|
||||
return this.#createMessage(spec, index, {
|
||||
@@ -139,15 +142,15 @@ export class Abi {
|
||||
return findMessage(this.messages, messageOrId);
|
||||
}
|
||||
|
||||
#createArgs = (args: ContractMessageParamSpec[], spec: unknown): AbiParam[] => {
|
||||
return args.map(({ name, type }, index): AbiParam => {
|
||||
#createArgs = (args: ContractMessageParamSpecLatest[], spec: unknown): AbiParam[] => {
|
||||
return args.map(({ label, type }, index): AbiParam => {
|
||||
try {
|
||||
assert(isObject(type), 'Invalid type definition found');
|
||||
|
||||
const displayName = type.displayName.length
|
||||
? type.displayName[type.displayName.length - 1].toString()
|
||||
: undefined;
|
||||
const camelName = stringCamelCase(name);
|
||||
const camelName = stringCamelCase(label);
|
||||
|
||||
if (displayName && PRIMITIVE_ALWAYS.includes(displayName)) {
|
||||
return {
|
||||
@@ -175,7 +178,7 @@ export class Abi {
|
||||
});
|
||||
};
|
||||
|
||||
#createEvent = (spec: ContractEventSpec, index: number): AbiEvent => {
|
||||
#createEvent = (spec: ContractEventSpecLatest, index: number): AbiEvent => {
|
||||
const args = this.#createArgs(spec.args, spec);
|
||||
const event = {
|
||||
args,
|
||||
@@ -184,16 +187,16 @@ export class Abi {
|
||||
args: this.#decodeArgs(args, data),
|
||||
event
|
||||
}),
|
||||
identifier: spec.name.toString(),
|
||||
identifier: spec.label.toString(),
|
||||
index
|
||||
};
|
||||
|
||||
return event;
|
||||
};
|
||||
|
||||
#createMessage = (spec: ContractMessageSpec | ContractConstructorSpec, index: number, add: Partial<AbiMessage> = {}): AbiMessage => {
|
||||
#createMessage = (spec: ContractMessageSpecLatest | ContractConstructorSpecLatest, index: number, add: Partial<AbiMessage> = {}): AbiMessage => {
|
||||
const args = this.#createArgs(spec.args, spec);
|
||||
const identifier = spec.name.toString();
|
||||
const identifier = spec.label.toString();
|
||||
const message = {
|
||||
...add,
|
||||
args,
|
||||
@@ -237,8 +240,8 @@ export class Abi {
|
||||
return message.fromU8a(trimmed.subarray(4));
|
||||
};
|
||||
|
||||
#encodeArgs = ({ name, selector }: ContractMessageSpec | ContractConstructorSpec, args: AbiParam[], data: unknown[]): Uint8Array => {
|
||||
assert(data.length === args.length, () => `Expected ${args.length} arguments to contract message '${name.toString()}', found ${data.length}`);
|
||||
#encodeArgs = ({ label, selector }: ContractMessageSpecLatest | ContractConstructorSpecLatest, args: AbiParam[], data: unknown[]): Uint8Array => {
|
||||
assert(data.length === args.length, () => `Expected ${args.length} arguments to contract message '${label.toString()}', found ${data.length}`);
|
||||
|
||||
return compactAddLength(
|
||||
u8aConcat(
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '@polkadot/types';
|
||||
|
||||
import abis from '../../test/contracts';
|
||||
import { v0ToLatest, v1ToLatest } from './toLatest';
|
||||
|
||||
describe('v0ToLatest', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
const contract = registry.createType('ContractMetadata', { V0: abis.ink_v0_erc20 });
|
||||
const latest = v0ToLatest(registry, contract.asV0);
|
||||
|
||||
it('has the correct constructors', (): void => {
|
||||
expect(
|
||||
latest.spec.constructors.map(({ label }) => label.toString())
|
||||
).toEqual(['new']);
|
||||
});
|
||||
|
||||
it('has the correct messages', (): void => {
|
||||
expect(
|
||||
latest.spec.messages.map(({ label }) => label.toString())
|
||||
).toEqual(['total_supply', 'balance_of', 'allowance', 'transfer', 'approve', 'transfer_from']);
|
||||
});
|
||||
|
||||
it('has the correct events', (): void => {
|
||||
expect(
|
||||
latest.spec.events.map(({ label }) => label.toString())
|
||||
).toEqual(['Transfer', 'Approval']);
|
||||
});
|
||||
|
||||
it('has the correct constructor arguments', (): void => {
|
||||
expect(
|
||||
latest.spec.constructors[0].args.map(({ label }) => label.toString())
|
||||
).toEqual(['initial_supply']);
|
||||
});
|
||||
|
||||
it('has the correct message arguments', (): void => {
|
||||
expect(
|
||||
latest.spec.messages[1].args.map(({ label }) => label.toString())
|
||||
).toEqual(['owner']);
|
||||
});
|
||||
|
||||
it('has the correct event arguments', (): void => {
|
||||
expect(
|
||||
latest.spec.events[0].args.map(({ label }) => label.toString())
|
||||
).toEqual(['from', 'to', 'value']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('v1ToLatest', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
const contract = registry.createType('ContractMetadata', { V1: abis.ink_v1_flipper.V1 });
|
||||
const latest = v1ToLatest(registry, contract.asV1);
|
||||
|
||||
it('has the correct constructors', (): void => {
|
||||
expect(
|
||||
latest.spec.constructors.map(({ label }) => label.toString())
|
||||
).toEqual(['new', 'default']);
|
||||
});
|
||||
|
||||
it('has the correct messages', (): void => {
|
||||
expect(
|
||||
latest.spec.messages.map(({ label }) => label.toString())
|
||||
).toEqual(['flip', 'get']);
|
||||
});
|
||||
|
||||
it('has the correct constructor arguments', (): void => {
|
||||
expect(
|
||||
latest.spec.constructors[0].args.map(({ label }) => label.toString())
|
||||
).toEqual(['init_value']);
|
||||
});
|
||||
});
|
||||
@@ -1,14 +1,16 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ContractMetadataLatest, ContractMetadataV0 } from '@polkadot/types/interfaces';
|
||||
import type { ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1 } from '@polkadot/types/interfaces';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { convertSiV0toV1 } from '@polkadot/types';
|
||||
import { v0ToV1 } from './toV1';
|
||||
import { v1ToV2 } from './toV2';
|
||||
|
||||
export function toLatest (registry: Registry, v0: ContractMetadataV0): ContractMetadataLatest {
|
||||
return registry.createType('ContractMetadataLatest', {
|
||||
...v0,
|
||||
types: convertSiV0toV1(registry, v0.types)
|
||||
});
|
||||
export function v1ToLatest (registry: Registry, v1: ContractMetadataV1): ContractMetadataLatest {
|
||||
return v1ToV2(registry, v1);
|
||||
}
|
||||
|
||||
export function v0ToLatest (registry: Registry, v0: ContractMetadataV0): ContractMetadataLatest {
|
||||
return v1ToLatest(registry, v0ToV1(registry, v0));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ContractMetadataV0, ContractMetadataV1 } from '@polkadot/types/interfaces';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { convertSiV0toV1 } from '@polkadot/types';
|
||||
import { objectSpread } from '@polkadot/util';
|
||||
|
||||
export function v0ToV1 (registry: Registry, v0: ContractMetadataV0): ContractMetadataV1 {
|
||||
return registry.createType('ContractMetadataV1', objectSpread({}, v0, {
|
||||
types: convertSiV0toV1(registry, v0.types)
|
||||
}));
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Text } from '@polkadot/types';
|
||||
import type { ContractMetadataV1, ContractMetadataV2 } from '@polkadot/types/interfaces';
|
||||
import type { InterfaceTypes, Registry } from '@polkadot/types/types';
|
||||
|
||||
import { objectSpread } from '@polkadot/util';
|
||||
|
||||
type WithArgs = keyof typeof ARG_TYPES;
|
||||
|
||||
interface NamedEntry {
|
||||
name: Text | Text[];
|
||||
}
|
||||
|
||||
interface ArgsEntry <T extends WithArgs> extends NamedEntry {
|
||||
args: InterfaceTypes[`${T}V0`]['args'][0][];
|
||||
}
|
||||
|
||||
const ARG_TYPES = {
|
||||
ContractConstructorSpec: 'ContractMessageParamSpecV2',
|
||||
ContractEventSpec: 'ContractEventParamSpecV2',
|
||||
ContractMessageSpec: 'ContractMessageParamSpecV2'
|
||||
};
|
||||
|
||||
function v1ToV2Label (entry: NamedEntry): { label: Text } {
|
||||
return objectSpread({}, entry, {
|
||||
label: Array.isArray(entry.name)
|
||||
? entry.name[0]
|
||||
: entry.name
|
||||
});
|
||||
}
|
||||
|
||||
function v1ToV2Labels <T extends WithArgs> (registry: Registry, outType: T, all: ArgsEntry<T>[]): unknown[] {
|
||||
return all.map((e) =>
|
||||
registry.createType(`${outType}V2`, objectSpread(v1ToV2Label(e), {
|
||||
args: e.args.map((a) =>
|
||||
registry.createType(ARG_TYPES[outType], v1ToV2Label(a))
|
||||
)
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
export function v1ToV2 (registry: Registry, v1: ContractMetadataV1): ContractMetadataV2 {
|
||||
return registry.createType('ContractMetadataV2', objectSpread({}, v1, {
|
||||
spec: objectSpread({}, v1.spec, {
|
||||
constructors: v1ToV2Labels(registry, 'ContractConstructorSpec', v1.spec.constructors),
|
||||
events: v1ToV2Labels(registry, 'ContractEventSpec', v1.spec.events),
|
||||
messages: v1ToV2Labels(registry, 'ContractMessageSpec', v1.spec.messages)
|
||||
})
|
||||
}));
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import type { AnyJson, Registry } from '@polkadot/types/types';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { ApiBase } from '@polkadot/api/base';
|
||||
import { assert, isFunction } from '@polkadot/util';
|
||||
@@ -16,7 +16,7 @@ export abstract class Base<ApiType extends ApiTypes> {
|
||||
|
||||
protected readonly _decorateMethod: DecorateMethod<ApiType>;
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, decorateMethod: DecorateMethod<ApiType>) {
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, decorateMethod: DecorateMethod<ApiType>) {
|
||||
this.abi = abi instanceof Abi
|
||||
? abi
|
||||
: new Abi(abi, api.registry.getChainProperties());
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
|
||||
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import type { AccountId, EventRecord, Hash } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson, ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { AbiConstructor, BlueprintOptions } from '../types';
|
||||
import type { MapConstructorExec } from './types';
|
||||
|
||||
@@ -18,6 +18,10 @@ import { Base } from './Base';
|
||||
import { Contract } from './Contract';
|
||||
import { createBluePrintTx, encodeSalt } from './util';
|
||||
|
||||
export interface BlueprintConstructor<ApiType extends ApiTypes> {
|
||||
new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array): Blueprint<ApiType>;
|
||||
}
|
||||
|
||||
export class BlueprintSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
|
||||
public readonly contract?: Contract<ApiType>;
|
||||
|
||||
@@ -36,7 +40,7 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
|
||||
readonly #tx: MapConstructorExec<ApiType> = {};
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, codeHash: string | Hash | Uint8Array, decorateMethod: DecorateMethod<ApiType>) {
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array, decorateMethod: DecorateMethod<ApiType>) {
|
||||
super(api, abi, decorateMethod);
|
||||
|
||||
this.codeHash = this.registry.createType('Hash', codeHash);
|
||||
@@ -68,3 +72,13 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function extendBlueprint <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): BlueprintConstructor<ApiType> {
|
||||
return class extends Blueprint<ApiType> {
|
||||
static __BlueprintType = type;
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array) {
|
||||
super(api, abi, codeHash, decorateMethod);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
@@ -19,19 +17,19 @@ const v0wasmFlipper = fs.readFileSync(path.join(__dirname, '../../test/contracts
|
||||
describe('Code', (): void => {
|
||||
it('can construct with an individual ABI/WASM combo', (): void => {
|
||||
expect(
|
||||
() => new Code(mockApi, v0abiFlipper as AnyJson, v0wasmFlipper, toPromiseMethod)
|
||||
() => new Code(mockApi, v0abiFlipper as Record<string, unknown>, v0wasmFlipper, toPromiseMethod)
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('can construct with an .contract ABI (v0)', (): void => {
|
||||
expect(
|
||||
() => new Code(mockApi, v0contractFlipper as AnyJson, null, toPromiseMethod)
|
||||
() => new Code(mockApi, v0contractFlipper as Record<string, unknown>, null, toPromiseMethod)
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it.only('can construct with an .contract ABI (v1)', (): void => {
|
||||
expect(
|
||||
() => new Code(mockApi, v1contractFlipper as AnyJson, null, toPromiseMethod)
|
||||
() => new Code(mockApi, v1contractFlipper as Record<string, unknown>, null, toPromiseMethod)
|
||||
).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
|
||||
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import type { EventRecord } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson, ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { AbiConstructor, BlueprintOptions } from '../types';
|
||||
import type { MapConstructorExec } from './types';
|
||||
|
||||
@@ -19,6 +19,10 @@ import { Blueprint } from './Blueprint';
|
||||
import { Contract } from './Contract';
|
||||
import { createBluePrintTx, encodeSalt } from './util';
|
||||
|
||||
export interface CodeConstructor<ApiType extends ApiTypes> {
|
||||
new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined): Code<ApiType>;
|
||||
}
|
||||
|
||||
export class CodeSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
|
||||
public readonly blueprint?: Blueprint<ApiType>;
|
||||
public readonly contract?: Contract<ApiType>;
|
||||
@@ -36,7 +40,7 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
|
||||
readonly #tx: MapConstructorExec<ApiType> = {};
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer | null | undefined, decorateMethod: DecorateMethod<ApiType>) {
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined, decorateMethod: DecorateMethod<ApiType>) {
|
||||
super(api, abi, decorateMethod);
|
||||
|
||||
this.code = isWasm(this.abi.info.source.wasm)
|
||||
@@ -78,3 +82,13 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function extendCode <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): CodeConstructor<ApiType> {
|
||||
return class extends Code<ApiType> {
|
||||
static __CodeType = type;
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
|
||||
super(api, abi, wasm, decorateMethod);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
|
||||
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import type { Bytes } from '@polkadot/types';
|
||||
import type { AccountId, EventRecord, Weight } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson, ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { AbiMessage, ContractCallOutcome, ContractOptions, DecodedEvent } from '../types';
|
||||
import type { ContractCallResult, ContractCallSend, ContractQuery, ContractTx, MapMessageQuery, MapMessageTx } from './types';
|
||||
|
||||
@@ -19,6 +19,10 @@ import { Abi } from '../Abi';
|
||||
import { applyOnEvent, extractOptions, isOptions } from '../util';
|
||||
import { Base } from './Base';
|
||||
|
||||
export interface ContractConstructor<ApiType extends ApiTypes> {
|
||||
new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId): Contract<ApiType>;
|
||||
}
|
||||
|
||||
// As per Rust, 5 * GAS_PER_SEC
|
||||
const MAX_CALL_GAS = new BN(5_000_000_000_000).isub(BN_ONE);
|
||||
const ERROR_NO_CALL = 'Your node does not expose the contracts.call RPC. This is most probably due to a runtime configuration.';
|
||||
@@ -59,7 +63,7 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
|
||||
readonly #tx: MapMessageTx<ApiType> = {};
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, address: string | AccountId, decorateMethod: DecorateMethod<ApiType>) {
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId, decorateMethod: DecorateMethod<ApiType>) {
|
||||
super(api, abi, decorateMethod);
|
||||
|
||||
this.address = this.registry.createType('AccountId', address);
|
||||
@@ -161,3 +165,13 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function extendContract <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): ContractConstructor<ApiType> {
|
||||
return class extends Contract<ApiType> {
|
||||
static __ContractType = type;
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId) {
|
||||
super(api, abi, address, decorateMethod);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { Blueprint, BlueprintSubmittableResult } from './Blueprint';
|
||||
export { Code, CodeSubmittableResult } from './Code';
|
||||
export { Contract } from './Contract';
|
||||
export { Blueprint, BlueprintSubmittableResult, extendBlueprint } from './Blueprint';
|
||||
export { Code, CodeSubmittableResult, extendCode } from './Code';
|
||||
export { Contract, extendContract } from './Contract';
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
// Simple non-runnable checks to test type definitions in the editor itself
|
||||
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { createTestPairs, TestKeyringMap } from '@polkadot/keyring/testingPairs';
|
||||
|
||||
@@ -12,7 +10,7 @@ import abiIncrementer from '../test/contracts/ink/incrementer.json';
|
||||
import { BlueprintPromise, ContractPromise } from '.';
|
||||
|
||||
async function checkBlueprint (api: ApiPromise, pairs: TestKeyringMap): Promise<void> {
|
||||
const blueprint = new BlueprintPromise(api, abiIncrementer as AnyJson, '0x1234');
|
||||
const blueprint = new BlueprintPromise(api, abiIncrementer as Record<string, unknown>, '0x1234');
|
||||
|
||||
// new style
|
||||
await blueprint.tx.new({ gasLimit: 456, salt: '0x1234', value: 123 }, 42).signAndSend(pairs.bob);
|
||||
@@ -23,7 +21,7 @@ async function checkBlueprint (api: ApiPromise, pairs: TestKeyringMap): Promise<
|
||||
}
|
||||
|
||||
async function checkContract (api: ApiPromise, pairs: TestKeyringMap): Promise<void> {
|
||||
const contract = new ContractPromise(api, abiIncrementer as AnyJson, '0x1234');
|
||||
const contract = new ContractPromise(api, abiIncrementer as Record<string, unknown>, '0x1234');
|
||||
|
||||
// queries
|
||||
await contract.query.get(pairs.alice.address, {});
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Hash } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { ApiPromise, toPromiseMethod } from '@polkadot/api';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { Blueprint as BaseBlueprint } from '../base';
|
||||
|
||||
export class Blueprint extends BaseBlueprint<'promise'> {
|
||||
constructor (api: ApiPromise, abi: AnyJson | Abi, codeHash: string | Hash) {
|
||||
super(api, abi, codeHash, toPromiseMethod);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiPromise } from '@polkadot/api';
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { toPromiseMethod } from '@polkadot/api';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { Code as BaseCode } from '../base';
|
||||
|
||||
export class Code extends BaseCode<'promise'> {
|
||||
constructor (api: ApiPromise, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
|
||||
super(api, abi, wasm, toPromiseMethod);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { ApiPromise, toPromiseMethod } from '@polkadot/api';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { Contract as BaseContract } from '../base';
|
||||
|
||||
export class Contract extends BaseContract<'promise'> {
|
||||
constructor (api: ApiPromise, abi: AnyJson | Abi, address: string | AccountId) {
|
||||
super(api, abi, address, toPromiseMethod);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { Blueprint } from './Blueprint';
|
||||
export { Code } from './Code';
|
||||
export { Contract } from './Contract';
|
||||
import { toPromiseMethod } from '@polkadot/api';
|
||||
|
||||
import { extendBlueprint, extendCode, extendContract } from '../base';
|
||||
|
||||
export const Blueprint = extendBlueprint<'promise'>('promise', toPromiseMethod);
|
||||
export const Code = extendCode<'promise'>('promise', toPromiseMethod);
|
||||
export const Contract = extendContract<'promise'>('promise', toPromiseMethod);
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Hash } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { ApiRx, toRxMethod } from '@polkadot/api';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { Blueprint as BaseBlueprint } from '../base';
|
||||
|
||||
export class Blueprint extends BaseBlueprint<'rxjs'> {
|
||||
constructor (api: ApiRx, abi: AnyJson | Abi, codeHash: string | Hash) {
|
||||
super(api, abi, codeHash, toRxMethod);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiRx } from '@polkadot/api';
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { toRxMethod } from '@polkadot/api';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { Code as BaseCode } from '../base';
|
||||
|
||||
export class Code extends BaseCode<'rxjs'> {
|
||||
constructor (api: ApiRx, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
|
||||
super(api, abi, wasm, toRxMethod);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { ApiRx, toRxMethod } from '@polkadot/api';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { Contract as BaseContract } from '../base';
|
||||
|
||||
export class Contract extends BaseContract<'rxjs'> {
|
||||
constructor (api: ApiRx, abi: AnyJson | Abi, address: string | AccountId) {
|
||||
super(api, abi, address, toRxMethod);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { Blueprint } from './Blueprint';
|
||||
export { Code } from './Code';
|
||||
export { Contract } from './Contract';
|
||||
import { toRxMethod } from '@polkadot/api';
|
||||
|
||||
import { extendBlueprint, extendCode, extendContract } from '../base';
|
||||
|
||||
export const Blueprint = extendBlueprint<'rxjs'>('rxjs', toRxMethod);
|
||||
export const Code = extendCode<'rxjs'>('rxjs', toRxMethod);
|
||||
export const Contract = extendContract<'rxjs'>('rxjs', toRxMethod);
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
[
|
||||
{
|
||||
"info": "Plain",
|
||||
"lookupIndex": 0,
|
||||
"type": "u128",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
{
|
||||
"info": "Struct",
|
||||
"lookupIndex": 1,
|
||||
"type": "{\"offsetKey\":\"InkPrimitivesKey\"}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::lazy::mapping::Mapping",
|
||||
"sub": [
|
||||
{
|
||||
"info": "VecFixed",
|
||||
"lookupIndex": 5,
|
||||
"lookupName": "InkPrimitivesKey",
|
||||
"type": "[u8;32]",
|
||||
"docs": [],
|
||||
"namespace": "",
|
||||
"length": 32,
|
||||
"sub": {
|
||||
"info": "Plain",
|
||||
"lookupIndex": 4,
|
||||
"type": "u8",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
"typeName": "Key",
|
||||
"name": "offsetKey"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"info": "Plain",
|
||||
"lookupIndex": 2,
|
||||
"type": "AccountId",
|
||||
"docs": [],
|
||||
"namespace": "ink_env::types::AccountId",
|
||||
"lookupNameRoot": "InkEnvAccountId"
|
||||
},
|
||||
{
|
||||
"info": "VecFixed",
|
||||
"lookupIndex": 3,
|
||||
"type": "[u8;32]",
|
||||
"docs": [],
|
||||
"namespace": "",
|
||||
"length": 32,
|
||||
"sub": {
|
||||
"info": "Plain",
|
||||
"lookupIndex": 4,
|
||||
"type": "u8",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"info": "Plain",
|
||||
"lookupIndex": 4,
|
||||
"type": "u8",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
{
|
||||
"info": "VecFixed",
|
||||
"lookupIndex": 5,
|
||||
"lookupName": "InkPrimitivesKey",
|
||||
"type": "[u8;32]",
|
||||
"docs": [],
|
||||
"namespace": "",
|
||||
"length": 32,
|
||||
"sub": {
|
||||
"info": "Plain",
|
||||
"lookupIndex": 4,
|
||||
"type": "u8",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
"typeName": "[u8;32]"
|
||||
},
|
||||
{
|
||||
"info": "Struct",
|
||||
"lookupIndex": 6,
|
||||
"type": "{\"offsetKey\":\"InkPrimitivesKey\"}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::lazy::mapping::Mapping",
|
||||
"sub": [
|
||||
{
|
||||
"info": "VecFixed",
|
||||
"lookupIndex": 5,
|
||||
"lookupName": "InkPrimitivesKey",
|
||||
"type": "[u8;32]",
|
||||
"docs": [],
|
||||
"namespace": "",
|
||||
"length": 32,
|
||||
"sub": {
|
||||
"info": "Plain",
|
||||
"lookupIndex": 4,
|
||||
"type": "u8",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
"typeName": "Key",
|
||||
"name": "offsetKey"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"info": "Tuple",
|
||||
"lookupIndex": 7,
|
||||
"type": "(AccountId,AccountId)",
|
||||
"docs": [],
|
||||
"namespace": "",
|
||||
"sub": [
|
||||
{
|
||||
"info": "Plain",
|
||||
"lookupIndex": 2,
|
||||
"type": "AccountId",
|
||||
"docs": [],
|
||||
"namespace": "ink_env::types::AccountId",
|
||||
"lookupNameRoot": "InkEnvAccountId"
|
||||
},
|
||||
{
|
||||
"info": "Plain",
|
||||
"lookupIndex": 2,
|
||||
"type": "AccountId",
|
||||
"docs": [],
|
||||
"namespace": "ink_env::types::AccountId",
|
||||
"lookupNameRoot": "InkEnvAccountId"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"info": "Result",
|
||||
"lookupIndex": 8,
|
||||
"type": "Result<Null, Erc20Error>",
|
||||
"docs": [],
|
||||
"namespace": "Result",
|
||||
"sub": [
|
||||
{
|
||||
"name": "Ok",
|
||||
"info": "Null",
|
||||
"lookupIndex": 9,
|
||||
"type": "Null",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
{
|
||||
"name": "Error",
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 10,
|
||||
"lookupName": "Erc20Error",
|
||||
"type": "Lookup10"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"info": "Null",
|
||||
"lookupIndex": 9,
|
||||
"type": "Null",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 10,
|
||||
"lookupName": "Erc20Error",
|
||||
"type": "{\"_enum\":[\"InsufficientBalance\",\"InsufficientAllowance\"]}",
|
||||
"docs": [],
|
||||
"namespace": "erc20::erc20::Error",
|
||||
"sub": [
|
||||
{
|
||||
"info": "Null",
|
||||
"type": "Null",
|
||||
"index": 0,
|
||||
"name": "InsufficientBalance"
|
||||
},
|
||||
{
|
||||
"info": "Null",
|
||||
"type": "Null",
|
||||
"index": 1,
|
||||
"name": "InsufficientAllowance"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"info": "Option",
|
||||
"lookupIndex": 11,
|
||||
"type": "Option<AccountId>",
|
||||
"docs": [],
|
||||
"namespace": "Option",
|
||||
"sub": {
|
||||
"info": "Plain",
|
||||
"lookupIndex": 2,
|
||||
"type": "AccountId",
|
||||
"docs": [],
|
||||
"namespace": "ink_env::types::AccountId",
|
||||
"lookupNameRoot": "InkEnvAccountId"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,9 @@
|
||||
[
|
||||
{
|
||||
"info": "Plain",
|
||||
"lookupIndex": 0,
|
||||
"type": "bool",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
}
|
||||
]
|
||||
@@ -5,17 +5,12 @@ import ink from './ink';
|
||||
import solang from './solang';
|
||||
import user from './user';
|
||||
|
||||
const all: Record<string, any> = {};
|
||||
const all: Record<string, Record<string, unknown>> = {};
|
||||
|
||||
function addExport (type: string, abis: Record<string, any>): void {
|
||||
Object.keys(abis).forEach((key): void => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
all[`${type}_${key}`] = abis[key];
|
||||
});
|
||||
}
|
||||
|
||||
addExport('ink', ink);
|
||||
addExport('solang', solang);
|
||||
addExport('user', user);
|
||||
Object.entries({ ink, solang, user }).forEach(([type, abis]) =>
|
||||
Object.entries(abis).forEach(([name, abi]): void => {
|
||||
all[`${type}_${name}`] = abi;
|
||||
})
|
||||
);
|
||||
|
||||
export default all;
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import { createVersionedExport } from '../util';
|
||||
import * as v0 from './v0';
|
||||
import * as v1 from './v1';
|
||||
import * as v2 from './v2';
|
||||
|
||||
const exp = createVersionedExport('v0', v0, {});
|
||||
|
||||
export default createVersionedExport('v1', v1, exp);
|
||||
export default createVersionedExport({ v0, v1, v2 });
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,5 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as erc20 } from './erc20.contract.json';
|
||||
export { default as flipper } from './flipper.contract.json';
|
||||
@@ -4,4 +4,4 @@
|
||||
import { createVersionedExport } from '../util';
|
||||
import * as v0 from './v0';
|
||||
|
||||
export default createVersionedExport('v0', v0, {});
|
||||
export default createVersionedExport({ v0 });
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
import { createVersionedExport } from '../util';
|
||||
import * as v0 from './v0';
|
||||
|
||||
export default createVersionedExport('v0', v0, {});
|
||||
export default createVersionedExport({ v0 });
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export function createVersionedExport (version: string, orig: Record<string, unknown>, exp: Record<string, unknown>): Record<string, unknown> {
|
||||
Object.entries(orig).forEach(([name, json]): void => {
|
||||
exp[`${version}_${name}`] = json;
|
||||
});
|
||||
export function createVersionedExport (versioned: Record<string, Record<string, unknown>>): Record<string, Record<string, unknown>> {
|
||||
const result: Record<string, Record<string, unknown>> = {};
|
||||
|
||||
return exp;
|
||||
Object.entries(versioned).forEach(([version, contracts]) =>
|
||||
Object.entries(contracts).forEach(([name, contract]): void => {
|
||||
result[`${version}_${name}`] = contract as Record<string, unknown>;
|
||||
})
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ export { knownOrigins } from './knownOrigins';
|
||||
export { packageInfo } from './packageInfo';
|
||||
export { mapXcmTypes } from './xcm';
|
||||
|
||||
function withNames <T> (chainName: Text | string, specName: Text | string, fn: (c: string, s: string) => T): T {
|
||||
return fn(chainName.toString(), specName.toString());
|
||||
}
|
||||
|
||||
// flatten a VersionedType[] into a Record<string, string>
|
||||
/** @internal */
|
||||
function filterVersions (versions: OverrideVersionedType[] = [], specVersion: number): RegistryTypes {
|
||||
@@ -35,19 +39,21 @@ function filterVersions (versions: OverrideVersionedType[] = [], specVersion: nu
|
||||
* @description Get types for specific modules (metadata override)
|
||||
*/
|
||||
export function getModuleTypes ({ knownTypes }: Registry, section: string): OverrideModuleType {
|
||||
return objectSpread({}, typesModules[section], knownTypes.typesAlias?.[section]);
|
||||
return objectSpread({},
|
||||
typesModules[section],
|
||||
knownTypes.typesAlias?.[section]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Based on the chain and runtimeVersion, get the applicable signed extensions (ready for registration)
|
||||
*/
|
||||
export function getSpecExtensions ({ knownTypes }: Registry, chainName: Text | string, specName: Text | string): ExtDef {
|
||||
const _chainName = chainName.toString();
|
||||
const _specName = specName.toString();
|
||||
|
||||
return objectSpread({},
|
||||
knownTypes.typesBundle?.spec?.[_specName]?.signedExtensions,
|
||||
knownTypes.typesBundle?.chain?.[_chainName]?.signedExtensions
|
||||
return withNames(chainName, specName, (c, s) =>
|
||||
objectSpread({},
|
||||
knownTypes.typesBundle?.spec?.[s]?.signedExtensions,
|
||||
knownTypes.typesBundle?.chain?.[c]?.signedExtensions
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -55,42 +61,43 @@ export function getSpecExtensions ({ knownTypes }: Registry, chainName: Text | s
|
||||
* @description Based on the chain and runtimeVersion, get the applicable types (ready for registration)
|
||||
*/
|
||||
export function getSpecTypes ({ knownTypes }: Registry, chainName: Text | string, specName: Text | string, specVersion: bigint | BN | number): RegistryTypes {
|
||||
const _chainName = chainName.toString();
|
||||
const _specName = specName.toString();
|
||||
const _specVersion = bnToBn(specVersion).toNumber();
|
||||
|
||||
// The order here is always, based on -
|
||||
// - spec then chain
|
||||
// - typesBundle takes higher precedence
|
||||
// - types is the final catch-all override
|
||||
return objectSpread({},
|
||||
filterVersions(typesSpec[_specName], _specVersion),
|
||||
filterVersions(typesChain[_chainName], _specVersion),
|
||||
filterVersions(knownTypes.typesBundle?.spec?.[_specName]?.types, _specVersion),
|
||||
filterVersions(knownTypes.typesBundle?.chain?.[_chainName]?.types, _specVersion),
|
||||
knownTypes.typesSpec?.[_specName],
|
||||
knownTypes.typesChain?.[_chainName],
|
||||
knownTypes.types
|
||||
return withNames(chainName, specName, (c, s) =>
|
||||
// The order here is always, based on -
|
||||
// - spec then chain
|
||||
// - typesBundle takes higher precedence
|
||||
// - types is the final catch-all override
|
||||
objectSpread({},
|
||||
filterVersions(typesSpec[s], _specVersion),
|
||||
filterVersions(typesChain[c], _specVersion),
|
||||
filterVersions(knownTypes.typesBundle?.spec?.[s]?.types, _specVersion),
|
||||
filterVersions(knownTypes.typesBundle?.chain?.[c]?.types, _specVersion),
|
||||
knownTypes.typesSpec?.[s],
|
||||
knownTypes.typesChain?.[c],
|
||||
knownTypes.types
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function getSpecHasher ({ knownTypes }: Registry, chainName: Text | string, specName: Text | string): CodecHasher | null {
|
||||
const _chainName = chainName.toString();
|
||||
const _specName = specName.toString();
|
||||
|
||||
return knownTypes.hasher || knownTypes.typesBundle?.chain?.[_chainName]?.hasher || knownTypes.typesBundle?.spec?.[_specName]?.hasher || null;
|
||||
return withNames(chainName, specName, (c, s) =>
|
||||
knownTypes.hasher ||
|
||||
knownTypes.typesBundle?.chain?.[c]?.hasher ||
|
||||
knownTypes.typesBundle?.spec?.[s]?.hasher ||
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Based on the chain and runtimeVersion, get the applicable rpc definitions (ready for registration)
|
||||
*/
|
||||
export function getSpecRpc ({ knownTypes }: Registry, chainName: Text | string, specName: Text | string): Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>> {
|
||||
const _chainName = chainName.toString();
|
||||
const _specName = specName.toString();
|
||||
|
||||
return objectSpread({},
|
||||
knownTypes.typesBundle?.spec?.[_specName]?.rpc,
|
||||
knownTypes.typesBundle?.chain?.[_chainName]?.rpc
|
||||
return withNames(chainName, specName, (c, s) =>
|
||||
objectSpread({},
|
||||
knownTypes.typesBundle?.spec?.[s]?.rpc,
|
||||
knownTypes.typesBundle?.chain?.[c]?.rpc
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -98,14 +105,13 @@ export function getSpecRpc ({ knownTypes }: Registry, chainName: Text | string,
|
||||
* @description Based on the chain and runtimeVersion, get the applicable alias definitions (ready for registration)
|
||||
*/
|
||||
export function getSpecAlias ({ knownTypes }: Registry, chainName: Text | string, specName: Text | string): Record<string, OverrideModuleType> {
|
||||
const _chainName = chainName.toString();
|
||||
const _specName = specName.toString();
|
||||
|
||||
// as per versions, first spec, then chain then finally non-versioned
|
||||
return objectSpread({},
|
||||
knownTypes.typesBundle?.spec?.[_specName]?.alias,
|
||||
knownTypes.typesBundle?.chain?.[_chainName]?.alias,
|
||||
knownTypes.typesAlias
|
||||
return withNames(chainName, specName, (c, s) =>
|
||||
// as per versions, first spec, then chain then finally non-versioned
|
||||
objectSpread({},
|
||||
knownTypes.typesBundle?.spec?.[s]?.alias,
|
||||
knownTypes.typesBundle?.chain?.[c]?.alias,
|
||||
knownTypes.typesAlias
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
import type { CollectiveOrigin, MemberCount, ProposalIndex, Votes, VotesTo230 } from '@polkadot/types/interfaces/collective';
|
||||
import type { AuthorityId, RawVRFOutput } from '@polkadot/types/interfaces/consensus';
|
||||
import type { AliveContractInfo, CodeHash, ContractCallRequest, ContractExecResult, ContractExecResultErr, ContractExecResultErrModule, ContractExecResultOk, ContractExecResultResult, ContractExecResultSuccessTo255, ContractExecResultSuccessTo260, ContractExecResultTo255, ContractExecResultTo260, ContractExecResultTo267, ContractInfo, ContractInstantiateResult, ContractInstantiateResultTo267, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateReturnValue, InstantiateReturnValueTo267, InstructionWeights, Limits, LimitsTo264, PrefabWasmModule, RentProjection, Schedule, ScheduleTo212, ScheduleTo258, ScheduleTo264, SeedOf, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts';
|
||||
import type { ContractConstructorSpec, ContractContractSpec, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEventParamSpec, ContractEventSpec, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpec, ContractMessageSpec, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi';
|
||||
import type { ContractConstructorSpecLatest, ContractConstructorSpecV0, ContractConstructorSpecV2, ContractContractSpecV0, ContractContractSpecV2, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEventParamSpecLatest, ContractEventParamSpecV0, ContractEventParamSpecV2, ContractEventSpecLatest, ContractEventSpecV0, ContractEventSpecV2, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpecLatest, ContractMessageParamSpecV0, ContractMessageParamSpecV2, ContractMessageSpecLatest, ContractMessageSpecV0, ContractMessageSpecV2, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractMetadataV2, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi';
|
||||
import type { FundIndex, FundInfo, LastContribution, TrieIndex } from '@polkadot/types/interfaces/crowdloan';
|
||||
import type { ConfigData, MessageId, OverweightIndex, PageCounter, PageIndexData } from '@polkadot/types/interfaces/cumulus';
|
||||
import type { AccountVote, AccountVoteSplit, AccountVoteStandard, Conviction, Delegations, PreimageStatus, PreimageStatusAvailable, PriorLock, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, ReferendumStatus, Tally, Voting, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces/democracy';
|
||||
@@ -212,13 +212,20 @@ declare module '@polkadot/types/types/registry' {
|
||||
ConsensusEngineId: ConsensusEngineId;
|
||||
ConsumedWeight: ConsumedWeight;
|
||||
ContractCallRequest: ContractCallRequest;
|
||||
ContractConstructorSpec: ContractConstructorSpec;
|
||||
ContractContractSpec: ContractContractSpec;
|
||||
ContractConstructorSpecLatest: ContractConstructorSpecLatest;
|
||||
ContractConstructorSpecV0: ContractConstructorSpecV0;
|
||||
ContractConstructorSpecV2: ContractConstructorSpecV2;
|
||||
ContractContractSpecV0: ContractContractSpecV0;
|
||||
ContractContractSpecV2: ContractContractSpecV2;
|
||||
ContractCryptoHasher: ContractCryptoHasher;
|
||||
ContractDiscriminant: ContractDiscriminant;
|
||||
ContractDisplayName: ContractDisplayName;
|
||||
ContractEventParamSpec: ContractEventParamSpec;
|
||||
ContractEventSpec: ContractEventSpec;
|
||||
ContractEventParamSpecLatest: ContractEventParamSpecLatest;
|
||||
ContractEventParamSpecV0: ContractEventParamSpecV0;
|
||||
ContractEventParamSpecV2: ContractEventParamSpecV2;
|
||||
ContractEventSpecLatest: ContractEventSpecLatest;
|
||||
ContractEventSpecV0: ContractEventSpecV0;
|
||||
ContractEventSpecV2: ContractEventSpecV2;
|
||||
ContractExecResult: ContractExecResult;
|
||||
ContractExecResultErr: ContractExecResultErr;
|
||||
ContractExecResultErrModule: ContractExecResultErrModule;
|
||||
@@ -240,12 +247,17 @@ declare module '@polkadot/types/types/registry' {
|
||||
ContractLayoutKey: ContractLayoutKey;
|
||||
ContractLayoutStruct: ContractLayoutStruct;
|
||||
ContractLayoutStructField: ContractLayoutStructField;
|
||||
ContractMessageParamSpec: ContractMessageParamSpec;
|
||||
ContractMessageSpec: ContractMessageSpec;
|
||||
ContractMessageParamSpecLatest: ContractMessageParamSpecLatest;
|
||||
ContractMessageParamSpecV0: ContractMessageParamSpecV0;
|
||||
ContractMessageParamSpecV2: ContractMessageParamSpecV2;
|
||||
ContractMessageSpecLatest: ContractMessageSpecLatest;
|
||||
ContractMessageSpecV0: ContractMessageSpecV0;
|
||||
ContractMessageSpecV2: ContractMessageSpecV2;
|
||||
ContractMetadata: ContractMetadata;
|
||||
ContractMetadataLatest: ContractMetadataLatest;
|
||||
ContractMetadataV0: ContractMetadataV0;
|
||||
ContractMetadataV1: ContractMetadataV1;
|
||||
ContractMetadataV2: ContractMetadataV2;
|
||||
ContractProject: ContractProject;
|
||||
ContractProjectContract: ContractProjectContract;
|
||||
ContractProjectInfo: ContractProjectInfo;
|
||||
|
||||
@@ -6,77 +6,10 @@
|
||||
|
||||
import type { Definitions } from '../../types';
|
||||
|
||||
import rpc from './rpc';
|
||||
|
||||
export default {
|
||||
rpc: {
|
||||
call: {
|
||||
description: 'Executes a call to a contract',
|
||||
params: [
|
||||
{
|
||||
name: 'callRequest',
|
||||
type: 'ContractCallRequest'
|
||||
},
|
||||
{
|
||||
name: 'at',
|
||||
type: 'BlockHash',
|
||||
isHistoric: true,
|
||||
isOptional: true
|
||||
}
|
||||
],
|
||||
type: 'ContractExecResult'
|
||||
},
|
||||
instantiate: {
|
||||
description: 'Instantiate a new contract',
|
||||
params: [
|
||||
{
|
||||
name: 'request',
|
||||
type: 'InstantiateRequest'
|
||||
},
|
||||
{
|
||||
name: 'at',
|
||||
type: 'BlockHash',
|
||||
isHstoric: true,
|
||||
isOptional: true
|
||||
}
|
||||
],
|
||||
type: 'ContractInstantiateResult'
|
||||
},
|
||||
getStorage: {
|
||||
description: 'Returns the value under a specified storage key in a contract',
|
||||
params: [
|
||||
{
|
||||
name: 'address',
|
||||
type: 'AccountId'
|
||||
},
|
||||
{
|
||||
name: 'key',
|
||||
type: 'H256'
|
||||
},
|
||||
{
|
||||
name: 'at',
|
||||
type: 'BlockHash',
|
||||
isHistoric: true,
|
||||
isOptional: true
|
||||
}
|
||||
],
|
||||
type: 'Option<Bytes>'
|
||||
},
|
||||
rentProjection: {
|
||||
description: 'Returns the projected time a given contract will be able to sustain paying its rent',
|
||||
params: [
|
||||
{
|
||||
name: 'address',
|
||||
type: 'AccountId'
|
||||
},
|
||||
{
|
||||
name: 'at',
|
||||
type: 'BlockHash',
|
||||
isHistoric: true,
|
||||
isOptional: true
|
||||
}
|
||||
],
|
||||
type: 'Option<BlockNumber>'
|
||||
}
|
||||
},
|
||||
rpc,
|
||||
types: {
|
||||
AliveContractInfo: {
|
||||
trieId: 'TrieId',
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// order important in structs... :)
|
||||
/* eslint-disable sort-keys */
|
||||
|
||||
import type { DefinitionsRpc } from '../../types';
|
||||
|
||||
export default {
|
||||
call: {
|
||||
description: 'Executes a call to a contract',
|
||||
params: [
|
||||
{
|
||||
name: 'callRequest',
|
||||
type: 'ContractCallRequest'
|
||||
},
|
||||
{
|
||||
name: 'at',
|
||||
type: 'BlockHash',
|
||||
isHistoric: true,
|
||||
isOptional: true
|
||||
}
|
||||
],
|
||||
type: 'ContractExecResult'
|
||||
},
|
||||
instantiate: {
|
||||
description: 'Instantiate a new contract',
|
||||
params: [
|
||||
{
|
||||
name: 'request',
|
||||
type: 'InstantiateRequest'
|
||||
},
|
||||
{
|
||||
name: 'at',
|
||||
type: 'BlockHash',
|
||||
isHstoric: true,
|
||||
isOptional: true
|
||||
}
|
||||
],
|
||||
type: 'ContractInstantiateResult'
|
||||
},
|
||||
getStorage: {
|
||||
description: 'Returns the value under a specified storage key in a contract',
|
||||
params: [
|
||||
{
|
||||
name: 'address',
|
||||
type: 'AccountId'
|
||||
},
|
||||
{
|
||||
name: 'key',
|
||||
type: 'H256'
|
||||
},
|
||||
{
|
||||
name: 'at',
|
||||
type: 'BlockHash',
|
||||
isHistoric: true,
|
||||
isOptional: true
|
||||
}
|
||||
],
|
||||
type: 'Option<Bytes>'
|
||||
},
|
||||
rentProjection: {
|
||||
description: 'Returns the projected time a given contract will be able to sustain paying its rent',
|
||||
params: [
|
||||
{
|
||||
name: 'address',
|
||||
type: 'AccountId'
|
||||
},
|
||||
{
|
||||
name: 'at',
|
||||
type: 'BlockHash',
|
||||
isHistoric: true,
|
||||
isOptional: true
|
||||
}
|
||||
],
|
||||
type: 'Option<BlockNumber>'
|
||||
}
|
||||
} as DefinitionsRpc;
|
||||
@@ -57,40 +57,76 @@ const layout = {
|
||||
};
|
||||
|
||||
const spec = {
|
||||
ContractConstructorSpec: {
|
||||
ContractConstructorSpecV0: {
|
||||
name: 'Text',
|
||||
selector: 'ContractSelector',
|
||||
args: 'Vec<ContractMessageParamSpec>',
|
||||
args: 'Vec<ContractMessageParamSpecV0>',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
ContractContractSpec: {
|
||||
constructors: 'Vec<ContractConstructorSpec>',
|
||||
messages: 'Vec<ContractMessageSpec>',
|
||||
events: 'Vec<ContractEventSpec>',
|
||||
ContractConstructorSpecV2: {
|
||||
label: 'Text',
|
||||
selector: 'ContractSelector',
|
||||
args: 'Vec<ContractMessageParamSpecV2>',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
ContractContractSpecV0: {
|
||||
constructors: 'Vec<ContractConstructorSpecV0>',
|
||||
messages: 'Vec<ContractMessageSpecV0>',
|
||||
events: 'Vec<ContractEventSpecV0>',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
ContractContractSpecV2: {
|
||||
constructors: 'Vec<ContractConstructorSpecV2>',
|
||||
messages: 'Vec<ContractMessageSpecV2>',
|
||||
events: 'Vec<ContractEventSpecV2>',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
ContractDisplayName: 'SiPath',
|
||||
ContractEventParamSpec: {
|
||||
ContractEventParamSpecV0: {
|
||||
name: 'Text',
|
||||
indexed: 'bool',
|
||||
type: 'ContractTypeSpec',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
ContractEventSpec: {
|
||||
name: 'Text',
|
||||
args: 'Vec<ContractEventParamSpec>',
|
||||
ContractEventParamSpecV2: {
|
||||
label: 'Text',
|
||||
indexed: 'bool',
|
||||
type: 'ContractTypeSpec',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
ContractMessageParamSpec: {
|
||||
ContractEventSpecV0: {
|
||||
name: 'Text',
|
||||
args: 'Vec<ContractEventParamSpecV0>',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
ContractEventSpecV2: {
|
||||
label: 'Text',
|
||||
args: 'Vec<ContractEventParamSpecV2>',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
ContractMessageParamSpecV0: {
|
||||
name: 'Text',
|
||||
type: 'ContractTypeSpec'
|
||||
},
|
||||
ContractMessageSpec: {
|
||||
ContractMessageParamSpecV2: {
|
||||
label: 'Text',
|
||||
type: 'ContractTypeSpec'
|
||||
},
|
||||
ContractMessageSpecV0: {
|
||||
name: 'Text',
|
||||
selector: 'ContractSelector',
|
||||
mutates: 'bool',
|
||||
payable: 'bool',
|
||||
args: 'Vec<ContractMessageParamSpec>',
|
||||
args: 'Vec<ContractMessageParamSpecV0>',
|
||||
returnType: 'Option<ContractTypeSpec>',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
ContractMessageSpecV2: {
|
||||
label: 'Text',
|
||||
selector: 'ContractSelector',
|
||||
mutates: 'bool',
|
||||
payable: 'bool',
|
||||
args: 'Vec<ContractMessageParamSpecV2>',
|
||||
returnType: 'Option<ContractTypeSpec>',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
@@ -103,12 +139,17 @@ const spec = {
|
||||
|
||||
const ContractMetadataV0 = {
|
||||
types: 'Vec<Si0Type>',
|
||||
spec: 'ContractContractSpec'
|
||||
spec: 'ContractContractSpecV0'
|
||||
};
|
||||
|
||||
const ContractMetadataV1 = {
|
||||
types: 'Vec<PortableType>',
|
||||
spec: 'ContractContractSpec'
|
||||
spec: 'ContractContractSpecV0'
|
||||
};
|
||||
|
||||
const ContractMetadataV2 = {
|
||||
types: 'Vec<PortableType>',
|
||||
spec: 'ContractContractSpecV2'
|
||||
};
|
||||
|
||||
const ContractProjectInfo = {
|
||||
@@ -116,19 +157,29 @@ const ContractProjectInfo = {
|
||||
contract: 'ContractProjectContract'
|
||||
};
|
||||
|
||||
const latest = {
|
||||
ContractConstructorSpecLatest: 'ContractConstructorSpecV2',
|
||||
ContractEventSpecLatest: 'ContractEventSpecV2',
|
||||
ContractEventParamSpecLatest: 'ContractEventParamSpecV2',
|
||||
ContractMessageParamSpecLatest: 'ContractMessageParamSpecV2',
|
||||
ContractMessageSpecLatest: 'ContractMessageSpecV2',
|
||||
ContractMetadataLatest: 'ContractMetadataV2'
|
||||
};
|
||||
|
||||
export default {
|
||||
rpc: {},
|
||||
types: objectSpread({}, layout, spec, {
|
||||
types: objectSpread({}, layout, spec, latest, {
|
||||
ContractProjectInfo,
|
||||
ContractMetadataV0,
|
||||
ContractMetadataV1,
|
||||
ContractMetadataV2,
|
||||
ContractMetadata: {
|
||||
_enum: {
|
||||
V0: 'ContractMetadataV0',
|
||||
V1: 'ContractMetadataV1'
|
||||
V1: 'ContractMetadataV1',
|
||||
V2: 'ContractMetadataV2'
|
||||
}
|
||||
},
|
||||
ContractMetadataLatest: 'ContractMetadataV1',
|
||||
ContractProjectV0: objectSpread({ metadataVersion: 'Text' }, ContractProjectInfo, ContractMetadataV0),
|
||||
ContractProject: '(ContractProjectInfo, ContractMetadata)',
|
||||
ContractProjectContract: {
|
||||
|
||||
@@ -6,19 +6,38 @@ import type { BTreeMap, Bytes, Enum, Option, Raw, Struct, Text, U8aFixed, Vec, b
|
||||
import type { Si0Type, SiLookupTypeId, SiPath } from '@polkadot/types/interfaces/scaleInfo';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
|
||||
/** @name ContractConstructorSpec */
|
||||
export interface ContractConstructorSpec extends Struct {
|
||||
/** @name ContractConstructorSpecLatest */
|
||||
export interface ContractConstructorSpecLatest extends ContractConstructorSpecV2 {}
|
||||
|
||||
/** @name ContractConstructorSpecV0 */
|
||||
export interface ContractConstructorSpecV0 extends Struct {
|
||||
readonly name: Text;
|
||||
readonly selector: ContractSelector;
|
||||
readonly args: Vec<ContractMessageParamSpec>;
|
||||
readonly args: Vec<ContractMessageParamSpecV0>;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
/** @name ContractContractSpec */
|
||||
export interface ContractContractSpec extends Struct {
|
||||
readonly constructors: Vec<ContractConstructorSpec>;
|
||||
readonly messages: Vec<ContractMessageSpec>;
|
||||
readonly events: Vec<ContractEventSpec>;
|
||||
/** @name ContractConstructorSpecV2 */
|
||||
export interface ContractConstructorSpecV2 extends Struct {
|
||||
readonly label: Text;
|
||||
readonly selector: ContractSelector;
|
||||
readonly args: Vec<ContractMessageParamSpecV2>;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
/** @name ContractContractSpecV0 */
|
||||
export interface ContractContractSpecV0 extends Struct {
|
||||
readonly constructors: Vec<ContractConstructorSpecV0>;
|
||||
readonly messages: Vec<ContractMessageSpecV0>;
|
||||
readonly events: Vec<ContractEventSpecV0>;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
/** @name ContractContractSpecV2 */
|
||||
export interface ContractContractSpecV2 extends Struct {
|
||||
readonly constructors: Vec<ContractConstructorSpecV2>;
|
||||
readonly messages: Vec<ContractMessageSpecV2>;
|
||||
readonly events: Vec<ContractEventSpecV2>;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
@@ -36,18 +55,39 @@ export interface ContractDiscriminant extends u32 {}
|
||||
/** @name ContractDisplayName */
|
||||
export interface ContractDisplayName extends SiPath {}
|
||||
|
||||
/** @name ContractEventParamSpec */
|
||||
export interface ContractEventParamSpec extends Struct {
|
||||
/** @name ContractEventParamSpecLatest */
|
||||
export interface ContractEventParamSpecLatest extends ContractEventParamSpecV2 {}
|
||||
|
||||
/** @name ContractEventParamSpecV0 */
|
||||
export interface ContractEventParamSpecV0 extends Struct {
|
||||
readonly name: Text;
|
||||
readonly indexed: bool;
|
||||
readonly type: ContractTypeSpec;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
/** @name ContractEventSpec */
|
||||
export interface ContractEventSpec extends Struct {
|
||||
/** @name ContractEventParamSpecV2 */
|
||||
export interface ContractEventParamSpecV2 extends Struct {
|
||||
readonly label: Text;
|
||||
readonly indexed: bool;
|
||||
readonly type: ContractTypeSpec;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
/** @name ContractEventSpecLatest */
|
||||
export interface ContractEventSpecLatest extends ContractEventSpecV2 {}
|
||||
|
||||
/** @name ContractEventSpecV0 */
|
||||
export interface ContractEventSpecV0 extends Struct {
|
||||
readonly name: Text;
|
||||
readonly args: Vec<ContractEventParamSpec>;
|
||||
readonly args: Vec<ContractEventParamSpecV0>;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
/** @name ContractEventSpecV2 */
|
||||
export interface ContractEventSpecV2 extends Struct {
|
||||
readonly label: Text;
|
||||
readonly args: Vec<ContractEventParamSpecV2>;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
@@ -99,19 +139,42 @@ export interface ContractLayoutStructField extends Struct {
|
||||
readonly name: Text;
|
||||
}
|
||||
|
||||
/** @name ContractMessageParamSpec */
|
||||
export interface ContractMessageParamSpec extends Struct {
|
||||
/** @name ContractMessageParamSpecLatest */
|
||||
export interface ContractMessageParamSpecLatest extends ContractMessageParamSpecV2 {}
|
||||
|
||||
/** @name ContractMessageParamSpecV0 */
|
||||
export interface ContractMessageParamSpecV0 extends Struct {
|
||||
readonly name: Text;
|
||||
readonly type: ContractTypeSpec;
|
||||
}
|
||||
|
||||
/** @name ContractMessageSpec */
|
||||
export interface ContractMessageSpec extends Struct {
|
||||
/** @name ContractMessageParamSpecV2 */
|
||||
export interface ContractMessageParamSpecV2 extends Struct {
|
||||
readonly label: Text;
|
||||
readonly type: ContractTypeSpec;
|
||||
}
|
||||
|
||||
/** @name ContractMessageSpecLatest */
|
||||
export interface ContractMessageSpecLatest extends ContractMessageSpecV2 {}
|
||||
|
||||
/** @name ContractMessageSpecV0 */
|
||||
export interface ContractMessageSpecV0 extends Struct {
|
||||
readonly name: Text;
|
||||
readonly selector: ContractSelector;
|
||||
readonly mutates: bool;
|
||||
readonly payable: bool;
|
||||
readonly args: Vec<ContractMessageParamSpec>;
|
||||
readonly args: Vec<ContractMessageParamSpecV0>;
|
||||
readonly returnType: Option<ContractTypeSpec>;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
/** @name ContractMessageSpecV2 */
|
||||
export interface ContractMessageSpecV2 extends Struct {
|
||||
readonly label: Text;
|
||||
readonly selector: ContractSelector;
|
||||
readonly mutates: bool;
|
||||
readonly payable: bool;
|
||||
readonly args: Vec<ContractMessageParamSpecV2>;
|
||||
readonly returnType: Option<ContractTypeSpec>;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
@@ -122,22 +185,30 @@ export interface ContractMetadata extends Enum {
|
||||
readonly asV0: ContractMetadataV0;
|
||||
readonly isV1: boolean;
|
||||
readonly asV1: ContractMetadataV1;
|
||||
readonly type: 'V0' | 'V1';
|
||||
readonly isV2: boolean;
|
||||
readonly asV2: ContractMetadataV2;
|
||||
readonly type: 'V0' | 'V1' | 'V2';
|
||||
}
|
||||
|
||||
/** @name ContractMetadataLatest */
|
||||
export interface ContractMetadataLatest extends ContractMetadataV1 {}
|
||||
export interface ContractMetadataLatest extends ContractMetadataV2 {}
|
||||
|
||||
/** @name ContractMetadataV0 */
|
||||
export interface ContractMetadataV0 extends Struct {
|
||||
readonly types: Vec<Si0Type>;
|
||||
readonly spec: ContractContractSpec;
|
||||
readonly spec: ContractContractSpecV0;
|
||||
}
|
||||
|
||||
/** @name ContractMetadataV1 */
|
||||
export interface ContractMetadataV1 extends Struct {
|
||||
readonly types: Vec<PortableType>;
|
||||
readonly spec: ContractContractSpec;
|
||||
readonly spec: ContractContractSpecV0;
|
||||
}
|
||||
|
||||
/** @name ContractMetadataV2 */
|
||||
export interface ContractMetadataV2 extends Struct {
|
||||
readonly types: Vec<PortableType>;
|
||||
readonly spec: ContractContractSpecV2;
|
||||
}
|
||||
|
||||
/** @name ContractProject */
|
||||
@@ -175,7 +246,7 @@ export interface ContractProjectV0 extends Struct {
|
||||
readonly source: ContractProjectSource;
|
||||
readonly contract: ContractProjectContract;
|
||||
readonly types: Vec<Si0Type>;
|
||||
readonly spec: ContractContractSpec;
|
||||
readonly spec: ContractContractSpecV0;
|
||||
}
|
||||
|
||||
/** @name ContractSelector */
|
||||
|
||||
Reference in New Issue
Block a user