Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ abstract_target 'fearlessAll' do
pod 'SSFModels', '0.1.32'
pod 'SSFEraKit'
pod 'SSFLogger'
pod 'SSFRuntimeCodingService', '0.1.29'
pod 'SSFRuntimeCodingService', '0.1.33'
pod 'SSFStorageQueryKit'
pod 'SSFChainConnection', '0.1.24'
pod 'SSFNetwork'
pod 'SSFChainRegistry', '0.1.29'
pod 'SSFUtils', '0.1.31'
pod 'SSFHelpers', '0.1.31'
pod 'SSFChainRegistry', '0.1.33'
pod 'SSFUtils', '0.1.33'
pod 'SSFHelpers', '0.1.33'
pod 'SSFCloudStorage'
end
end
Expand Down
3 changes: 2 additions & 1 deletion fearless/Common/Configs/ApplicationConfigs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ extension ApplicationConfig: ApplicationConfigProtocol, XcmConfigProtocol {
}

var chainTypesSourceUrl: URL {
GitHubUrl.url(suffix: "chains/all_chains_types.json")
GitHubUrl.url(suffix: "chains/all_chains_types.json", branch: .withoutTypes)
}

// MARK: - xcm
Expand Down Expand Up @@ -230,6 +230,7 @@ private enum GitHubUrl {
case rococo = "feature/rococo"
case newEvms = "new-evms"
case masterReef = "master-reef"
case withoutTypes = "without-types"
}

static func url(suffix: String, url: BaseUrl = .sharedUtils, branch: DefaultBranch = .master) -> URL {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import SSFModels

protocol RuntimeHotBootSnapshotFactoryProtocol {
func createRuntimeSnapshotWrapper(
usedRuntimePaths: [String: [String]],
chainTypes: Data
chainTypes: Data?
) -> ClosureOperation<RuntimeSnapshot?>
}

Expand All @@ -26,22 +25,25 @@ final class RuntimeHotBootSnapshotFactory: RuntimeHotBootSnapshotFactoryProtocol
}

