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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user