Skip to content

Commit ba66ff8

Browse files
authored
Merge pull request #65 from novasamatech/feature/runtime-api-in-v15
Add support for runtime api for v15
2 parents c871bf2 + b4c1a6e commit ba66ff8

9 files changed

+146
-18
lines changed

Example/Podfile

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ target 'SubstrateSdkExample' do
55
pod 'Operation-iOS', :git => 'https://github.com/novasamatech/Operation-iOS.git', :tag => '2.0.1'
66
pod 'Starscream', :git => 'https://github.com/ERussel/Starscream.git', :branch => 'feature/without-origin'
77
pod 'SwiftLint'
8+
pod 'IrohaCrypto', :git => 'https://github.com/novasamatech/IrohaCrypto', :tag => '0.9.1'
9+
pod 'secp256k1.c', :git => 'https://github.com/novasamatech/secp256k1.c', :tag => '0.1.3'
810

911
target 'SubstrateSdkTests' do
1012
inherit! :search_paths

Example/Podfile.lock

+40-16
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,43 @@
11
PODS:
22
- BigInt (5.2.0)
3-
- IrohaCrypto/BIP39 (0.9.0):
3+
- IrohaCrypto (0.9.1):
4+
- IrohaCrypto/BIP39 (= 0.9.1)
5+
- IrohaCrypto/blake2 (= 0.9.1)
6+
- IrohaCrypto/Common (= 0.9.1)
7+
- IrohaCrypto/ed25519 (= 0.9.1)
8+
- IrohaCrypto/Iroha (= 0.9.1)
9+
- IrohaCrypto/Scrypt (= 0.9.1)
10+
- IrohaCrypto/secp256k1 (= 0.9.1)
11+
- IrohaCrypto/sr25519 (= 0.9.1)
12+
- IrohaCrypto/ss58 (= 0.9.1)
13+
- IrohaCrypto/BIP39 (0.9.1):
414
- IrohaCrypto/Common
5-
- IrohaCrypto/blake2 (0.9.0)
6-
- IrohaCrypto/Common (0.9.0)
7-
- IrohaCrypto/ed25519 (0.9.0):
15+
- IrohaCrypto/blake2 (0.9.1)
16+
- IrohaCrypto/Common (0.9.1)
17+
- IrohaCrypto/ed25519 (0.9.1):
818
- IrohaCrypto/Common
9-
- IrohaCrypto/Scrypt (0.9.0):
19+
- IrohaCrypto/Iroha (0.9.1):
20+
- IrohaCrypto/Common
21+
- IrohaCrypto/Scrypt (0.9.1):
1022
- IrohaCrypto/Common
1123
- scrypt.c (~> 0.1)
12-
- IrohaCrypto/secp256k1 (0.9.0):
24+
- IrohaCrypto/secp256k1 (0.9.1):
1325
- IrohaCrypto/Common
1426
- secp256k1.c (~> 0.1)
15-
- IrohaCrypto/sr25519 (0.9.0):
27+
- IrohaCrypto/sr25519 (0.9.1):
1628
- IrohaCrypto/BIP39
1729
- IrohaCrypto/blake2
1830
- IrohaCrypto/Common
19-
- IrohaCrypto/ss58 (0.9.0):
31+
- IrohaCrypto/ss58 (0.9.1):
2032
- IrohaCrypto/blake2
2133
- IrohaCrypto/Common
2234
- keccak.c (0.1.3)
2335
- Operation-iOS (2.0.1)
2436
- ReachabilitySwift (5.2.4)
2537
- scrypt.c (0.1.1)
26-
- secp256k1.c (0.1.2)
38+
- secp256k1.c (0.1.3)
2739
- Starscream (4.0.4)
28-
- SubstrateSdk (3.3.2):
40+
- SubstrateSdk (3.4.0):
2941
- BigInt (~> 5.0)
3042
- IrohaCrypto/ed25519 (~> 0.9.0)
3143
- IrohaCrypto/Scrypt (~> 0.9.0)
@@ -43,55 +55,67 @@ PODS:
4355
- xxHash-Swift (1.0.13)
4456