func createRuntimeSnapshotWrapper(
usedRuntimePaths: [String: [String]],
chainTypes: Data
chainTypes: Data?
) -> ClosureOperation<RuntimeSnapshot?> {
let snapshotOperation = ClosureOperation<RuntimeSnapshot?> { [weak self] in
guard let strongSelf = self else { return nil }

let decoder = try ScaleDecoder(data: strongSelf.runtimeItem.metadata)
let runtimeMetadata = try RuntimeMetadata(scaleDecoder: decoder)

// TODO: think about it
let json: JSON = .dictionaryValue(["types": .dictionaryValue([:])])
var definitionJson: JSON?
if let data = chainTypes {
let jsonDecoder = JSONDecoder()
let json = try jsonDecoder.decode(JSON.self, from: data)
definitionJson = json.types
}

let catalog = try TypeRegistryCatalog.createFromTypeDefinition(
try JSONEncoder().encode(json),
definitionJson: definitionJson,
versioningData: chainTypes,
runtimeMetadata: runtimeMetadata,
usedRuntimePaths: usedRuntimePaths
runtimeMetadata: runtimeMetadata
)

return RuntimeSnapshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ final class RuntimeProvider {
internal let chainId: ChainModel.Id
private let chainName: String
private let chainModel: ChainModel
private let usedRuntimePaths: [String: [String]]

private let snapshotOperationFactory: RuntimeSnapshotFactoryProtocol
private let snapshotHotOperationFactory: RuntimeHotBootSnapshotFactoryProtocol?
Expand Down Expand Up @@ -65,7 +64,6 @@ final class RuntimeProvider {
dataHasher: StorageHasher = .twox256,
logger: LoggerProtocol? = nil,
repository: AnyDataProviderRepository<RuntimeMetadataItem>,
usedRuntimePaths: [String: [String]],
chainMetadata: RuntimeMetadataItem?,
chainTypes: Data?
) {
Expand All @@ -79,7 +77,6 @@ final class RuntimeProvider {
self.dataHasher = dataHasher
self.logger = logger
self.repository = repository
self.usedRuntimePaths = usedRuntimePaths
initialChainMetadata = chainMetadata
self.chainTypes = chainTypes

Expand All @@ -89,19 +86,15 @@ final class RuntimeProvider {
}

private func buildSnapshot(for metadata: RuntimeMetadataItem?) {
guard
let chainTypes = chainTypes,
let chainMetadata = metadata
else {
guard let chainMetadata = metadata else {
return
}

logger?.debug("Will start building snapshot for \(chainName)")

let wrapper = snapshotOperationFactory.createRuntimeSnapshotWrapper(
chainTypes: chainTypes,
chainMetadata: chainMetadata,
usedRuntimePaths: usedRuntimePaths
chainMetadata: chainMetadata
)

wrapper.completionBlock = { [weak self] in
Expand All @@ -118,14 +111,11 @@ final class RuntimeProvider {
private func buildHotSnapshot() {
logger?.debug("Will start building hot snapshot for \(chainName)")

guard let snapshotHotOperationFactory = snapshotHotOperationFactory,
let chainTypes = chainTypes
else {
guard let snapshotHotOperationFactory = snapshotHotOperationFactory else {
return
}

let wrapper = snapshotHotOperationFactory.createRuntimeSnapshotWrapper(
usedRuntimePaths: usedRuntimePaths,
chainTypes: chainTypes
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import SSFModels
protocol RuntimeProviderFactoryProtocol {
func createRuntimeProvider(
for chain: ChainModel,
chainTypes: Data?,
usedRuntimePaths: [String: [String]]
chainTypes: Data?
) -> RuntimeProviderProtocol
func createHotRuntimeProvider(
for chain: ChainModel,
runtimeItem: RuntimeMetadataItem,
chainTypes: Data,
usedRuntimePaths: [String: [String]]
chainTypes: Data?
) -> RuntimeProviderProtocol
}

Expand Down Expand Up @@ -44,8 +42,7 @@ final class RuntimeProviderFactory {
extension RuntimeProviderFactory: RuntimeProviderFactoryProtocol {
func createRuntimeProvider(
for chain: ChainModel,
chainTypes: Data?,
usedRuntimePaths: [String: [String]]
chainTypes: Data?
) -> RuntimeProviderProtocol {
let snapshotOperationFactory = RuntimeSnapshotFactory(
chainId: chain.chainId,
Expand All @@ -61,7 +58,6 @@ extension RuntimeProviderFactory: RuntimeProviderFactoryProtocol {
operationQueue: operationQueue,
logger: logger,
repository: repository,
usedRuntimePaths: usedRuntimePaths,
chainMetadata: nil,
chainTypes: chainTypes
)
Expand All @@ -70,8 +66,7 @@ extension RuntimeProviderFactory: RuntimeProviderFactoryProtocol {
func createHotRuntimeProvider(
for chain: ChainModel,
runtimeItem: RuntimeMetadataItem,
chainTypes: Data,
usedRuntimePaths: [String: [String]]
chainTypes: Data?
) -> RuntimeProviderProtocol {
let snapshotOperationFactory = RuntimeSnapshotFactory(
chainId: chain.chainId,
Expand All @@ -93,7 +88,6 @@ extension RuntimeProviderFactory: RuntimeProviderFactoryProtocol {
operationQueue: operationQueue,
logger: logger,
repository: repository,
usedRuntimePaths: usedRuntimePaths,
chainMetadata: runtimeItem,
chainTypes: chainTypes
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protocol RuntimeProviderPoolProtocol {
func setupHotRuntimeProvider(
for chain: ChainModel,
runtimeItem: RuntimeMetadataItem,
chainTypes: Data
chainTypes: Data?
) -> RuntimeProviderProtocol
func destroyRuntimeProvider(for chainId: ChainModel.Id)
func getRuntimeProvider(for chainId: ChainModel.Id) -> RuntimeProviderProtocol?
Expand All @@ -20,7 +20,6 @@ protocol RuntimeProviderPoolProtocol {
final class RuntimeProviderPool {
private let runtimeProviderFactory: RuntimeProviderFactoryProtocol

private var usedRuntimeModules = UsedRuntimePaths()
private(set) var runtimeProviders: [ChainModel.Id: RuntimeProviderProtocol] = [:]

private let lock = ReaderWriterLock()
Expand All @@ -35,13 +34,12 @@ extension RuntimeProviderPool: RuntimeProviderPoolProtocol {
func setupHotRuntimeProvider(
for chain: ChainModel,
runtimeItem: RuntimeMetadataItem,
chainTypes: Data
chainTypes: Data?
) -> RuntimeProviderProtocol {
let runtimeProvider = runtimeProviderFactory.createHotRuntimeProvider(
for: chain,
runtimeItem: runtimeItem,
chainTypes: chainTypes,
usedRuntimePaths: usedRuntimeModules.usedRuntimePaths
chainTypes: chainTypes
)

lock.exclusivelyWrite { [weak self] in
Expand All @@ -63,8 +61,7 @@ extension RuntimeProviderPool: RuntimeProviderPoolProtocol {
} else {
let runtimeProvider = runtimeProviderFactory.createRuntimeProvider(
for: chain,
chainTypes: chainTypes,
usedRuntimePaths: usedRuntimeModules.usedRuntimePaths
chainTypes: chainTypes
)

lock.exclusivelyWrite { [weak self] in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import SSFModels

protocol RuntimeSnapshotFactoryProtocol {
func createRuntimeSnapshotWrapper(
chainTypes: Data,
chainMetadata: RuntimeMetadataItem,
usedRuntimePaths: [String: [String]]
chainTypes: Data?,
chainMetadata: RuntimeMetadataItem
) -> ClosureOperation<RuntimeSnapshot?>
}

Expand All @@ -27,21 +26,24 @@ final class RuntimeSnapshotFactory {
}

private func createWrapperForChainTypes(
ownTypes: Data,
runtimeMetadataItem: RuntimeMetadataItem,
usedRuntimePaths: [String: [String]]
ownTypes: Data?,
runtimeMetadataItem: RuntimeMetadataItem
) -> ClosureOperation<RuntimeSnapshot?> {
let snapshotOperation = ClosureOperation<RuntimeSnapshot?> {
let decoder = try ScaleDecoder(data: runtimeMetadataItem.metadata)
let runtimeMetadata = try RuntimeMetadata(scaleDecoder: decoder)

// TODO: think about it
let json: JSON = .dictionaryValue(["types": .dictionaryValue([:])])
var definitionJson: JSON?
if let data = ownTypes {
let jsonDecoder = JSONDecoder()
let json = try jsonDecoder.decode(JSON.self, from: data)
definitionJson = json.types
}

let catalog = try TypeRegistryCatalog.createFromTypeDefinition(
try JSONEncoder().encode(json),
definitionJson: definitionJson,
versioningData: ownTypes,
runtimeMetadata: runtimeMetadata,
usedRuntimePaths: usedRuntimePaths
runtimeMetadata: runtimeMetadata
)

return RuntimeSnapshot(
Expand All @@ -60,14 +62,12 @@ final class RuntimeSnapshotFactory {

extension RuntimeSnapshotFactory: RuntimeSnapshotFactoryProtocol {
func createRuntimeSnapshotWrapper(
chainTypes: Data,
chainMetadata: RuntimeMetadataItem,
usedRuntimePaths: [String: [String]]
chainTypes: Data?,
chainMetadata: RuntimeMetadataItem
) -> ClosureOperation<RuntimeSnapshot?> {
createWrapperForChainTypes(
ownTypes: chainTypes,
runtimeMetadataItem: chainMetadata,
usedRuntimePaths: usedRuntimePaths
runtimeMetadataItem: chainMetadata
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,10 @@ final class SnapshotHotBootBuilder: SnapshotHotBootBuilderProtocol {
}

result.chains.forEach { chain in
guard
let runtimeItem = runtimeItemsMap[chain.chainId],
let chainTypes = chainsTypesJson[chain.chainId]
else {
guard let runtimeItem = runtimeItemsMap[chain.chainId] else {
return
}

let chainTypes = chainsTypesJson[chain.chainId]
runtimeProviderPool.setupHotRuntimeProvider(
for: chain,
runtimeItem: runtimeItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ struct CrowdloanContribution: Decodable {

final class CrowdloanContributionMapper: DynamicScaleDecodable {
func accept(decoder: DynamicScaleDecoding) throws -> JSON {
let balance = try decoder.read(type: KnownType.balance.rawValue)
let balance: JSON
do {
balance = try decoder.read(type: GenericType.balance.rawValue)
} catch {
balance = try decoder.read(type: KnownType.balance.rawValue)
}
let memo = try decoder.read(type: GenericType.bytes.rawValue)

return JSON.dictionaryValue(
Expand Down
Loading