Adjust inspect for ExtrinsicPayload (#4862)
* Adjust inspect for ExtrinsicPayload * Adjust
This commit is contained in:
@@ -7,6 +7,9 @@ Changes:
|
|||||||
- Add codec support for specialized `Option<bool>`
|
- Add codec support for specialized `Option<bool>`
|
||||||
- Optimization for `createClass` with shortcut typeDef creation
|
- Optimization for `createClass` with shortcut typeDef creation
|
||||||
- Optimization of `registry.getOrUnknown` with lookup cache
|
- Optimization of `registry.getOrUnknown` with lookup cache
|
||||||
|
- Optimization of Array allocations in decoding
|
||||||
|
- Use `compactFromU8aLim` & `u8aConcatStrict` variants
|
||||||
|
- Adjust `.inspect()` for `ExtrinsicPayload`
|
||||||
- Adjust Kusama `StakingLedger` for runtime 1051
|
- Adjust Kusama `StakingLedger` for runtime 1051
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,13 +54,15 @@ export class Bytes extends Raw {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
override inspect (): Inspect {
|
override inspect (isBare?: boolean): Inspect {
|
||||||
const clength = compactToU8a(this.length);
|
const clength = compactToU8a(this.length);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
outer: this.length
|
outer: isBare
|
||||||
? [clength, super.toU8a()]
|
? [super.toU8a()]
|
||||||
: [clength]
|
: this.length
|
||||||
|
? [clength, super.toU8a()]
|
||||||
|
: [clength]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -231,12 +231,16 @@ export class Struct<
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
inspect (): Inspect {
|
inspect (isBare?: BareOpts): Inspect {
|
||||||
const inner = new Array<Inspect>();
|
const inner = new Array<Inspect>();
|
||||||
|
|
||||||
for (const [k, v] of this.entries()) {
|
for (const [k, v] of this.entries()) {
|
||||||
inner.push({
|
inner.push({
|
||||||
...v.inspect(),
|
...v.inspect(
|
||||||
|
!isBare || isBoolean(isBare)
|
||||||
|
? isBare
|
||||||
|
: isBare[k]
|
||||||
|
),
|
||||||
name: stringCamelCase(k as string)
|
name: stringCamelCase(k as string)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export interface Codec {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
inspect (): Inspect;
|
inspect (isBare?: BareOpts): Inspect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
// Copyright 2017-2022 @polkadot/types authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import rpcMetadata from '@polkadot/types-support/metadata/static-substrate';
|
||||||
|
|
||||||
|
import { TypeRegistry } from '../../create';
|
||||||
|
import { decorateExtrinsics, Metadata } from '../../metadata';
|
||||||
|
import { GenericExtrinsicPayloadV4 as ExtrinsicPayload } from '.';
|
||||||
|
|
||||||
|
const registry = new TypeRegistry();
|
||||||
|
const metadata = new Metadata(registry, rpcMetadata);
|
||||||
|
|
||||||
|
registry.setMetadata(metadata);
|
||||||
|
|
||||||
|
const tx = decorateExtrinsics(registry, metadata.asLatest, metadata.version);
|
||||||
|
|
||||||
|
describe('ExtrinsicPayload', (): void => {
|
||||||
|
it('has a sane inspect', (): void => {
|
||||||
|
// we don't expect this to fail, however it is actually a good
|
||||||
|
// reference for the ordering in base Substrate
|
||||||
|
expect(new ExtrinsicPayload(registry, { method: tx.timestamp.set(0).toHex() } as never).inspect()).toEqual({
|
||||||
|
inner: [
|
||||||
|
{ name: 'method', outer: [new Uint8Array([3, 0, 0])] },
|
||||||
|
{ name: 'era', outer: [new Uint8Array([0]), new Uint8Array([0])] },
|
||||||
|
{ name: 'nonce', outer: [new Uint8Array([0])] },
|
||||||
|
{ name: 'tip', outer: [new Uint8Array([0])] },
|
||||||
|
{ name: 'assetId', outer: [new Uint8Array([0])] },
|
||||||
|
{ name: 'specVersion', outer: [new Uint8Array([0, 0, 0, 0])] },
|
||||||
|
{ name: 'transactionVersion', outer: [new Uint8Array([0, 0, 0, 0])] },
|
||||||
|
{ name: 'genesisHash', outer: [new Uint8Array(32)] },
|
||||||
|
{ name: 'blockHash', outer: [new Uint8Array(32)] }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import type { SignOptions } from '@polkadot/keyring/types';
|
import type { SignOptions } from '@polkadot/keyring/types';
|
||||||
import type { Registry } from '@polkadot/types-codec/types';
|
import type { Inspect, Registry } from '@polkadot/types-codec/types';
|
||||||
import type { HexString } from '@polkadot/util/types';
|
import type { HexString } from '@polkadot/util/types';
|
||||||
import type { ExtrinsicEra } from '../../interfaces/extrinsics';
|
import type { ExtrinsicEra } from '../../interfaces/extrinsics';
|
||||||
import type { Hash } from '../../interfaces/runtime';
|
import type { Hash } from '../../interfaces/runtime';
|
||||||
@@ -37,6 +37,13 @@ export class GenericExtrinsicPayloadV4 extends Struct {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
|
*/
|
||||||
|
public override inspect (): Inspect {
|
||||||
|
return super.inspect({ method: true });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description The block [[Hash]] the signature applies to (mortal/immortal)
|
* @description The block [[Hash]] the signature applies to (mortal/immortal)
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user