Skip to content

Commit

Permalink
Merge pull request #37 from soramitsu/develop
Browse files Browse the repository at this point in the history
v0.10.0
  • Loading branch information
ERussel authored Jun 21, 2021
2 parents 4a44ab5 + 2774cae commit 3a09366
Show file tree
Hide file tree
Showing 40 changed files with 2,356 additions and 566 deletions.
12 changes: 12 additions & 0 deletions Example/FearlessUtils.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
84452C8325D3F97F00F47EC5 /* GenericEventNodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84452C8225D3F97F00F47EC5 /* GenericEventNodeTests.swift */; };
84452C9B25D40B5600F47EC5 /* RegexReplaceResolverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84452C9A25D40B5600F47EC5 /* RegexReplaceResolverTests.swift */; };
84452D9325D48FC100F47EC5 /* ExtrinsicNodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84452D9225D48FC100F47EC5 /* ExtrinsicNodeTests.swift */; };
8459EA0E2657961F006BBF9E /* FundInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459EA0D2657961F006BBF9E /* FundInfo.swift */; };
8459EA122657963C006BBF9E /* MultiSigner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459EA112657963C006BBF9E /* MultiSigner.swift */; };
8459EA162657987D006BBF9E /* LastContribution.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459EA152657987D006BBF9E /* LastContribution.swift */; };
845D80ED24C8D91A00EC2540 /* SeedFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845D80EC24C8D91A00EC2540 /* SeedFactoryTests.swift */; };
8467FD1424E677C2005D486C /* ed25519HDKD.json in Resources */ = {isa = PBXBuildFile; fileRef = 8467FD1124E675D0005D486C /* ed25519HDKD.json */; };
8467FD1524E677C6005D486C /* ecdsaHDKD.json in Resources */ = {isa = PBXBuildFile; fileRef = 8467FD1024E675D0005D486C /* ecdsaHDKD.json */; };
Expand Down Expand Up @@ -151,6 +154,9 @@
84452C8225D3F97F00F47EC5 /* GenericEventNodeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericEventNodeTests.swift; sourceTree = "<group>"; };
84452C9A25D40B5600F47EC5 /* RegexReplaceResolverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegexReplaceResolverTests.swift; sourceTree = "<group>"; };
84452D9225D48FC100F47EC5 /* ExtrinsicNodeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtrinsicNodeTests.swift; sourceTree = "<group>"; };
8459EA0D2657961F006BBF9E /* FundInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FundInfo.swift; sourceTree = "<group>"; };
8459EA112657963C006BBF9E /* MultiSigner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiSigner.swift; sourceTree = "<group>"; };
8459EA152657987D006BBF9E /* LastContribution.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LastContribution.swift; sourceTree = "<group>"; };
845D80EC24C8D91A00EC2540 /* SeedFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedFactoryTests.swift; sourceTree = "<group>"; };
8467FD1024E675D0005D486C /* ecdsaHDKD.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ecdsaHDKD.json; sourceTree = "<group>"; };
8467FD1124E675D0005D486C /* ed25519HDKD.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ed25519HDKD.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -507,6 +513,9 @@
84F43A7725DC827A00AEDA56 /* TransientValidationData.swift */,
84F43B6F25DE90EC00AEDA56 /* TransferArgs.swift */,
84F30E4625FC05BE00039D09 /* SessionKeysPolkadot.swift */,
8459EA0D2657961F006BBF9E /* FundInfo.swift */,
8459EA112657963C006BBF9E /* MultiSigner.swift */,
8459EA152657987D006BBF9E /* LastContribution.swift */,
);
path = RuntimeTypes;
sourceTree = "<group>";
Expand Down Expand Up @@ -793,6 +802,7 @@
84DA3B4324C8CE5A00B5E27F /* ScaleStringTests.swift in Sources */,
84DA3B4224C8CE5A00B5E27F /* ScaleUInt64Tests.swift in Sources */,
849E0A7A25C94E3F00B33506 /* EnumMappingFactoryTests.swift in Sources */,
8459EA162657987D006BBF9E /* LastContribution.swift in Sources */,
84452B0325D27BDB00F47EC5 /* DataNodeTests.swift in Sources */,
84F30E4725FC05BE00039D09 /* SessionKeysPolkadot.swift in Sources */,
84FACC0425F799A900F32ED4 /* ChainDataCodingTests.swift in Sources */,
Expand All @@ -804,11 +814,13 @@
849E0AAC25C96C7800B33506 /* TupleNodeFactoryTests.swift in Sources */,
849E0A8225C95E2700B33506 /* NumericSetFactoryTests.swift in Sources */,
84DA3B4124C8CE5A00B5E27F /* ScaleInt32Tests.swift in Sources */,
8459EA0E2657961F006BBF9E /* FundInfo.swift in Sources */,
8467FD2624E71A37005D486C /* IconGenerationTests.swift in Sources */,
84F43A7D25DC82B200AEDA56 /* TransientValidationData.swift in Sources */,
84452C8325D3F97F00F47EC5 /* GenericEventNodeTests.swift in Sources */,
849E0A7E25C95C7F00B33506 /* EnumValuesFactoryTests.swift in Sources */,
842D1E2324C98CEA00C30A7A /* StorageKeyFactoryTests.swift in Sources */,
8459EA122657963C006BBF9E /* MultiSigner.swift in Sources */,
8467FD2824E72CCD005D486C /* HSLColorTests.swift in Sources */,
84FACC0C25F79D8600F32ED4 /* GenericHashTests.swift in Sources */,
842D1E2724C9B63300C30A7A /* ScaleOptionTests.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion FearlessUtils.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

s.homepage = 'https://github.com/soramitsu/fearless-utils-iOS'
Expand Down
2 changes: 1 addition & 1 deletion FearlessUtils/Classes/Common/StorageKeyFactory.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public protocol StorageKeyFactoryProtocol: class {
public protocol StorageKeyFactoryProtocol: AnyObject {
func createStorageKey(moduleName: String, storageName: String) throws -> Data

func createStorageKey(moduleName: String,
Expand Down
13 changes: 11 additions & 2 deletions FearlessUtils/Classes/Extrinsic/ExtrinsicBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import Foundation
import BigInt
import IrohaCrypto

public protocol ExtrinsicBuilderProtocol: class {
public protocol ExtrinsicBuilderProtocol: AnyObject {
func with<A: Codable>(address: A) throws -> Self
func with(nonce: UInt32) -> Self
func with(era: Era, blockHash: String) -> Self
func with(tip: BigUInt) -> Self
func with(shouldUseAtomicBatch: Bool) -> Self
func adding<T: RuntimeCallable>(call: T) throws -> Self

func signing(by signer: (Data) throws -> Data,
Expand Down Expand Up @@ -45,6 +46,7 @@ public final class ExtrinsicBuilder {
private var era: Era
private var tip: BigUInt
private var signature: ExtrinsicSignature?
private var shouldUseAtomicBatch: Bool = true

public init(specVersion: UInt32,
transactionVersion: UInt32,
Expand All @@ -67,8 +69,10 @@ public final class ExtrinsicBuilder {
return calls[0]
}

let callName = shouldUseAtomicBatch ? KnowRuntimeModule.Utitlity.batchAll : KnowRuntimeModule.Utitlity.batch

let call = RuntimeCall(moduleName: KnowRuntimeModule.Utitlity.name,
callName: KnowRuntimeModule.Utitlity.batch,
callName: callName,
args: BatchArgs(calls: calls))

guard metadata.getFunction(from: call.moduleName, with: call.callName) != nil else {
Expand Down Expand Up @@ -149,6 +153,11 @@ extension ExtrinsicBuilder: ExtrinsicBuilderProtocol {
return self
}

public func with(shouldUseAtomicBatch: Bool) -> Self {
self.shouldUseAtomicBatch = shouldUseAtomicBatch
return self
}

public func adding<T: RuntimeCallable>(call: T) throws -> Self {
let json = try call.toScaleCompatibleJSON()
calls.append(json)
Expand Down
9 changes: 8 additions & 1 deletion FearlessUtils/Classes/Runtime/BasisNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public struct BasisNodes {
GenericBlockNode(),
GenericCallNode(runtimeMetadata: runtimeMetadata),
GenericVoteNode(),
KeyValueNode(typeName: GenericType.hashMap.rawValue),
H160Node(),
H256Node(),
H512Node(),
Expand All @@ -47,7 +48,13 @@ public struct BasisNodes {
AccountIdAddressNode(),
ExtrinsicNode(),
ExtrinsicSignatureNode(runtimeMetadata: runtimeMetadata),
ExtrinsicExtraNode(runtimeMetadata: runtimeMetadata)
ExtrinsicExtraNode(runtimeMetadata: runtimeMetadata),
MappingNode.consensus,
MappingNode.seal,
MappingNode.sealv0,
MappingNode.preRuntime,
AliasNode(typeName: GenericType.voteWeight.rawValue, underlyingTypeName: PrimitiveType.u64.rawValue)
]
}

}
7 changes: 7 additions & 0 deletions FearlessUtils/Classes/Runtime/GenericType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public enum GenericType: String, CaseIterable {
case opaqueCall = "OpaqueCall"
case sessionKeys = "SessionKeysSubstrate"
case ecdsa = "EcdsaSignature"
case hashMap = "HashMap"
case signature = "Signature"
case voteWeight = "VoteWeight"
case consensus = "GenericConsensus"
case seal = "GenericSeal"
case sealv0 = "GenericSealV0"
case preRuntime = "GenericPreRuntime"

public var name: String { rawValue }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public struct KnowRuntimeModule {
public struct Utitlity {
public static let name = "Utility"
public static let batch = "batch"
public static let batchAll = "batch_all"
}
}
19 changes: 19 additions & 0 deletions FearlessUtils/Classes/Runtime/Nodes/Items/AliasNode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Foundation

public class AliasNode: Node {
public let typeName: String
public let underlyingTypeName: String

public init(typeName: String, underlyingTypeName: String) {
self.typeName = typeName
self.underlyingTypeName = underlyingTypeName
}

public func accept(encoder: DynamicScaleEncoding, value: JSON) throws {
try encoder.append(json: value, type: underlyingTypeName)
}

public func accept(decoder: DynamicScaleDecoding) throws -> JSON {
try decoder.read(type: underlyingTypeName)
}
}
4 changes: 1 addition & 3 deletions FearlessUtils/Classes/Runtime/Nodes/Items/DataNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public class DataNode: Node {
}

public func accept(decoder: DynamicScaleDecoding) throws -> JSON {
guard let chainData: ChainData = try decoder.read() else {
return .null
}
let chainData: ChainData = try decoder.read()

switch chainData {
case .none:
Expand Down
4 changes: 1 addition & 3 deletions FearlessUtils/Classes/Runtime/Nodes/Items/EraNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ public class EraNode: Node {
}

public func accept(decoder: DynamicScaleDecoding) throws -> JSON {
guard let era: Era = try decoder.read() else {
return .null
}
let era: Era = try decoder.read()

return try era.toScaleCompatibleJSON()
}
Expand Down
7 changes: 2 additions & 5 deletions FearlessUtils/Classes/Runtime/Nodes/Items/ExtrinsicNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ public class ExtrinsicNode: Node {

public func accept(decoder: DynamicScaleDecoding) throws -> JSON {
// read and ignore extrinsic length
let _: BigUInt? = try decoder.read()

guard let version: UInt8 = try decoder.read() else {
throw ExtrinsicNodeError.invalidVersion
}
let _: BigUInt = try decoder.read()
let version: UInt8 = try decoder.read()

let isSigned = (version & ExtrinsicConstants.signedMask) != 0

Expand Down
35 changes: 35 additions & 0 deletions FearlessUtils/Classes/Runtime/Nodes/Items/KeyValueNode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Foundation

public class KeyValueNode: Node {
public let typeName: String

public init(typeName: String) {
self.typeName = typeName
}

public func accept(encoder: DynamicScaleEncoding, value: JSON) throws {
guard let mapping = value.dictValue else {
throw DynamicScaleEncoderError.dictExpected(json: value)
}

let tuples: [ScaleTuple<String, String>] = try mapping.enumerated().map { (_, element) in
guard let value = element.value.stringValue else {
throw DynamicScaleEncoderError.stringExpected(json: element.value)
}

return ScaleTuple(first: element.key, second: value)
}

try encoder.append(encodable: tuples)
}

public func accept(decoder: DynamicScaleDecoding) throws -> JSON {
let tuples: [ScaleTuple<String, String>] = try decoder.read()

let mapping = tuples.reduce(into: [String: JSON]()) { (result, item) in
result[item.first] = .stringValue(item.second)
}

return .dictionaryValue(mapping)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Foundation

public extension MappingNode {
static var consensus: MappingNode {
MappingNode(
typeName: GenericType.consensus.rawValue,
typeMapping: [
NamedType(name: "engineId", type: GenericType.consensusEngineId.name),
NamedType(name: "data", type: GenericType.bytes.rawValue)
])
}

static var seal: MappingNode {
MappingNode(
typeName: GenericType.seal.rawValue,
typeMapping: [
NamedType(name: "engineId", type: GenericType.consensusEngineId.name),
NamedType(name: "data", type: GenericType.bytes.rawValue)
])
}

static var sealv0: MappingNode {
MappingNode(
typeName: GenericType.sealv0.rawValue,
typeMapping: [
NamedType(name: "slot", type: PrimitiveType.u64.rawValue),
NamedType(name: "signature", type: GenericType.signature.rawValue)
])
}

static var preRuntime: MappingNode {
MappingNode(
typeName: GenericType.preRuntime.rawValue,
typeMapping: [
NamedType(name: "engineId", type: GenericType.consensusEngineId.name),
NamedType(name: "data", type: GenericType.bytes.rawValue)
])
}
}
2 changes: 1 addition & 1 deletion FearlessUtils/Classes/Runtime/Nodes/Items/ProxyNode.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public protocol NodeResolver: class {
public protocol NodeResolver: AnyObject {
func resolve(for key: String) -> Node?
}

Expand Down
2 changes: 1 addition & 1 deletion FearlessUtils/Classes/Runtime/Nodes/Items/TypeNode.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public protocol Node: class, DynamicScaleCodable {
public protocol Node: AnyObject, DynamicScaleCodable {
var typeName: String { get }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public extension RegexReplaceResolver {
}

static func genericsFilter() -> RegexReplaceResolver {
let pattern = "(<.+>)$"
// match generic type which can span multiple lines
let pattern = "(?s)(<.+>)$"
return RegexReplaceResolver(pattern: pattern, replacement: "")
}
}
2 changes: 2 additions & 0 deletions FearlessUtils/Classes/Scale/CodableWrappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ public struct NullCodable<T: Codable>: Codable {
}
}
}

extension NullCodable: Equatable where T: Equatable {}
3 changes: 1 addition & 2 deletions FearlessUtils/Classes/Scale/DynamicScaleCoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public protocol DynamicScaleDecoding {
func readU128() throws -> JSON
func readU256() throws -> JSON
func readBool() throws -> JSON
func read<T: ScaleCodable>() throws -> T?
func read<T: ScaleCodable>() throws -> T
}

public protocol DynamicScaleDecodable {
Expand All @@ -53,5 +53,4 @@ public typealias DynamicScaleCodable = DynamicScaleEncodable & DynamicScaleDecod

enum ScaleCodingModifier {
case compact
case option
}
1 change: 1 addition & 0 deletions FearlessUtils/Classes/Scale/DynamicScaleCodingError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum DynamicScaleEncoderError: Error {
case unexpectedEnumValues(value: UInt64, count: Int)
case unexpectedTupleJSON(json: JSON)
case unexpectedTupleComponents(count: Int, actual: Int)
case stringExpected(json: JSON)
}

public enum DynamicScaleDecoderError: Error {
Expand Down
Loading

0 comments on commit 3a09366

Please sign in to comment.