4557
DEPENDENCIES:
58+
- IrohaCrypto (from `https://github.com/novasamatech/IrohaCrypto`, tag `0.9.1`)
4659
- Operation-iOS (from `https://github.com/novasamatech/Operation-iOS.git`, tag `2.0.1`)
60+
- secp256k1.c (from `https://github.com/novasamatech/secp256k1.c`, tag `0.1.3`)
4761
- Starscream (from `https://github.com/ERussel/Starscream.git`, branch `feature/without-origin`)
4862
- SubstrateSdk (from `../`)
4963
- SwiftLint
5064

5165
SPEC REPOS:
5266
trunk:
5367
- BigInt
54-
- IrohaCrypto
5568
- keccak.c
5669
- ReachabilitySwift
5770
- scrypt.c
58-
- secp256k1.c
5971
- SwiftLint
6072
- TweetNacl
6173
- xxHash-Swift
6274

6375
EXTERNAL SOURCES:
76+
IrohaCrypto:
77+
:git: https://github.com/novasamatech/IrohaCrypto
78+
:tag: 0.9.1
6479
Operation-iOS:
6580
:git: https://github.com/novasamatech/Operation-iOS.git
6681
:tag: 2.0.1
82+
secp256k1.c:
83+
:git: https://github.com/novasamatech/secp256k1.c
84+
:tag: 0.1.3
6785
Starscream:
6886
:branch: feature/without-origin
6987
:git: https://github.com/ERussel/Starscream.git
7088
SubstrateSdk:
7189
:path: "../"
7290

7391
CHECKOUT OPTIONS:
92+
IrohaCrypto:
93+
:git: https://github.com/novasamatech/IrohaCrypto
94+
:tag: 0.9.1
7495
Operation-iOS:
7596
:git: https://github.com/novasamatech/Operation-iOS.git
7697
:tag: 2.0.1
98+
secp256k1.c:
99+
:git: https://github.com/novasamatech/secp256k1.c
100+
:tag: 0.1.3
77101
Starscream:
78102
:commit: b9e69390d96e71427463469f47cdafb8c0db1b21
79103
:git: https://github.com/ERussel/Starscream.git
80104

81105
SPEC CHECKSUMS:
82106
BigInt: f668a80089607f521586bbe29513d708491ef2f7
83-
IrohaCrypto: 6be75a4268cd1f5cec4231c6d3f95cb03f723fd3
107+
IrohaCrypto: b53a7f16c839a1a76936402ffe35f496eaa8cbb0
84108
keccak.c: 859583afdaccb4e4fcc0f0096064d101580313f4
85109
Operation-iOS: 5f1c2cb82bf10f46b92faefc92d5821550b14eb5
86110
ReachabilitySwift: 32793e867593cfc1177f5d16491e3a197d2fccda
87111
scrypt.c: b42ae06183251329d2b2c620c226fb541a4a3592
88-
secp256k1.c: db47b726585d80f027423682eb369729e61b3b20
112+
secp256k1.c: 9df12a79da0a6735022c5d996d2df6a6e57e1d99
89113
Starscream: 5178aed56b316f13fa3bc55694e583d35dd414d9
90-
SubstrateSdk: a5af2260b57982600f2f852f53e9408a024f8cbb
114+
SubstrateSdk: ee92f2ede60ffc3a80c73d57870c2cea05741ab4
91115
SwiftLint: 4fa9579c63416865179bc416f0a92d55f009600d
92116
TweetNacl: 3abf4d1d2082b0114e7a67410e300892448951e6
93117
xxHash-Swift: 30bd6a7507b3b7348a277c49b1cb6346c2905ec7
94118

