Skip to content

Commit

Permalink
Merge pull request #65 from novasamatech/feature/runtime-api-in-v15
Browse files Browse the repository at this point in the history
Add support for runtime api for v15
  • Loading branch information
ERussel authored Nov 19, 2024
2 parents c871bf2 + b4c1a6e commit ba66ff8
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ target 'SubstrateSdkExample' do
pod 'Operation-iOS', :git => 'https://github.com/novasamatech/Operation-iOS.git', :tag => '2.0.1'
pod 'Starscream', :git => 'https://github.com/ERussel/Starscream.git', :branch => 'feature/without-origin'
pod 'SwiftLint'
pod 'IrohaCrypto', :git => 'https://github.com/novasamatech/IrohaCrypto', :tag => '0.9.1'
pod 'secp256k1.c', :git => 'https://github.com/novasamatech/secp256k1.c', :tag => '0.1.3'

target 'SubstrateSdkTests' do
inherit! :search_paths
Expand Down
56 changes: 40 additions & 16 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
PODS:
- BigInt (5.2.0)
- IrohaCrypto/BIP39 (0.9.0):
- IrohaCrypto (0.9.1):
- IrohaCrypto/BIP39 (= 0.9.1)
- IrohaCrypto/blake2 (= 0.9.1)
- IrohaCrypto/Common (= 0.9.1)
- IrohaCrypto/ed25519 (= 0.9.1)
- IrohaCrypto/Iroha (= 0.9.1)
- IrohaCrypto/Scrypt (= 0.9.1)
- IrohaCrypto/secp256k1 (= 0.9.1)
- IrohaCrypto/sr25519 (= 0.9.1)
- IrohaCrypto/ss58 (= 0.9.1)
- IrohaCrypto/BIP39 (0.9.1):
- IrohaCrypto/Common
- IrohaCrypto/blake2 (0.9.0)
- IrohaCrypto/Common (0.9.0)
- IrohaCrypto/ed25519 (0.9.0):
- IrohaCrypto/blake2 (0.9.1)
- IrohaCrypto/Common (0.9.1)
- IrohaCrypto/ed25519 (0.9.1):
- IrohaCrypto/Common
- IrohaCrypto/Scrypt (0.9.0):
- IrohaCrypto/Iroha (0.9.1):
- IrohaCrypto/Common
- IrohaCrypto/Scrypt (0.9.1):
- IrohaCrypto/Common
- scrypt.c (~> 0.1)
- IrohaCrypto/secp256k1 (0.9.0):
- IrohaCrypto/secp256k1 (0.9.1):
- IrohaCrypto/Common
- secp256k1.c (~> 0.1)
- IrohaCrypto/sr25519 (0.9.0):
- IrohaCrypto/sr25519 (0.9.1):
- IrohaCrypto/BIP39
- IrohaCrypto/blake2
- IrohaCrypto/Common
- IrohaCrypto/ss58 (0.9.0):
- IrohaCrypto/ss58 (0.9.1):
- IrohaCrypto/blake2
- IrohaCrypto/Common
- keccak.c (0.1.3)
- Operation-iOS (2.0.1)
- ReachabilitySwift (5.2.4)
- scrypt.c (0.1.1)
- secp256k1.c (0.1.2)
- secp256k1.c (0.1.3)
- Starscream (4.0.4)
- SubstrateSdk (3.3.2):
- SubstrateSdk (3.4.0):
- BigInt (~> 5.0)
- IrohaCrypto/ed25519 (~> 0.9.0)
- IrohaCrypto/Scrypt (~> 0.9.0)
Expand All @@ -43,55 +55,67 @@ PODS:
- xxHash-Swift (1.0.13)

DEPENDENCIES:
- IrohaCrypto (from `https://github.com/novasamatech/IrohaCrypto`, tag `0.9.1`)
- Operation-iOS (from `https://github.com/novasamatech/Operation-iOS.git`, tag `2.0.1`)
- secp256k1.c (from `https://github.com/novasamatech/secp256k1.c`, tag `0.1.3`)
- Starscream (from `https://github.com/ERussel/Starscream.git`, branch `feature/without-origin`)
- SubstrateSdk (from `../`)
- SwiftLint

SPEC REPOS:
trunk:
- BigInt
- IrohaCrypto
- keccak.c
- ReachabilitySwift
- scrypt.c
- secp256k1.c
- SwiftLint
- TweetNacl
- xxHash-Swift

