1 |
|
2 |
|
3 | import { isString, isU8a, u8aToU8a } from '@polkadot/util';
|
4 | import { MetadataVersioned } from "./MetadataVersioned.js";
|
5 |
|
6 | const VERSION_IDX = 4;
|
7 |
|
8 | const EMPTY_METADATA = new Uint8Array([0x6d, 0x65, 0x74, 0x61, 9]);
|
9 |
|
10 | function decodeU8a(registry, value) {
|
11 | const u8a = value.length === 0 ? EMPTY_METADATA : value;
|
12 |
|
13 |
|
14 |
|
15 | if (u8a[VERSION_IDX] === 9) {
|
16 | try {
|
17 | return new MetadataVersioned(registry, u8a);
|
18 | } catch (error) {
|
19 | u8a[VERSION_IDX] = 10;
|
20 | return u8a;
|
21 | }
|
22 | }
|
23 |
|
24 | return u8a;
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | export class Metadata extends MetadataVersioned {
|
34 | constructor(registry, value) {
|
35 |
|
36 | super(registry, isU8a(value) || isString(value) ? decodeU8a(registry, u8aToU8a(value)) : value);
|
37 | }
|
38 |
|
39 | } |
\ | No newline at end of file |