95-
PODFILE CHECKSUM: 157538d05d1fb55023eefa284e3e1237dbd4e2e6
119+
PODFILE CHECKSUM: 62e174568457e9c60da708e29cfd1993e7b3c847
96120

97121
COCOAPODS: 1.15.2

SubstrateSdk.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'SubstrateSdk'
11-
s.version = '3.3.2'
11+
s.version = '3.4.0'
1212
s.summary = 'Utility library that implements clients specific logic to interact with substrate based networks'
1313

1414
s.homepage = 'https://github.com/nova-wallet/substrate-sdk-ios'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Foundation
2+
import BigInt
3+
4+
public struct RuntimeApiMetadata {
5+
public let name: String
6+
public let methods: [RuntimeApiMethodMetadata]
7+
public let docs: [String]
8+
}
9+
10+
extension RuntimeApiMetadata: ScaleCodable {
11+
public func encode(scaleEncoder: ScaleEncoding) throws {
12+
try name.encode(scaleEncoder: scaleEncoder)
13+
try methods.encode(scaleEncoder: scaleEncoder)
14+
try docs.encode(scaleEncoder: scaleEncoder)
15+
}
16+
17+
public init(scaleDecoder: ScaleDecoding) throws {
18+
name = try String(scaleDecoder: scaleDecoder)
19+
methods = try [RuntimeApiMethodMetadata](scaleDecoder: scaleDecoder)
20+
docs = try [String](scaleDecoder: scaleDecoder)
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import Foundation
2+
import BigInt
3+
4+
public struct RuntimeApiMethodMetadata {
5+
public let name: String
6+
public let inputs: [RuntimeApiMethodParamMetadata]
7+
public let output: SiLookupId
8+
public let docs: [String]
9+
}
10+
11+
extension RuntimeApiMethodMetadata: ScaleCodable {
12+
public func encode(scaleEncoder: ScaleEncoding) throws {
13+
try name.encode(scaleEncoder: scaleEncoder)
14+
try inputs.encode(scaleEncoder: scaleEncoder)
15+
try BigUInt(output).encode(scaleEncoder: scaleEncoder)
16+
try docs.encode(scaleEncoder: scaleEncoder)
17+
}
18+
19+
public init(scaleDecoder: ScaleDecoding) throws {
20+
name = try String(scaleDecoder: scaleDecoder)
21+
inputs = try [RuntimeApiMethodParamMetadata](scaleDecoder: scaleDecoder)
22+
output = try SiLookupId(BigUInt(scaleDecoder: scaleDecoder))
23+
docs = try [String](scaleDecoder: scaleDecoder)
24+
}
25+
}
26+
27+
public struct RuntimeApiMethodParamMetadata {
28+
public let name: String
29+
public let paramType: SiLookupId
30+
}
31+
32+
extension RuntimeApiMethodParamMetadata: ScaleCodable {
33+
public func encode(scaleEncoder: ScaleEncoding) throws {
34+
try name.encode(scaleEncoder: scaleEncoder)
35+
try BigUInt(paramType).encode(scaleEncoder: scaleEncoder)
36+
}
37+
38+
public init(scaleDecoder: ScaleDecoding) throws {
39+
name = try String(scaleDecoder: scaleDecoder)
40+
paramType = try SiLookupId(BigUInt(scaleDecoder: scaleDecoder))
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Foundation
2+
3+
public struct RuntimeApiQueryResult {
4+
public let callName: String
5+
public let method: RuntimeApiMethodMetadata
6+
7+
public init(callName: String, method: RuntimeApiMethodMetadata) {
8+
self.callName = callName
9+
self.method = method
10+
}
11+
}

SubstrateSdk/Classes/Runtime/Metadata/RuntimeMetadata.swift

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public protocol RuntimeMetadataProtocol {
1616
func getConstant(in moduleName: String, constantName: String) -> ModuleConstantMetadata?
1717

1818
func getEventForModuleIndex(_ moduleIndex: UInt8, eventIndex: UInt32) -> EventMetadata?
19+
20+
func getRuntimeApiMethod(for runtimeApiName: String, methodName: String) -> RuntimeApiQueryResult?
1921

2022
func getSignedExtensions() -> [String]
2123

@@ -96,6 +98,10 @@ public struct RuntimeMetadata: RuntimeMetadataProtocol {
9698
// types are not stored onchain for pre 14 runtime
9799
nil
98100
}
101+
102+
public func getRuntimeApiMethod(for runtimeApiName: String, methodName: String) -> RuntimeApiQueryResult? {
103+
nil
104+
}
99105
}
100106

101107
extension RuntimeMetadata: ScaleCodable {

SubstrateSdk/Classes/Runtime/Metadata/V14/RuntimeMetadataV14.swift

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ extension RuntimeMetadataV14: PostV14RuntimeMetadataProtocol {
2828
public var postV14Extrinsic: PostV14ExtrinsicMetadataProtocol {
2929
extrinsic
3030
}
31+
32+
public func getRuntimeApiMethod(for runtimeApiName: String, methodName: String) -> RuntimeApiQueryResult? {
33+
nil
34+
}
3135
}
3236

3337
extension RuntimeMetadataV14: ScaleCodable {

SubstrateSdk/Classes/Runtime/Metadata/V15/RuntimeMetadataV15.swift

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ public struct RuntimeMetadataV15 {
66
public let pallets: [PalletMetadataV15]
77
public let extrinsic: ExtrinsicMetadataV15
88
public let runtimeType: SiLookupId
9+
public let apis: [RuntimeApiMetadata]
910

1011
public init(
1112
types: RuntimeTypesLookup,
1213
pallets: [PalletMetadataV15],
1314
extrinsic: ExtrinsicMetadataV15,
14-
runtimeType: SiLookupId
15+
runtimeType: SiLookupId,
16+
apis: [RuntimeApiMetadata]
1517
) {
1618
self.types = types
1719
self.pallets = pallets
1820
self.extrinsic = extrinsic
1921
self.runtimeType = runtimeType
22+
self.apis = apis
2023
}
2124
}
2225

@@ -28,6 +31,18 @@ extension RuntimeMetadataV15: PostV14RuntimeMetadataProtocol {
2831
public var postV14Extrinsic: PostV14ExtrinsicMetadataProtocol {
2932
extrinsic
3033
}
34+
35+
public func getRuntimeApiMethod(for runtimeApiName: String, methodName: String) -> RuntimeApiQueryResult? {
36+
guard let api = apis.first(where: { $0.name == runtimeApiName }) else {
37+
return nil
38+
}
39+
40+
guard let method = api.methods.first(where: { $0.name == methodName }) else {
41+
return nil
42+
}
43+
44+
return .init(callName: runtimeApiName + "_" + methodName, method: method)
45+
}
3146
}
3247

3348
extension RuntimeMetadataV15: ScaleCodable {
@@ -36,12 +51,14 @@ extension RuntimeMetadataV15: ScaleCodable {
3651
try pallets.encode(scaleEncoder: scaleEncoder)
3752
try extrinsic.encode(scaleEncoder: scaleEncoder)
3853
try BigUInt(runtimeType).encode(scaleEncoder: scaleEncoder)
54+
try apis.encode(scaleEncoder: scaleEncoder)
3955
}
4056

4157
public init(scaleDecoder: ScaleDecoding) throws {
4258
types = try RuntimeTypesLookup(scaleDecoder: scaleDecoder)
4359
pallets = try [PalletMetadataV15](scaleDecoder: scaleDecoder)
4460
extrinsic = try ExtrinsicMetadataV15(scaleDecoder: scaleDecoder)
4561
runtimeType = try SiLookupId(BigUInt(scaleDecoder: scaleDecoder))
62+
apis = try [RuntimeApiMetadata](scaleDecoder: scaleDecoder)
4663
}
4764
}

0 commit comments

Comments
 (0)