Skip to content

Commit

Permalink
Merge pull request #47 from novasamatech/fix/default-types-derivative
Browse files Browse the repository at this point in the history
fix types derivation
  • Loading branch information
ERussel authored Jan 5, 2024
2 parents b35098f + 6dbf16e commit 6ba51da
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion SubstrateSdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'SubstrateSdk'
s.version = '1.15.0'
s.version = '1.16.0'
s.summary = 'Utility library that implements clients specific logic to interact with substrate based networks'

s.homepage = 'https://github.com/nova-wallet/substrate-sdk-ios'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public extension RuntimeType {
public var pathBasedName: String? {
!path.isEmpty ? path.joined(separator: ".") : nil
}

public static func pathFromName(_ name: String) -> [String] {
name.components(separatedBy: ".")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ public final class RuntimeAugmentationFactory: RuntimeAugmentationFactoryProtoco
let runtimeType = "frame_support.dispatch.DispatchInfo"

guard
let portableType = RuntimeMetadataSearchEngine.findPortableType(
let portableType = RuntimeMetadataSearchEngine.findPortableTypes(
for: runtimeType,
in: runtime,
mode: .firstLastComponents
),
).first,
case let .composite(compositeType) = portableType.type.typeDefinition else {
return additionalNodes.adding(notMatchedType: feeType)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import Foundation

public enum RuntimeMetadataSearchEngine {
public static func findPortableType(
public static func findPortableTypes(
for type: String,
in metadata: RuntimeMetadataV14,
mode: RuntimeTypeMatchingMode
) -> PortableType? {
) -> [PortableType] {
switch mode {
case .full:
let path = RuntimeType.pathFromName(type)
return metadata.types.types.first(where: { $0.type.path == path })
return metadata.types.types.filter({ $0.type.path == path })
case .lastComponent:
let component = RuntimeType.pathFromName(type).last

return metadata.types.types.first(where: { $0.type.path.last == component })
return metadata.types.types.filter({ $0.type.path.last == component })
case .firstLastComponents:
let path = RuntimeType.pathFromName(type)
let first = path.first
let last = path.last

return metadata.types.types.first(
where: { $0.type.path.first == first && $0.type.path.last == last }
return metadata.types.types.filter(
{ $0.type.path.first == first && $0.type.path.last == last }
)
}
}
Expand All @@ -31,7 +31,7 @@ public enum RuntimeMetadataSearchEngine {
in metadata: RuntimeMetadataV14,
mode: RuntimeTypeMatchingMode
) -> String? {
guard let type = findPortableType(for: mainType, in: metadata, mode: mode) else {
guard let type = findPortableTypes(for: mainType, in: metadata, mode: mode).first else {
return nil
}

Expand All @@ -45,6 +45,16 @@ public enum RuntimeMetadataSearchEngine {
}

public static func find(type: String, in metadata: RuntimeMetadataV14, mode: RuntimeTypeMatchingMode) -> String? {
findPortableType(for: type, in: metadata, mode: mode)?.type.pathBasedName
let types = findPortableTypes(for: type, in: metadata, mode: mode)

guard !types.isEmpty else {
return nil
}

if types.count > 1 {
return types.first?.type.pathBasedName
} else {
return types.first.map { String($0.identifier) }
}
}
}

0 comments on commit 6ba51da

Please sign in to comment.