Fix memomization on BigInt values (#2728)

This commit is contained in:
Jaco Greeff
2020-10-15 08:59:48 +02:00
committed by GitHub
parent 393c677a16
commit d47faa4687
3 changed files with 18 additions and 5 deletions
+3 -3
View File
@@ -13,6 +13,7 @@ import jsonrpc from '@polkadot/types/interfaces/jsonrpc';
import { Option, StorageKey, Vec, createClass, createTypeUnsafe } from '@polkadot/types';
import { assert, hexToU8a, isFunction, isNull, isUndefined, logger, u8aToU8a } from '@polkadot/util';
import normalizer from './normalizer';
import { drr, refCountDelay } from './rxjs';
interface StorageChangeSetJSON {
@@ -267,7 +268,7 @@ export default class Rpc implements RpcInterface {
memoized = memoizee(this._createMethodWithRaw(creator), {
length: false,
normalizer: (args) => this.#instanceId + JSON.stringify(args)
normalizer: normalizer(this.#instanceId)
});
return memoized;
@@ -355,8 +356,7 @@ export default class Rpc implements RpcInterface {
// Normalize args so that different args that should be cached
// together are cached together.
// E.g.: `query.my.method('abc') === query.my.method(createType('AccountId', 'abc'));`
// eslint-disable-next-line @typescript-eslint/unbound-method
normalizer: (args) => this.#instanceId + JSON.stringify(args)
normalizer: normalizer(this.#instanceId)
});
return memoized;
+13
View File
@@ -0,0 +1,13 @@
// Copyright 2017-2020 @polkadot/rpc-core authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { isBigInt } from '@polkadot/util';
export default function normalizer (instanceId: string): (value: unknown) => string {
return (value: unknown) =>
instanceId + JSON.stringify(value, (_, value: unknown) =>
isBigInt(value)
? value.toString()
: value
);
}