accountId decoding

This commit is contained in:
Jaco Greeff
2018-08-12 00:40:12 +02:00
parent 285e56bf11
commit 415bedcd3b
3 changed files with 29 additions and 2 deletions
@@ -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)
};
}
@@ -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);