EXTERNAL SOURCES:
IrohaCrypto:
:git: https://github.com/novasamatech/IrohaCrypto
:tag: 0.9.1
Operation-iOS:
:git: https://github.com/novasamatech/Operation-iOS.git
:tag: 2.0.1
secp256k1.c:
:git: https://github.com/novasamatech/secp256k1.c
:tag: 0.1.3
Starscream:
:branch: feature/without-origin
:git: https://github.com/ERussel/Starscream.git
SubstrateSdk:
:path: "../"

CHECKOUT OPTIONS:
IrohaCrypto:
:git: https://github.com/novasamatech/IrohaCrypto
:tag: 0.9.1
Operation-iOS:
:git: https://github.com/novasamatech/Operation-iOS.git
:tag: 2.0.1
secp256k1.c:
:git: https://github.com/novasamatech/secp256k1.c
:tag: 0.1.3
Starscream:
:commit: b9e69390d96e71427463469f47cdafb8c0db1b21
:git: https://github.com/ERussel/Starscream.git

SPEC CHECKSUMS:
BigInt: f668a80089607f521586bbe29513d708491ef2f7
IrohaCrypto: 6be75a4268cd1f5cec4231c6d3f95cb03f723fd3
IrohaCrypto: b53a7f16c839a1a76936402ffe35f496eaa8cbb0
keccak.c: 859583afdaccb4e4fcc0f0096064d101580313f4
Operation-iOS: 5f1c2cb82bf10f46b92faefc92d5821550b14eb5
ReachabilitySwift: 32793e867593cfc1177f5d16491e3a197d2fccda
scrypt.c: b42ae06183251329d2b2c620c226fb541a4a3592
secp256k1.c: db47b726585d80f027423682eb369729e61b3b20
secp256k1.c: 9df12a79da0a6735022c5d996d2df6a6e57e1d99
Starscream: 5178aed56b316f13fa3bc55694e583d35dd414d9
SubstrateSdk: a5af2260b57982600f2f852f53e9408a024f8cbb
SubstrateSdk: ee92f2ede60ffc3a80c73d57870c2cea05741ab4
SwiftLint: 4fa9579c63416865179bc416f0a92d55f009600d
TweetNacl: 3abf4d1d2082b0114e7a67410e300892448951e6
xxHash-Swift: 30bd6a7507b3b7348a277c49b1cb6346c2905ec7

PODFILE CHECKSUM: 157538d05d1fb55023eefa284e3e1237dbd4e2e6
PODFILE CHECKSUM: 62e174568457e9c60da708e29cfd1993e7b3c847

COCOAPODS: 1.15.2
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 = '3.3.2'
s.version = '3.4.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
@@ -0,0 +1,22 @@
import Foundation
import BigInt

public struct RuntimeApiMetadata {
public let name: String
public let methods: [RuntimeApiMethodMetadata]
public let docs: [String]
}

