Ensure SignerPayload correctly serializes Option with None (#4079)
* Ensure `SignerPayload` correctly serializes `Option` with `None` * patch * Update CHANGELOG.md Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/types",
|
||||
"version": "6.4.2-1",
|
||||
"version": "6.4.2",
|
||||
"type": "module",
|
||||
"description": "Implementation of the Parity codec",
|
||||
"main": "index.js",
|
||||
@@ -26,7 +26,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^7.5.1",
|
||||
"@polkadot/types-support": "6.4.2-1",
|
||||
"@polkadot/types-support": "6.4.2",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^4.12.0"
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ describe('Option', (): void => {
|
||||
expect(new Option(registry, Text, undefined).isNone).toBe(true);
|
||||
expect(new Option(registry, Text, null).isNone).toBe(true);
|
||||
expect(new Option(registry, Text, 'test').isNone).toBe(false);
|
||||
expect(new Option(registry, Text, '0x').isNone).toBe(true);
|
||||
});
|
||||
|
||||
it('converts an option to an option', (): void => {
|
||||
|
||||
@@ -18,7 +18,7 @@ function decodeOptionU8a (registry: Registry, Type: Constructor, value: Uint8Arr
|
||||
|
||||
/** @internal */
|
||||
function decodeOption (registry: Registry, typeName: Constructor | string, value?: unknown): Codec {
|
||||
if (isNull(value) || isUndefined(value) || value instanceof Null) {
|
||||
if (isNull(value) || isUndefined(value) || value instanceof Null || value === '0x') {
|
||||
return new Null(registry);
|
||||
}
|
||||
|
||||
|
||||
@@ -459,9 +459,9 @@ export class TypeRegistry implements Registry {
|
||||
// setup the available extensions
|
||||
this.setSignedExtensions(
|
||||
signedExtensions || (
|
||||
metadata.asLatest.extrinsic.version.gt(BN_ZERO)
|
||||
this.#metadata.extrinsic.version.gt(BN_ZERO)
|
||||
// FIXME Use the extension and their injected types
|
||||
? metadata.asLatest.extrinsic.signedExtensions.map(({ identifier }) => identifier.toString())
|
||||
? this.#metadata.extrinsic.signedExtensions.map(({ identifier }) => identifier.toString())
|
||||
: fallbackExtensions
|
||||
),
|
||||
userExtensions
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { Codec, ISignerPayload, Registry, SignerPayloadJSON, SignerPayloadR
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { Compact } from '../codec/Compact';
|
||||
import { Option } from '../codec/Option';
|
||||
import { Struct } from '../codec/Struct';
|
||||
import { Vec } from '../codec/Vec';
|
||||
import { Text } from '../primitive/Text';
|
||||
@@ -120,7 +121,13 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign
|
||||
return {
|
||||
// add any explicit overrides we may have
|
||||
...(Object.keys(this._extraTypes).reduce<Record<string, string>>((map, key) => {
|
||||
map[key] = (this.get(key) as Codec).toHex();
|
||||
const value = this.get(key) as Codec;
|
||||
const isOption = value instanceof Option;
|
||||
|
||||
// Don't include Option.isNone
|
||||
if (!isOption || value.isSome) {
|
||||
map[key] = value.toHex();
|
||||
}
|
||||
|
||||
return map;
|
||||
}, {})),
|
||||
|
||||
Reference in New Issue
Block a user