From 3e3b83255392b5e31533972882b8c190d3f066dd Mon Sep 17 00:00:00 2001 From: Russel Date: Sun, 9 Oct 2022 11:46:25 +0500 Subject: [PATCH] add fallback to alternative batch name --- SubstrateSdk.podspec | 2 +- .../Classes/Extrinsic/ExtrinsicBuilder.swift | 14 ++++++++++++-- .../Runtime/Metadata/KnownRuntimeModule.swift | 3 ++- Tests/ExtrinsicBuilder/ExtrinsicBuilderTests.swift | 8 ++++---- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/SubstrateSdk.podspec b/SubstrateSdk.podspec index 89f0c22..f5ec761 100644 --- a/SubstrateSdk.podspec +++ b/SubstrateSdk.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'SubstrateSdk' - s.version = '1.4.1' + s.version = '1.5.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' diff --git a/SubstrateSdk/Classes/Extrinsic/ExtrinsicBuilder.swift b/SubstrateSdk/Classes/Extrinsic/ExtrinsicBuilder.swift index 11f2b4c..514fa78 100644 --- a/SubstrateSdk/Classes/Extrinsic/ExtrinsicBuilder.swift +++ b/SubstrateSdk/Classes/Extrinsic/ExtrinsicBuilder.swift @@ -92,9 +92,19 @@ public class ExtrinsicBuilder { return calls[0] } - let callName = shouldUseAtomicBatch ? KnowRuntimeModule.Utitlity.batchAll : KnowRuntimeModule.Utitlity.batch + let callName: String + + if shouldUseAtomicBatch { + if metadata.getCall(from: KnowRuntimeModule.Utility.name, with: KnowRuntimeModule.Utility.batchAll) != nil { + callName = KnowRuntimeModule.Utility.batchAll + } else { + callName = KnowRuntimeModule.Utility.batchAtomic + } + } else { + callName = KnowRuntimeModule.Utility.batch + } - let call = RuntimeCall(moduleName: KnowRuntimeModule.Utitlity.name, + let call = RuntimeCall(moduleName: KnowRuntimeModule.Utility.name, callName: callName, args: BatchArgs(calls: calls)) diff --git a/SubstrateSdk/Classes/Runtime/Metadata/KnownRuntimeModule.swift b/SubstrateSdk/Classes/Runtime/Metadata/KnownRuntimeModule.swift index 4ed1db6..1965446 100644 --- a/SubstrateSdk/Classes/Runtime/Metadata/KnownRuntimeModule.swift +++ b/SubstrateSdk/Classes/Runtime/Metadata/KnownRuntimeModule.swift @@ -1,9 +1,10 @@ import Foundation public struct KnowRuntimeModule { - public struct Utitlity { + public struct Utility { public static let name = "Utility" public static let batch = "batch" public static let batchAll = "batch_all" + public static let batchAtomic = "batch_atomic" } } diff --git a/Tests/ExtrinsicBuilder/ExtrinsicBuilderTests.swift b/Tests/ExtrinsicBuilder/ExtrinsicBuilderTests.swift index 3d55ba0..bcd1f17 100644 --- a/Tests/ExtrinsicBuilder/ExtrinsicBuilderTests.swift +++ b/Tests/ExtrinsicBuilder/ExtrinsicBuilderTests.swift @@ -26,8 +26,8 @@ class ExtrinsicBuilderTests: XCTestCase { } let expectedJsonCalls = try calls.toScaleCompatibleJSON() - let expectedCall = try RuntimeCall(moduleName: KnowRuntimeModule.Utitlity.name, - callName: KnowRuntimeModule.Utitlity.batch, + let expectedCall = try RuntimeCall(moduleName: KnowRuntimeModule.Utility.name, + callName: KnowRuntimeModule.Utility.batch, args: BatchArgs(calls: expectedJsonCalls.arrayValue!)) .toScaleCompatibleJSON() @@ -64,8 +64,8 @@ class ExtrinsicBuilderTests: XCTestCase { } let expectedJsonCalls = try calls.toScaleCompatibleJSON() - let expectedCall = try RuntimeCall(moduleName: KnowRuntimeModule.Utitlity.name, - callName: KnowRuntimeModule.Utitlity.batchAll, + let expectedCall = try RuntimeCall(moduleName: KnowRuntimeModule.Utility.name, + callName: KnowRuntimeModule.Utility.batchAll, args: BatchArgs(calls: expectedJsonCalls.arrayValue!)) .toScaleCompatibleJSON()