Skip to content

Commit

Permalink
Merge pull request #13 from soramitsu/fix/storage-factory-improvements
Browse files Browse the repository at this point in the history
StorageKeyFactory improvements
  • Loading branch information
ERussel authored Oct 12, 2020
2 parents e9e06e9 + 36f1638 commit 6116358
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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.6.0'
s.version = '0.7.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
12 changes: 8 additions & 4 deletions FearlessUtils/Classes/Common/StorageKeyFactory.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation

public protocol StorageKeyFactoryProtocol {
func createStorageKey(moduleName: String, serviceName: String) throws -> Data
func createStorageKey(moduleName: String, serviceName: String, identifier: Data) throws -> Data
}

Expand All @@ -11,7 +12,7 @@ public enum StorageKeyFactoryError: Error {
public struct StorageKeyFactory: StorageKeyFactoryProtocol {
public init() {}

public func createStorageKey(moduleName: String, serviceName: String, identifier: Data) throws -> Data {
public func createStorageKey(moduleName: String, serviceName: String) throws -> Data {
guard let moduleKey = moduleName.data(using: .utf8) else {
throw StorageKeyFactoryError.badSerialization
}
Expand All @@ -20,11 +21,14 @@ public struct StorageKeyFactory: StorageKeyFactoryProtocol {
throw StorageKeyFactoryError.badSerialization
}

let moduleKeyHash = moduleKey.xxh128()
let serviceKeyHash = serviceKey.xxh128()
return moduleKey.xxh128() + serviceKey.xxh128()
}

public func createStorageKey(moduleName: String, serviceName: String, identifier: Data) throws -> Data {
let subkey = try createStorageKey(moduleName: moduleName, serviceName: serviceName)

let identifierHash = try identifier.blake128Concat()

return moduleKeyHash + serviceKeyHash + identifierHash
return subkey + identifierHash
}
}

0 comments on commit 6116358

Please sign in to comment.