Opaque{Metadata, Multiaddr, PeerId} -> WrapperOpaque<Bytes> (#5038)
* Opaque{Metadata, Multiaddr, PeerId} -> WrapperOpaque<Bytes>
* Adjust
* Adjust
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust `Opaque{Metadata, Multiaddr, PeerId}` decoding to `WrapperOpaque<Bytes>`
|
||||
- Adjust type generation to correctly cater for ambient definitions
|
||||
- Improve type argument generation for `Option<...>` types
|
||||
|
||||
|
||||
@@ -2566,8 +2566,8 @@ export default {
|
||||
* Lookup268: sp_core::offchain::OpaqueNetworkState
|
||||
**/
|
||||
SpCoreOffchainOpaqueNetworkState: {
|
||||
peerId: 'Bytes',
|
||||
externalAddresses: 'Vec<Bytes>'
|
||||
peerId: 'OpaquePeerId',
|
||||
externalAddresses: 'Vec<OpaqueMultiaddr>'
|
||||
},
|
||||
/**
|
||||
* Lookup272: pallet_im_online::sr25519::app_sr25519::Signature
|
||||
|
||||
@@ -9,6 +9,7 @@ import type { Data } from '@polkadot/types';
|
||||
import type { BTreeMap, Bytes, Compact, Enum, Null, Option, Result, Set, Struct, Text, U256, U8aFixed, Vec, WrapperKeepOpaque, bool, u128, u16, u32, u64, u8 } from '@polkadot/types-codec';
|
||||
import type { ITuple } from '@polkadot/types-codec/types';
|
||||
import type { Vote } from '@polkadot/types/interfaces/elections';
|
||||
import type { OpaqueMultiaddr, OpaquePeerId } from '@polkadot/types/interfaces/imOnline';
|
||||
import type { AccountId32, Call, H256, MultiAddress, PerU16, Perbill, Percent, Perquintill } from '@polkadot/types/interfaces/runtime';
|
||||
import type { Event } from '@polkadot/types/interfaces/system';
|
||||
|
||||
@@ -2775,8 +2776,8 @@ declare module '@polkadot/types/lookup' {
|
||||
|
||||
/** @name SpCoreOffchainOpaqueNetworkState (268) */
|
||||
interface SpCoreOffchainOpaqueNetworkState extends Struct {
|
||||
readonly peerId: Bytes;
|
||||
readonly externalAddresses: Vec<Bytes>;
|
||||
readonly peerId: OpaquePeerId;
|
||||
readonly externalAddresses: Vec<OpaqueMultiaddr>;
|
||||
}
|
||||
|
||||
/** @name PalletImOnlineSr25519AppSr25519Signature (272) */
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { AnyJson, AnyU8a, Codec, CodecClass, Inspect, Registry } from '../types';
|
||||
|
||||
import { compactAddLength, compactStripLength, compactToU8a, isHex, isU8a } from '@polkadot/util';
|
||||
import { compactAddLength, compactStripLength, compactToU8a, isHex, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { Raw } from '../native/Raw';
|
||||
import { typeToConstructor } from '../utils';
|
||||
@@ -20,9 +20,11 @@ function decodeRaw<T extends Codec> (registry: Registry, typeName: CodecClass<T>
|
||||
|
||||
if (isU8a(value) || isHex(value)) {
|
||||
try {
|
||||
const [, u8a] = isHex(value) || (value instanceof Raw)
|
||||
? [0, value]
|
||||
: compactStripLength(value);
|
||||
const [, u8a] = isHex(value)
|
||||
? [0, u8aToU8a(value)]
|
||||
: (value instanceof Raw)
|
||||
? [0, value.subarray()]
|
||||
: compactStripLength(value);
|
||||
|
||||
return [Type, new Type(registry, u8a), value];
|
||||
} catch {
|
||||
|
||||
@@ -36,7 +36,7 @@ describe('WrapperOpaque', (): void => {
|
||||
it('has the correct unwrap', (): void => {
|
||||
expect(
|
||||
new WrapperOpaque(registry, 'u32', '0x12345678').unwrap().toHex()
|
||||
).toEqual('0x12345678');
|
||||
).toEqual('0x78563412');
|
||||
});
|
||||
|
||||
it('has the correct toRawType', (): void => {
|
||||
@@ -47,7 +47,7 @@ describe('WrapperOpaque', (): void => {
|
||||
|
||||
it('has a sane inspect', (): void => {
|
||||
expect(
|
||||
new WrapperOpaque(registry, 'u32', '0x12345678').inspect()
|
||||
new WrapperOpaque(registry, 'u32', '0x78563412').inspect()
|
||||
).toEqual({
|
||||
inner: [{ outer: [new Uint8Array([0x78, 0x56, 0x34, 0x12])] }],
|
||||
outer: [new Uint8Array([4 << 2])]
|
||||
|
||||
@@ -24,8 +24,8 @@ export default {
|
||||
sessionIndex: 'SessionIndex',
|
||||
authorityIndex: 'AuthIndex'
|
||||
},
|
||||
OpaqueMultiaddr: 'Bytes',
|
||||
OpaquePeerId: 'Bytes',
|
||||
OpaqueMultiaddr: 'WrapperOpaque<Bytes>',
|
||||
OpaquePeerId: 'WrapperOpaque<Bytes>',
|
||||
OpaqueNetworkState: {
|
||||
peerId: 'OpaquePeerId',
|
||||
externalAddresses: 'Vec<OpaqueMultiaddr>'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable */
|
||||
|
||||
import type { Bytes, Struct, Vec, u32 } from '@polkadot/types-codec';
|
||||
import type { Bytes, Struct, Vec, WrapperOpaque, u32 } from '@polkadot/types-codec';
|
||||
import type { Signature } from '@polkadot/types/interfaces/extrinsics';
|
||||
import type { BlockNumber } from '@polkadot/types/interfaces/runtime';
|
||||
import type { SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
@@ -30,7 +30,7 @@ export interface HeartbeatTo244 extends Struct {
|
||||
}
|
||||
|
||||
/** @name OpaqueMultiaddr */
|
||||
export interface OpaqueMultiaddr extends Bytes {}
|
||||
export interface OpaqueMultiaddr extends WrapperOpaque<Bytes> {}
|
||||
|
||||
/** @name OpaqueNetworkState */
|
||||
export interface OpaqueNetworkState extends Struct {
|
||||
@@ -39,6 +39,6 @@ export interface OpaqueNetworkState extends Struct {
|
||||
}
|
||||
|
||||
/** @name OpaquePeerId */
|
||||
export interface OpaquePeerId extends Bytes {}
|
||||
export interface OpaquePeerId extends WrapperOpaque<Bytes> {}
|
||||
|
||||
export type PHANTOM_IMONLINE = 'imOnline';
|
||||
|
||||
@@ -44,7 +44,7 @@ export default {
|
||||
StorageHasher: 'StorageHasherV14',
|
||||
|
||||
// additional types
|
||||
OpaqueMetadata: 'Bytes',
|
||||
OpaqueMetadata: 'WrapperOpaque<Bytes>',
|
||||
|
||||
// the enum containing all the mappings
|
||||
MetadataAll: {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* eslint-disable */
|
||||
|
||||
import type { PortableRegistry } from '@polkadot/types';
|
||||
import type { Bytes, Enum, Option, Struct, Text, Type, Vec, bool, u8 } from '@polkadot/types-codec';
|
||||
import type { Bytes, Enum, Option, Struct, Text, Type, Vec, WrapperOpaque, bool, u8 } from '@polkadot/types-codec';
|
||||
import type { Si1Field, Si1LookupTypeId, Si1Type, SiLookupTypeId } from '@polkadot/types/interfaces/scaleInfo';
|
||||
|
||||
/** @name ErrorMetadataLatest */
|
||||
@@ -276,7 +276,7 @@ export interface ModuleMetadataV9 extends Struct {
|
||||
}
|
||||
|
||||
/** @name OpaqueMetadata */
|
||||
export interface OpaqueMetadata extends Bytes {}
|
||||
export interface OpaqueMetadata extends WrapperOpaque<Bytes> {}
|
||||
|
||||
/** @name PalletCallMetadataLatest */
|
||||
export interface PalletCallMetadataLatest extends PalletCallMetadataV14 {}
|
||||
|
||||
@@ -55,6 +55,10 @@ const PATHS_ALIAS = splitNamespace([
|
||||
'*_democracy::vote::Vote',
|
||||
'*_conviction_voting::vote::Vote',
|
||||
'*_identity::types::Data',
|
||||
// these are opaque Vec<u8> wrappers
|
||||
'sp_core::OpaqueMetadata',
|
||||
'sp_core::OpaquePeerId',
|
||||
'sp_core::offchain::OpaqueMultiaddr',
|
||||
// shorten some well-known types
|
||||
'primitive_types::*',
|
||||
'sp_arithmetic::per_things::*',
|
||||
|
||||
Reference in New Issue
Block a user