extension RuntimeApiMetadata: ScaleCodable {
public func encode(scaleEncoder: ScaleEncoding) throws {
try name.encode(scaleEncoder: scaleEncoder)
try methods.encode(scaleEncoder: scaleEncoder)
try docs.encode(scaleEncoder: scaleEncoder)
}

public init(scaleDecoder: ScaleDecoding) throws {
name = try String(scaleDecoder: scaleDecoder)
methods = try [RuntimeApiMethodMetadata](scaleDecoder: scaleDecoder)
docs = try [String](scaleDecoder: scaleDecoder)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Foundation
import BigInt

public struct RuntimeApiMethodMetadata {
public let name: String
public let inputs: [RuntimeApiMethodParamMetadata]
public let output: SiLookupId
public let docs: [String]
}

extension RuntimeApiMethodMetadata: ScaleCodable {
public func encode(scaleEncoder: ScaleEncoding) throws {
try name.encode(scaleEncoder: scaleEncoder)
try inputs.encode(scaleEncoder: scaleEncoder)
try BigUInt(output).encode(scaleEncoder: scaleEncoder)
try docs.encode(scaleEncoder: scaleEncoder)
}

public init(scaleDecoder: ScaleDecoding) throws {
name = try String(scaleDecoder: scaleDecoder)
inputs = try [RuntimeApiMethodParamMetadata](scaleDecoder: scaleDecoder)
output = try SiLookupId(BigUInt(scaleDecoder: scaleDecoder))
docs = try [String](scaleDecoder: scaleDecoder)
}
}

public struct RuntimeApiMethodParamMetadata {
public let name: String
public let paramType: SiLookupId
}

extension RuntimeApiMethodParamMetadata: ScaleCodable {
public func encode(scaleEncoder: ScaleEncoding) throws {
try name.encode(scaleEncoder: scaleEncoder)
try BigUInt(paramType).encode(scaleEncoder: scaleEncoder)
}

public init(scaleDecoder: ScaleDecoding) throws {
name = try String(scaleDecoder: scaleDecoder)
paramType = try SiLookupId(BigUInt(scaleDecoder: scaleDecoder))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation

public struct RuntimeApiQueryResult {
public let callName: String
public let method: RuntimeApiMethodMetadata

public init(callName: String, method: RuntimeApiMethodMetadata) {
self.callName = callName
self.method = method
}
}
6 changes: 6 additions & 0 deletions SubstrateSdk/Classes/Runtime/Metadata/RuntimeMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public protocol RuntimeMetadataProtocol {
func getConstant(in moduleName: String, constantName: String) -> ModuleConstantMetadata?

func getEventForModuleIndex(_ moduleIndex: UInt8, eventIndex: UInt32) -> EventMetadata?

func getRuntimeApiMethod(for runtimeApiName: String, methodName: String) -> RuntimeApiQueryResult?

func getSignedExtensions() -> [String]

Expand Down Expand Up @@ -96,6 +98,10 @@ public struct RuntimeMetadata: RuntimeMetadataProtocol {
// types are not stored onchain for pre 14 runtime
nil
}

public func getRuntimeApiMethod(for runtimeApiName: String, methodName: String) -> RuntimeApiQueryResult? {
nil
}
}

extension RuntimeMetadata: ScaleCodable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ extension RuntimeMetadataV14: PostV14RuntimeMetadataProtocol {
public var postV14Extrinsic: PostV14ExtrinsicMetadataProtocol {
extrinsic
}

public func getRuntimeApiMethod(for runtimeApiName: String, methodName: String) -> RuntimeApiQueryResult? {
nil
}
}

extension RuntimeMetadataV14: ScaleCodable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ public struct RuntimeMetadataV15 {
public let pallets: [PalletMetadataV15]
public let extrinsic: ExtrinsicMetadataV15
public let runtimeType: SiLookupId
public let apis: [RuntimeApiMetadata]

public init(
types: RuntimeTypesLookup,
pallets: [PalletMetadataV15],
extrinsic: ExtrinsicMetadataV15,
runtimeType: SiLookupId
runtimeType: SiLookupId,
apis: [RuntimeApiMetadata]
) {
self.types = types
self.pallets = pallets
self.extrinsic = extrinsic
self.runtimeType = runtimeType
self.apis = apis
}
}

Expand All @@ -28,6 +31,18 @@ extension RuntimeMetadataV15: PostV14RuntimeMetadataProtocol {
public var postV14Extrinsic: PostV14ExtrinsicMetadataProtocol {
extrinsic
}

public func getRuntimeApiMethod(for runtimeApiName: String, methodName: String) -> RuntimeApiQueryResult? {
guard let api = apis.first(where: { $0.name == runtimeApiName }) else {
return nil
}

guard let method = api.methods.first(where: { $0.name == methodName }) else {
return nil
}

return .init(callName: runtimeApiName + "_" + methodName, method: method)
}
}

extension RuntimeMetadataV15: ScaleCodable {
Expand All @@ -36,12 +51,14 @@ extension RuntimeMetadataV15: ScaleCodable {
try pallets.encode(scaleEncoder: scaleEncoder)
try extrinsic.encode(scaleEncoder: scaleEncoder)
try BigUInt(runtimeType).encode(scaleEncoder: scaleEncoder)
try apis.encode(scaleEncoder: scaleEncoder)
}

public init(scaleDecoder: ScaleDecoding) throws {
types = try RuntimeTypesLookup(scaleDecoder: scaleDecoder)
pallets = try [PalletMetadataV15](scaleDecoder: scaleDecoder)
extrinsic = try ExtrinsicMetadataV15(scaleDecoder: scaleDecoder)
runtimeType = try SiLookupId(BigUInt(scaleDecoder: scaleDecoder))
apis = try [RuntimeApiMetadata](scaleDecoder: scaleDecoder)
}
}

0 comments on commit ba66ff8

Please sign in to comment.