-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
draft implementation with version metadata
- Loading branch information
Showing
3 changed files
with
140 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2017-2024 @polkadot/api-contract authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { ContractMetadataLatest, ContractMetadataV4, ContractMetadataV5 } from '@polkadot/types/interfaces'; | ||
import type { Registry } from '@polkadot/types/types'; | ||
|
||
import { v0ToV1 } from './toV1.js'; | ||
import { v1ToV2 } from './toV2.js'; | ||
import { v2ToV3 } from './toV3.js'; | ||
import { v3ToV4 } from './toV4.js'; | ||
|
||
// The versions where an enum is used, aka V0 is missing | ||
// (Order from newest, i.e. we expect more on newest vs oldest) | ||
export const enumVersions = ['V5', 'V4', 'V3', 'V2', 'V1'] as const; | ||
|
||
type Versions = typeof enumVersions[number] | 'V0'; | ||
|
||
type Converter = (registry: Registry, vx: any) => ContractMetadataV4 | ContractMetadataV5; | ||
|
||
// Helper to convert metadata from one step to the next | ||
function createConverter <I, O> (next: (registry: Registry, input: O) => ContractMetadataLatest, step: (registry: Registry, input: I) => O): (registry: Registry, input: I) => ContractMetadataLatest { | ||
return (registry: Registry, input: I): ContractMetadataLatest => | ||
next(registry, step(registry, input)); | ||
} | ||
|
||
export function v5ToLatestCompatible (_registry: Registry, v5: ContractMetadataV5): ContractMetadataV5 { | ||
return v5; | ||
} | ||
|
||
export function v4ToLatestCompatible (_registry: Registry, v4: ContractMetadataV4): ContractMetadataV4 { | ||
return v4; | ||
} | ||
|
||
export const v3ToLatestCompatible = /*#__PURE__*/ createConverter(v4ToLatestCompatible, v3ToV4); | ||
Check failure on line 34 in packages/api-contract/src/Abi/toLatestCompatible.ts
|
||
export const v2ToLatestCompatible = /*#__PURE__*/ createConverter(v3ToLatestCompatible, v2ToV3); | ||
export const v1ToLatestCompatible = /*#__PURE__*/ createConverter(v2ToLatestCompatible, v1ToV2); | ||
export const v0ToLatestCompatible = /*#__PURE__*/ createConverter(v1ToLatestCompatible, v0ToV1); | ||
|
||
export const convertVersions: [Versions, Converter][] = [ | ||
['V5', v5ToLatestCompatible], | ||
['V4', v4ToLatestCompatible], | ||
['V3', v3ToLatestCompatible], | ||
['V2', v2ToLatestCompatible], | ||
['V1', v1ToLatestCompatible], | ||
['V0', v0ToLatestCompatible] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters