Allow for CodecHash override & hasher option (#3206)

* Allow for CodecHash override & hasher option

* Adjust

* CodecHash maps to Hash
This commit is contained in:
Jaco Greeff
2021-02-24 10:17:29 +01:00
committed by GitHub
parent e333c3d8d9
commit ba8849a3e9
24 changed files with 70 additions and 47 deletions
+8 -1
View File
@@ -5,7 +5,7 @@ import type BN from 'bn.js';
import type { Text } from '@polkadot/types';
import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
import type { Hash } from '@polkadot/types/interfaces';
import type { ChainUpgradeVersion, DefinitionRpc, DefinitionRpcSub, OverrideModuleType, OverrideVersionedType, Registry, RegistryTypes } from '@polkadot/types/types';
import type { ChainUpgradeVersion, CodecHasher, DefinitionRpc, DefinitionRpcSub, OverrideModuleType, OverrideVersionedType, Registry, RegistryTypes } from '@polkadot/types/types';
import { bnToBn, isUndefined } from '@polkadot/util';
@@ -74,6 +74,13 @@ export function getSpecTypes ({ knownTypes }: Registry, chainName: Text | string
};
}
export function getSpecHasher ({ knownTypes }: Registry, chainName: Text | string, specName: Text | string): CodecHasher | null {
const _chainName = chainName.toString();
const _specName = specName.toString();
return knownTypes.hasher || knownTypes.typesBundle?.chain?.[_chainName]?.hasher || knownTypes.typesBundle?.spec?.[_specName]?.hasher || null;
}
/**
* @description Based on the chain and runtimeVersion, get the applicable rpc definitions (ready for registration)
*/