diff --git a/packages/type-params/package.json b/packages/type-params/package.json index 6b4b63148f..682821b47a 100644 --- a/packages/type-params/package.json +++ b/packages/type-params/package.json @@ -37,6 +37,7 @@ "@polkadot/extrinsics": "^0.28.4", "@polkadot/params": "^0.28.4", "@polkadot/primitives": "^0.28.4", - "@polkadot/util": "^0.28.1" + "@polkadot/util": "^0.28.1", + "@polkadot/util-keyring": "^0.28.1" } } diff --git a/packages/type-params/src/decode/value/accountId.ts b/packages/type-params/src/decode/value/accountId.ts new file mode 100644 index 0000000000..216053f11f --- /dev/null +++ b/packages/type-params/src/decode/value/accountId.ts @@ -0,0 +1,25 @@ +// Copyright 2017-2018 @polkadot/params authors & contributors +// This software may be modified and distributed under the terms +// of the ISC license. See the LICENSE file for details. + +import { EncodingVersions, Param$Decoded } from '../../types'; + +// TODO Comment out when auto-convert of addresses is in place +// import encodeAddress from '@polkadot/util-keyring/address/encode'; + +import u8a from './u8a'; + +export default function accountId (input: Uint8Array | null, version: EncodingVersions, isStorage: boolean): Param$Decoded { + if (input === null) { + return { + length: 0 + } as Param$Decoded; + } + + const u8aDecoded = u8a(input, 256, (isStorage || version === 'poc-1') ? 0 : 1); + + return { + length: u8aDecoded.length, + value: u8aDecoded.value // encodeAddress(u8aDecoded.value as Uint8Array) + }; +} diff --git a/packages/type-params/src/decode/value/index.ts b/packages/type-params/src/decode/value/index.ts index 9d47dde454..5c75b65721 100644 --- a/packages/type-params/src/decode/value/index.ts +++ b/packages/type-params/src/decode/value/index.ts @@ -8,6 +8,7 @@ import { Decoder } from '../types'; import sizes from '@polkadot/primitives/sizes'; import toU8a from '@polkadot/util/u8a/toU8a'; +import accountId from './accountId'; import bool from './bool'; import bn from './bn'; import byte from './byte'; @@ -30,7 +31,7 @@ export default function decodeValue (decode: Decoder, type: Param$Type, _input: switch (type) { // TODO Pass back the actual address, not publicKey? case 'AccountId': - return u8a(input, 256, (isStorage || version === 'poc-1') ? 0 : 1); + return accountId(input, version, isStorage); case 'Balance': return bn(input, sizes.Balance);