StorageKey toHuman returns decoded key (#2183)

This commit is contained in:
Jaco Greeff
2020-04-16 15:28:15 +02:00
committed by GitHub
parent e484e7cf35
commit 8c949bb3df
2 changed files with 19 additions and 7 deletions
@@ -240,9 +240,7 @@ describe('StorageKey', (): void => {
key.setMeta(metadata.query.staking.erasStakers.meta);
expect(
key.args.map((arg) => arg.toHuman())
).toEqual([
expect(key.toHuman()).toEqual([
'16',
'5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY'
]);
@@ -253,9 +251,7 @@ describe('StorageKey', (): void => {
key.setMeta(metadata.query.society.defenderVotes.meta);
expect(
key.args.map((arg) => arg.toHuman())
).toEqual([
expect(key.toHuman()).toEqual([
'5D4yQHKfqCQYThhHmTfN1JEDi47uyDJc1xg9eZfAG1R7FC7J'
]);
});
+17 -1
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { StorageEntryMetadataLatest, StorageEntryTypeLatest, StorageHasher } from '../interfaces/metadata';
import { AnyU8a, Codec, InterfaceTypes, Registry } from '../types';
import { AnyJson, AnyU8a, Codec, InterfaceTypes, Registry } from '../types';
import { assert, isFunction, isString, isU8a } from '@polkadot/util';
@@ -261,4 +261,20 @@ export default class StorageKey extends Bytes {
return this;
}
/**
* @description Returns the Human representation for this type
*/
public toHuman (): AnyJson {
return this._args.length
? this._args.map((arg) => arg.toHuman())
: super.toHuman();
}
/**
* @description Returns the raw type for this
*/
public toRawType (): string {
return 'StorageKey';
}
}