Fix MultiAddress decoding from raw publicKey (#3215)
* Fix Multiddress decoding from raw publicKey * Full decoding on empty * Update
This commit is contained in:
@@ -26,7 +26,7 @@ describe('Call', (): void => {
|
||||
|
||||
it('handles creation from a hex value properly', (): void => {
|
||||
expect(
|
||||
new Call(registry, '0x0601').toU8a()
|
||||
new Call(registry, '0x06010000000000000000000000000000000000000000000000000000000000000000').toU8a()
|
||||
).toEqual(
|
||||
new Uint8Array([6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
||||
); // balances.setBalance
|
||||
|
||||
@@ -6,6 +6,13 @@ import { TypeRegistry } from '../create';
|
||||
describe('MultiAddress', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
it('decodes from an empty value', (): void => {
|
||||
const a = registry.createType('MultiAddress');
|
||||
|
||||
expect(a.index).toEqual(0);
|
||||
expect(a.toHex()).toEqual('0x000000000000000000000000000000000000000000000000000000000000000000');
|
||||
});
|
||||
|
||||
it('correctly decodes a stream with Address20', (): void => {
|
||||
const a = registry.createType('MultiAddress', '0x0467f89207abe6e1b093befd84a48f03313765929207009e292608');
|
||||
|
||||
|
||||
@@ -3,17 +3,15 @@
|
||||
|
||||
import type { Registry } from '../types';
|
||||
|
||||
import { isBn, isNumber, isString } from '@polkadot/util';
|
||||
import { isBn, isNumber, isString, isU8a } from '@polkadot/util';
|
||||
import { decodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import { Enum } from '../codec/Enum';
|
||||
import { GenericAccountId } from './AccountId';
|
||||
import { GenericAccountIndex } from './AccountIndex';
|
||||
|
||||
function decodeString (registry: Registry, value: string): unknown {
|
||||
const u8a = decodeAddress(value.toString());
|
||||
|
||||
if (u8a.length === 32) {
|
||||
function decodeU8a (registry: Registry, u8a: Uint8Array): unknown {
|
||||
if ([0, 32].includes(u8a.length)) {
|
||||
return { Id: u8a };
|
||||
} else if (u8a.length === 20) {
|
||||
return { Address20: u8a };
|
||||
@@ -32,7 +30,9 @@ function decodeMultiAny (registry: Registry, value?: unknown): unknown {
|
||||
} else if (value instanceof GenericAccountIndex || isBn(value) || isNumber(value)) {
|
||||
return { Index: isNumber(value) ? value : value.toNumber() };
|
||||
} else if (isString(value)) {
|
||||
return decodeString(registry, value.toString());
|
||||
return decodeU8a(registry, decodeAddress(value.toString()));
|
||||
} else if (isU8a(value)) {
|
||||
return decodeU8a(registry, value);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
Reference in New Issue
Block a user