Adjust PortableRegistry name extraction (#4946)
* Adjust PortableRegistry name extraction * Adjust count * Adjust * Adjust .every check * Adjust ink! test outcomes
This commit is contained in:
@@ -252,7 +252,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 13,
|
||||
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"MultisigPlainMultisigPlainTransaction\"}}",
|
||||
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"MultisigPlainTransaction\"}}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::collections::stash::Entry",
|
||||
"sub": [
|
||||
@@ -269,7 +269,7 @@
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 14,
|
||||
"lookupName": "MultisigPlainMultisigPlainTransaction",
|
||||
"lookupName": "MultisigPlainTransaction",
|
||||
"type": "Lookup14",
|
||||
"index": 1,
|
||||
"name": "Occupied"
|
||||
@@ -279,7 +279,7 @@
|
||||
{
|
||||
"info": "Struct",
|
||||
"lookupIndex": 14,
|
||||
"lookupName": "MultisigPlainMultisigPlainTransaction",
|
||||
"lookupName": "MultisigPlainTransaction",
|
||||
"type": "{\"callee\":\"AccountId\",\"selector\":\"[u8;4]\",\"input\":\"Bytes\",\"transferredValue\":\"u128\",\"gasLimit\":\"u64\"}",
|
||||
"docs": [],
|
||||
"namespace": "multisig_plain::multisig_plain::Transaction",
|
||||
@@ -418,7 +418,7 @@
|
||||
{
|
||||
"info": "Tuple",
|
||||
"lookupIndex": 21,
|
||||
"type": "(u32,MultisigPlainMultisigPlainConfirmationStatus)",
|
||||
"type": "(u32,MultisigPlainConfirmationStatus)",
|
||||
"docs": [],
|
||||
"namespace": "",
|
||||
"sub": [
|
||||
@@ -433,7 +433,7 @@
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 22,
|
||||
"lookupName": "MultisigPlainMultisigPlainConfirmationStatus",
|
||||
"lookupName": "MultisigPlainConfirmationStatus",
|
||||
"type": "Lookup22"
|
||||
}
|
||||
]
|
||||
@@ -441,7 +441,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 22,
|
||||
"lookupName": "MultisigPlainMultisigPlainConfirmationStatus",
|
||||
"lookupName": "MultisigPlainConfirmationStatus",
|
||||
"type": "{\"_enum\":{\"Confirmed\":\"Null\",\"ConfirmationsNeeded\":\"u32\"}}",
|
||||
"docs": [],
|
||||
"namespace": "multisig_plain::multisig_plain::ConfirmationStatus",
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 4,
|
||||
"lookupName": "EnumExampleEnumExampleVariant",
|
||||
"type": "{\"_enum\":{\"None\":\"Null\",\"Weekday\":\"EnumExampleEnumExampleWeekday\",\"TupleMaybeSigned\":\"EnumExampleEnumExampleTupleMaybeSigned\",\"NamedMaybeSigned\":\"EnumExampleEnumExampleNamedMaybeSigned\",\"Color\":\"EnumExampleEnumExampleColor\"}}",
|
||||
"lookupName": "EnumExampleVariant",
|
||||
"type": "{\"_enum\":{\"None\":\"Null\",\"Weekday\":\"EnumExampleWeekday\",\"TupleMaybeSigned\":\"EnumExampleTupleMaybeSigned\",\"NamedMaybeSigned\":\"EnumExampleNamedMaybeSigned\",\"Color\":\"EnumExampleColor\"}}",
|
||||
"docs": [],
|
||||
"namespace": "enum_example::enum_example::Variant",
|
||||
"sub": [
|
||||
@@ -38,7 +38,7 @@
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 5,
|
||||
"lookupName": "EnumExampleEnumExampleWeekday",
|
||||
"lookupName": "EnumExampleWeekday",
|
||||
"type": "Lookup5",
|
||||
"index": 1,
|
||||
"name": "Weekday"
|
||||
@@ -47,7 +47,7 @@
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 6,
|
||||
"lookupName": "EnumExampleEnumExampleTupleMaybeSigned",
|
||||
"lookupName": "EnumExampleTupleMaybeSigned",
|
||||
"type": "Lookup6",
|
||||
"index": 2,
|
||||
"name": "TupleMaybeSigned"
|
||||
@@ -56,7 +56,7 @@
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 7,
|
||||
"lookupName": "EnumExampleEnumExampleNamedMaybeSigned",
|
||||
"lookupName": "EnumExampleNamedMaybeSigned",
|
||||
"type": "Lookup7",
|
||||
"index": 3,
|
||||
"name": "NamedMaybeSigned"
|
||||
@@ -65,7 +65,7 @@
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 8,
|
||||
"lookupName": "EnumExampleEnumExampleColor",
|
||||
"lookupName": "EnumExampleColor",
|
||||
"type": "Lookup8",
|
||||
"index": 4,
|
||||
"name": "Color"
|
||||
@@ -75,7 +75,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 5,
|
||||
"lookupName": "EnumExampleEnumExampleWeekday",
|
||||
"lookupName": "EnumExampleWeekday",
|
||||
"type": "{\"_enum\":[\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\",\"Sunday\"]}",
|
||||
"docs": [],
|
||||
"namespace": "enum_example::enum_example::Weekday",
|
||||
@@ -127,7 +127,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 6,
|
||||
"lookupName": "EnumExampleEnumExampleTupleMaybeSigned",
|
||||
"lookupName": "EnumExampleTupleMaybeSigned",
|
||||
"type": "{\"_enum\":{\"Signed\":\"i32\",\"Unsigned\":\"u32\"}}",
|
||||
"docs": [],
|
||||
"namespace": "enum_example::enum_example::TupleMaybeSigned",
|
||||
@@ -155,7 +155,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 7,
|
||||
"lookupName": "EnumExampleEnumExampleNamedMaybeSigned",
|
||||
"lookupName": "EnumExampleNamedMaybeSigned",
|
||||
"type": "{\"_enum\":{\"Signed\":\"{\\\"value\\\":\\\"i32\\\"}\",\"Unsigned\":\"{\\\"value\\\":\\\"u32\\\"}\"}}",
|
||||
"docs": [],
|
||||
"namespace": "enum_example::enum_example::NamedMaybeSigned",
|
||||
@@ -197,7 +197,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 8,
|
||||
"lookupName": "EnumExampleEnumExampleColor",
|
||||
"lookupName": "EnumExampleColor",
|
||||
"type": "{\"_enum\":{\"Red\":\"Null\",\"Blue\":\"Null\",\"Green\":\"Null\",\"Yellow\":\"Null\",\"Rgb\":\"{\\\"r\\\":\\\"u8\\\",\\\"g\\\":\\\"u8\\\",\\\"b\\\":\\\"u8\\\"}\",\"Rgba\":\"{\\\"r\\\":\\\"u8\\\",\\\"g\\\":\\\"u8\\\",\\\"b\\\":\\\"u8\\\",\\\"a\\\":\\\"u8\\\"}\"}}",
|
||||
"docs": [],
|
||||
"namespace": "enum_example::enum_example::Color",
|
||||
|
||||
@@ -164,44 +164,48 @@ function getAliasPath (path: SiPath): string | null {
|
||||
|
||||
/** @internal */
|
||||
function extractNameFlat (portable: PortableType[], lookupIndex: number, params: SiTypeParameter[], path: AnyString[], isInternal = false): Extract | null {
|
||||
const last = path.length - 1;
|
||||
const count = path.length;
|
||||
|
||||
// if we have no path or determined as a wrapper, we just skip it
|
||||
if (last === -1 || WRAPPERS.includes(path[last].toString())) {
|
||||
if (count === 0 || WRAPPERS.includes(path[count - 1].toString())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const parts: string[] = [];
|
||||
let name = '';
|
||||
const camels = new Array<string>(count);
|
||||
const lowers = new Array<string>(count);
|
||||
|
||||
for (let i = 0; i <= last; i++) {
|
||||
const p = stringPascalCase(
|
||||
// initially just create arrays of the camelCase and lowercase path
|
||||
// parts - we will check these to extract the final values. While
|
||||
// we have 2 loops here, we also don't do the same operation twice
|
||||
for (let i = 0; i < count; i++) {
|
||||
const c = stringPascalCase(
|
||||
isInternal
|
||||
? path[i].replace('pallet_', '')
|
||||
: path[i]
|
||||
);
|
||||
const l = p.toLowerCase();
|
||||
const l = c.toLowerCase();
|
||||
|
||||
if (
|
||||
(
|
||||
// Remove ::{generic, misc, pallet, traits, types}::
|
||||
i !== 1 ||
|
||||
!PATH_RM_INDEX_1.includes(l)
|
||||
) &&
|
||||
(
|
||||
// sp_runtime::generic::digest::Digest -> sp_runtime::generic::Digest
|
||||
// sp_runtime::multiaddress::MultiAddress -> sp_runtime::MultiAddress
|
||||
i === last ||
|
||||
l !== path[i + 1].toLowerCase()
|
||||
)
|
||||
) {
|
||||
parts.push(p);
|
||||
name += p;
|
||||
camels[i] = c;
|
||||
lowers[i] = l;
|
||||
}
|
||||
|
||||
let name = '';
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const l = lowers[i];
|
||||
|
||||
// Remove ::{generic, misc, pallet, traits, types}::
|
||||
if (i !== 1 || !PATH_RM_INDEX_1.includes(l)) {
|
||||
// sp_runtime::generic::digest::Digest -> sp_runtime::generic::Digest
|
||||
// sp_runtime::multiaddress::MultiAddress -> sp_runtime::MultiAddress
|
||||
if (l !== lowers[i + 1]) {
|
||||
name += camels[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// do magic for RawOrigin lookup, e.g. pallet_collective::RawOrigin
|
||||
if (parts.length === 2 && parts[1] === 'RawOrigin' && params.length === 2 && params[1].type.isSome) {
|
||||
if (camels[1] === 'RawOrigin' && count === 2 && params.length === 2 && params[1].type.isSome) {
|
||||
const instanceType = portable[params[1].type.unwrap().toNumber()];
|
||||
|
||||
if (instanceType.type.path.length === 2) {
|
||||
@@ -301,12 +305,11 @@ function removeDupeNames (lookup: PortableRegistry, portable: PortableType[], na
|
||||
// not just the first
|
||||
// find the first parameter that yields differences
|
||||
const paramIdx = params.findIndex(({ type }, index) =>
|
||||
allSame.every(({ params }) =>
|
||||
params[index].type.isSome
|
||||
) &&
|
||||
allSame.every(({ params }, aIndex) =>
|
||||
aIndex === 0 ||
|
||||
!params[index].type.eq(type)
|
||||
params[index].type.isSome && (
|
||||
aIndex === 0 ||
|
||||
!params[index].type.eq(type)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user