Adjust for aliasses for Weight 1.5 (#5465)
* Adjust for aliasses for Weight 1.5 * 9.13.5
This commit is contained in:
@@ -540,24 +540,28 @@ export class TypeRegistry implements Registry {
|
||||
// attach the lookup before we register any types
|
||||
this.setLookup(lookup);
|
||||
|
||||
// default to V1 - this includes 1.5 (with single field)
|
||||
let weightType = 'WeightV1';
|
||||
const WeightV2 = this.get<WeightV2>('SpWeightsWeightV2Weight');
|
||||
// we detect based on runtime configuration
|
||||
let Weight: string | null = null;
|
||||
|
||||
// detection for WeightV2 type
|
||||
if (WeightV2) {
|
||||
const weight = new WeightV2(this);
|
||||
if (this.hasType('SpWeightsWeightV2Weight')) {
|
||||
// detection for WeightV2 type based on latest naming
|
||||
const weightv2 = this.createType<WeightV2>('SpWeightsWeightV2Weight');
|
||||
|
||||
if (weight.refTime && weight.proofSize) {
|
||||
weightType = 'SpWeightsWeightV2Weight';
|
||||
}
|
||||
}
|
||||
|
||||
if (weightType !== 'WeightV1' || !isBn(this.createType<WeightV1>('Weight'))) {
|
||||
// where we have an already-supplied override, we don't clobber
|
||||
Weight = weightv2.refTime && weightv2.proofSize
|
||||
// with both refTime & proofSize we use as-is (WeightV2)
|
||||
? 'SpWeightsWeightV2Weight'
|
||||
// fallback to WeightV1 (WeightV1.5 is a struct, single field)
|
||||
: 'WeightV1';
|
||||
} else if (!isBn(this.createType<WeightV1>('Weight'))) {
|
||||
// where we have an already-supplied BN override, we don't clobber
|
||||
// it with our detected value (This protects against pre-defines
|
||||
// where Weight may be aliassed to WeightV0, e.g. in early Kusama chains)
|
||||
this.register({ Weight: weightType });
|
||||
Weight = 'WeightV1';
|
||||
}
|
||||
|
||||
if (Weight) {
|
||||
// we have detected a version, adjust the definition
|
||||
this.register({ Weight });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -47,9 +47,8 @@ const PATHS_ALIAS = splitNamespace([
|
||||
'sp_core::crypto::AccountId32',
|
||||
'sp_runtime::generic::era::Era',
|
||||
'sp_runtime::multiaddress::MultiAddress',
|
||||
// weights 2 (1.5+) is a structure, potentially can be flatenned
|
||||
// weights 1.5+ is a structure can be flatenned
|
||||
'frame_support::weights::weight_v2::Weight',
|
||||
'sp_weights::weight_v2::Weight',
|
||||
// ethereum overrides (Frontier, Moonbeam, Polkadot claims)
|
||||
'account::AccountId20',
|
||||
'polkadot_runtime_common::claims::EthereumAddress',
|
||||
@@ -152,12 +151,7 @@ function matchParts (first: string[], second: (string | Text)[]): boolean {
|
||||
}
|
||||
|
||||
/** @internal check if the path matches the PATHS_ALIAS (with wildcards) */
|
||||
function getAliasPath ({ def, path }: SiType): string | null {
|
||||
// specific logic for weights - we only override when non-complex struct
|
||||
if (path.join('::') === 'sp_weights::weight_v2::Weight' && def.isComposite && def.asComposite.fields.length !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function getAliasPath ({ path }: SiType): string | null {
|
||||
// TODO We need to handle ink! Balance in some way
|
||||
return path.length && PATHS_ALIAS.some((a) => matchParts(a, path))
|
||||
? path[path.length - 1].toString()
|
||||
|
||||
Reference in New Issue
Block a user