From 415bedcd3bcd85a05ca459f56aefed8bb7418b6c Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sun, 12 Aug 2018 00:40:12 +0200 Subject: [PATCH] accountId decoding --- packages/type-params/package.json | 3 ++- .../type-params/src/decode/value/accountId.ts | 25 +++++++++++++++++++ .../type-params/src/decode/value/index.ts | 3 ++- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 packages/type-params/src/decode/value/accountId.ts 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);