Adjust toHuman on Call (#4109)

This commit is contained in:
Jaco
2021-10-25 17:10:26 +03:00
committed by GitHub
parent 2c212e6b4d
commit 7f5a52258c
2 changed files with 13 additions and 8 deletions
+1
View File
@@ -4,6 +4,7 @@
Changes:
- Adjust `toHuman` on `Call` to return names & (not only) values
- Allow for optional known `RuntimeVersion` to short-circuit `api.at`
+12 -8
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { FunctionMetadataLatest } from '../interfaces/metadata';
import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, CallBase, CallFunction, IMethod, InterfaceTypes, Registry } from '../types';
import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, CallBase, CallFunction, Codec, IMethod, InterfaceTypes, Registry } from '../types';
import { isHex, isObject, isU8a, u8aToU8a } from '@polkadot/util';
@@ -145,7 +145,6 @@ export class GenericCall<A extends AnyTuple = AnyTuple> extends Struct implement
* @description The arguments for the function call
*/
public get args (): A {
// FIXME This should return a Struct instead of an Array
return [...(this.get('args') as Struct).values()] as A;
}
@@ -156,6 +155,13 @@ export class GenericCall<A extends AnyTuple = AnyTuple> extends Struct implement
return getArgsDef(this.registry, this.meta);
}
/**
* @description The argument entries
*/
public get argsEntries (): [string, Codec][] {
return [...(this.get('args') as Struct).entries()];
}
/**
* @description The encoded `[sectionIndex, methodIndex]` identifier
*/
@@ -211,12 +217,10 @@ export class GenericCall<A extends AnyTuple = AnyTuple> extends Struct implement
}
return {
args: this.args.map((arg) => arg.toHuman(isExpanded)),
// args: this.args.map((arg, index) => call
// ? { [call.meta.args[index].name.toString()]: arg.toHuman(isExpanded) }
// : arg.toHuman(isExpanded)
// ),
// callIndex: u8aToHex(this.callIndex),
args: this.argsEntries.reduce<Record<string, AnyJson>>((args, [n, a]) => ({
...args,
[n]: a.toHuman(isExpanded)
}), {}),
method: call?.method,
section: call?.section,
...(isExpanded && call