From 79d30fbff93c1ce923bdf0ca64e33db009b12623 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Tue, 17 Dec 2024 18:25:09 +1300 Subject: [PATCH] two da --- .../Blockchain/DataStore/DataStore.swift | 24 ++++++++++--------- .../Validator/DataAvailability.swift | 5 ++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Blockchain/Sources/Blockchain/DataStore/DataStore.swift b/Blockchain/Sources/Blockchain/DataStore/DataStore.swift index 61f1e375..ff1a3c1d 100644 --- a/Blockchain/Sources/Blockchain/DataStore/DataStore.swift +++ b/Blockchain/Sources/Blockchain/DataStore/DataStore.swift @@ -16,29 +16,31 @@ public final class DataStore: Sendable { } // partitioning files so that we won't have too many files in a single directory - private func path(for name: String) -> URL { - var path = basePath + private func getPath(path: String, name: String) -> URL { + var ret = basePath + ret.append(component: path) var name = name[...] if let first = name.first { - path = path.appendingPathComponent(String(first), isDirectory: true) + ret.append(component: String(first), directoryHint: .isDirectory) name = name.dropFirst() } if let second = name.first { - path = path.appendingPathComponent(String(second), isDirectory: true) + ret.append(component: String(second), directoryHint: .isDirectory) name = name.dropFirst() } - return path.appendingPathComponent(String(name), isDirectory: false) + ret.append(component: String(name), directoryHint: .notDirectory) + return ret } - public func read(name: String) async throws -> Data? { - try await impl.read(path: path(for: name)) + public func read(path: String, name: String) async throws -> Data? { + try await impl.read(path: getPath(path: path, name: name)) } - public func write(name: String, value: Data) async throws { - try await impl.write(path: path(for: name), value: value) + public func write(path: String, name: String, value: Data) async throws { + try await impl.write(path: getPath(path: path, name: name), value: value) } - public func delete(name: String) async throws { - try await impl.delete(path: path(for: name)) + public func delete(path: String, name: String) async throws { + try await impl.delete(path: getPath(path: path, name: name)) } } diff --git a/Blockchain/Sources/Blockchain/Validator/DataAvailability.swift b/Blockchain/Sources/Blockchain/Validator/DataAvailability.swift index a2b02f97..c6c3cd0e 100644 --- a/Blockchain/Sources/Blockchain/Validator/DataAvailability.swift +++ b/Blockchain/Sources/Blockchain/Validator/DataAvailability.swift @@ -2,6 +2,11 @@ import Foundation import TracingUtils import Utils +enum DataAvailabilityStore: String, Sendable { + case imports + case audits +} + public final class DataAvailability: ServiceBase2, @unchecked Sendable { private let dataProvider: BlockchainDataProvider private let dataStore: DataStore