* [#541] Adopt Latest main commit of SDK This adopts commit `cf60f44aa83938432c81361917406483ff42c719` from `main` branch of ZcashLightClientKit. It includes changes to remove a fake "defaultBirthday" and use the real `BlockHeight.ofLatestCheckpoint()` function that allows the wallets to fetch the latest checkpoint available from bundle and define it as the birthday. Also "defaultBirthday" birthday was incorrectly being used as a replacement for Sapling Activation height which is the minimum birthday supported by the wallet in terms of shielded pools. Wallets with lower heights that have only transparent funds could in theory work, but they won't be able to see sprout funds. Also the the SDK won't provide a birthday prior to sapling activation. removes references to `LightWalletService` since this class has been made internal to the SDK only. adopts FsBlockDb and adds a FsBlockDbRoot directory dependency for the Databases dependencies. Which should be renamed in a later commit Closes #541 * Fix SwiftLint issues
This commit is contained in:
parent
26dd0ea988
commit
adb48ba507
|
@ -54,7 +54,6 @@ opt_in_rules:
|
|||
- toggle_bool
|
||||
# - trailing_closure # weird in SwiftUI
|
||||
- unneeded_parentheses_in_closure_argument
|
||||
- unused_import
|
||||
- vertical_whitespace_closing_braces
|
||||
- vertical_whitespace_opening_braces
|
||||
- weak_delegate
|
||||
|
|
|
@ -2084,6 +2084,7 @@
|
|||
};
|
||||
6696BA8726F0B1D200D5C875 /* SwiftLint */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
alwaysOutOfDate = 1;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
|
@ -2098,7 +2099,7 @@
|
|||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "swiftlint_version=0.47.0\n\nif which swiftlint >/dev/null; then\n if [ $(swiftlint version) = $swiftlint_version ]; then\n swiftlint\n else\n echo \"warning: Compatible SwiftLint version not installed, download version $swiftlint_version from https://github.com/realm/SwiftLint. Currently installed version is $(swiftlint version)\"\n fi \nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
|
||||
shellScript = "swiftlint_version=0.50.3\n\nif which swiftlint >/dev/null; then\n if ![ $(swiftlint version) = $swiftlint_version ]; then\n echo \"warning: Compatible SwiftLint version not installed, download version $swiftlint_version from https://github.com/realm/SwiftLint. Currently installed version is $(swiftlint version)\"\n fi\n \n swiftlint \nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
|
@ -2720,8 +2721,8 @@
|
|||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/zcash/ZcashLightClientKit/";
|
||||
requirement = {
|
||||
kind = upToNextMajorVersion;
|
||||
minimumVersion = "0.18.0-beta";
|
||||
branch = main;
|
||||
kind = branch;
|
||||
};
|
||||
};
|
||||
6654C7382715A38000901167 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */ = {
|
||||
|
|
|
@ -329,8 +329,8 @@
|
|||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/zcash-hackworks/zcash-light-client-ffi.git",
|
||||
"state" : {
|
||||
"revision" : "b6013b8b313523b2c72ce62dbdc17f6ffad3a500",
|
||||
"version" : "0.1.1"
|
||||
"revision" : "c2dd0eff1defbe6dfb6197c3a42ab21ea2db2fc2",
|
||||
"version" : "0.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -338,8 +338,8 @@
|
|||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/zcash/ZcashLightClientKit/",
|
||||
"state" : {
|
||||
"revision" : "2c211732e16d53fdcb1c94304bc4016af7f15c6c",
|
||||
"version" : "0.18.1-beta"
|
||||
"branch" : "main",
|
||||
"revision" : "27b99013f7dda11caee0a261361c155490966e7f"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
|
|
@ -10,6 +10,7 @@ import ZcashLightClientKit
|
|||
|
||||
struct DatabaseFiles {
|
||||
enum DatabaseFilesError: Error {
|
||||
case getFsBlockDbRoot
|
||||
case getDocumentsURL
|
||||
case getCacheURL
|
||||
case getDataURL
|
||||
|
|
|
@ -18,6 +18,7 @@ extension DependencyValues {
|
|||
|
||||
struct DatabaseFilesClient {
|
||||
let documentsDirectory: () throws -> URL
|
||||
let fsBlockDbRootFor: (ZcashNetwork) throws -> URL
|
||||
let cacheDbURLFor: (ZcashNetwork) throws -> URL
|
||||
let dataDbURLFor: (ZcashNetwork) throws -> URL
|
||||
let outputParamsURLFor: (ZcashNetwork) throws -> URL
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
//
|
||||
|
||||
import ComposableArchitecture
|
||||
import ZcashLightClientKit
|
||||
|
||||
extension DatabaseFilesClient: DependencyKey {
|
||||
static let liveValue = DatabaseFilesClient.live()
|
||||
|
@ -15,6 +16,11 @@ extension DatabaseFilesClient: DependencyKey {
|
|||
documentsDirectory: {
|
||||
try databaseFiles.documentsDirectory()
|
||||
},
|
||||
fsBlockDbRootFor: { network in
|
||||
try databaseFiles.documentsDirectory()
|
||||
.appendingPathComponent(network.networkType.chainName)
|
||||
.appendingPathComponent(ZcashSDK.defaultFsCacheName, isDirectory: true)
|
||||
},
|
||||
cacheDbURLFor: { network in
|
||||
try databaseFiles.cacheDbURL(for: network)
|
||||
},
|
||||
|
|
|
@ -12,6 +12,7 @@ import XCTestDynamicOverlay
|
|||
extension DatabaseFilesClient: TestDependencyKey {
|
||||
static let testValue = Self(
|
||||
documentsDirectory: XCTUnimplemented("\(Self.self).documentsDirectory", placeholder: .emptyURL),
|
||||
fsBlockDbRootFor: XCTUnimplemented("\(Self.self).fsBlockDbRootFor", placeholder: .emptyURL),
|
||||
cacheDbURLFor: XCTUnimplemented("\(Self.self).cacheDbURLFor", placeholder: .emptyURL),
|
||||
dataDbURLFor: XCTUnimplemented("\(Self.self).dataDbURLFor", placeholder: .emptyURL),
|
||||
outputParamsURLFor: XCTUnimplemented("\(Self.self).outputParamsURLFor", placeholder: .emptyURL),
|
||||
|
@ -31,6 +32,7 @@ extension URL {
|
|||
extension DatabaseFilesClient {
|
||||
static let noOp = Self(
|
||||
documentsDirectory: { .emptyURL },
|
||||
fsBlockDbRootFor: { _ in .emptyURL },
|
||||
cacheDbURLFor: { _ in .emptyURL },
|
||||
dataDbURLFor: { _ in .emptyURL },
|
||||
outputParamsURLFor: { _ in .emptyURL },
|
||||
|
|
|
@ -158,7 +158,7 @@ struct WalletStorage {
|
|||
}
|
||||
|
||||
func baseQuery(forAccount account: String = "", andKey forKey: String) -> [String: Any] {
|
||||
let query:[ String: AnyObject ] = [
|
||||
let query: [String: AnyObject] = [
|
||||
/// Uniquely identify this keychain accessor
|
||||
kSecAttrService as String: (zcashStoredWalletPrefix + forKey) as AnyObject,
|
||||
kSecAttrAccount as String: account as AnyObject,
|
||||
|
@ -239,7 +239,7 @@ struct WalletStorage {
|
|||
) throws {
|
||||
let query = baseQuery(forAccount: account, andKey: forKey)
|
||||
|
||||
let attributes:[ String: AnyObject ] = [
|
||||
let attributes: [String: AnyObject] = [
|
||||
kSecValueData as String: data as AnyObject
|
||||
]
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ extension DependencyValues {
|
|||
|
||||
extension ZcashSDKEnvironment {
|
||||
enum ZcashSDKConstants {
|
||||
static let defaultBlockHeight = 1_629_724
|
||||
static let endpointMainnetAddress = "lightwalletd.electriccoin.co"
|
||||
static let endpointTestnetAddress = "lightwalletd.testnet.electriccoin.co"
|
||||
static let endpointPort = 9067
|
||||
|
@ -28,10 +27,9 @@ extension ZcashSDKEnvironment {
|
|||
}
|
||||
|
||||
struct ZcashSDKEnvironment {
|
||||
let defaultBirthday: BlockHeight
|
||||
let latestCheckpoint: (ZcashNetwork) -> BlockHeight
|
||||
let endpoint: LightWalletEndpoint
|
||||
var isMainnet: Bool { network.networkType == .mainnet }
|
||||
let lightWalletService: LightWalletService
|
||||
let memoCharLimit: Int
|
||||
let mnemonicWordsMaxCount: Int
|
||||
let network: ZcashNetwork
|
||||
|
|
|
@ -12,25 +12,17 @@ extension ZcashSDKEnvironment: DependencyKey {
|
|||
static let mainnet = ZcashSDKEnvironment.liveValue
|
||||
|
||||
static let liveValue = Self(
|
||||
defaultBirthday: BlockHeight(ZcashSDKConstants.defaultBlockHeight),
|
||||
latestCheckpoint: { network in BlockHeight.ofLatestCheckpoint(network: network) },
|
||||
endpoint: LightWalletEndpoint(
|
||||
address: ZcashSDKConstants.endpointTestnetAddress,
|
||||
port: ZcashSDKConstants.endpointPort,
|
||||
secure: true,
|
||||
streamingCallTimeoutInMillis: ZcashSDKConstants.streamingCallTimeoutInMillis
|
||||
),
|
||||
lightWalletService: LightWalletGRPCService(
|
||||
endpoint: LightWalletEndpoint(
|
||||
address: ZcashSDKConstants.endpointTestnetAddress,
|
||||
port: ZcashSDKConstants.endpointPort,
|
||||
secure: true,
|
||||
streamingCallTimeoutInMillis: ZcashSDKConstants.streamingCallTimeoutInMillis
|
||||
)
|
||||
),
|
||||
memoCharLimit: 512,
|
||||
memoCharLimit: MemoBytes.capacity,
|
||||
mnemonicWordsMaxCount: ZcashSDKConstants.mnemonicWordsMaxCount,
|
||||
network: ZcashNetworkBuilder.network(for: .testnet),
|
||||
requiredTransactionConfirmations: ZcashSDKConstants.requiredTransactionConfirmations,
|
||||
sdkVersion: "0.17.0-beta"
|
||||
sdkVersion: "0.18.1-beta"
|
||||
)
|
||||
}
|
||||
|
|
|
@ -13,25 +13,17 @@ extension ZcashSDKEnvironment: TestDependencyKey {
|
|||
static let testnet = ZcashSDKEnvironment.liveValue
|
||||
|
||||
static let testValue = Self(
|
||||
defaultBirthday: BlockHeight(ZcashSDKConstants.defaultBlockHeight),
|
||||
latestCheckpoint: { network in BlockHeight.ofLatestCheckpoint(network: network) },
|
||||
endpoint: LightWalletEndpoint(
|
||||
address: ZcashSDKConstants.endpointTestnetAddress,
|
||||
port: ZcashSDKConstants.endpointPort,
|
||||
secure: true,
|
||||
streamingCallTimeoutInMillis: ZcashSDKConstants.streamingCallTimeoutInMillis
|
||||
),
|
||||
lightWalletService: LightWalletGRPCService(
|
||||
endpoint: LightWalletEndpoint(
|
||||
address: ZcashSDKConstants.endpointTestnetAddress,
|
||||
port: ZcashSDKConstants.endpointPort,
|
||||
secure: true,
|
||||
streamingCallTimeoutInMillis: ZcashSDKConstants.streamingCallTimeoutInMillis
|
||||
)
|
||||
),
|
||||
memoCharLimit: 512,
|
||||
memoCharLimit: MemoBytes.capacity,
|
||||
mnemonicWordsMaxCount: ZcashSDKConstants.mnemonicWordsMaxCount,
|
||||
network: ZcashNetworkBuilder.network(for: .testnet),
|
||||
requiredTransactionConfirmations: ZcashSDKConstants.requiredTransactionConfirmations,
|
||||
sdkVersion: "0.17.0-beta"
|
||||
sdkVersion: "0.18.1-beta"
|
||||
)
|
||||
}
|
||||
|
|
|
@ -78,8 +78,11 @@ struct ImportWalletReducer: ReducerProtocol {
|
|||
return .none
|
||||
|
||||
case .birthdayInputChanged(let redactedBirthday):
|
||||
let saplingActivation = zcashSDKEnvironment.network.constants.saplingActivationHeight
|
||||
|
||||
state.birthdayHeight = redactedBirthday
|
||||
if let birthdayHeight = BlockHeight(state.birthdayHeight.data), birthdayHeight >= zcashSDKEnvironment.defaultBirthday {
|
||||
|
||||
if let birthdayHeight = BlockHeight(state.birthdayHeight.data), birthdayHeight >= saplingActivation {
|
||||
state.birthdayHeightValue = birthdayHeight.redacted
|
||||
} else {
|
||||
state.birthdayHeightValue = nil
|
||||
|
@ -99,7 +102,8 @@ struct ImportWalletReducer: ReducerProtocol {
|
|||
try mnemonic.isValid(state.importedSeedPhrase.data)
|
||||
|
||||
// store it to the keychain
|
||||
let birthday = state.birthdayHeightValue ?? zcashSDKEnvironment.defaultBirthday.redacted
|
||||
let birthday = state.birthdayHeightValue ?? zcashSDKEnvironment.latestCheckpoint(zcashSDKEnvironment.network).redacted
|
||||
|
||||
try walletStorage.importWallet(state.importedSeedPhrase.data, birthday.data, .english, false)
|
||||
|
||||
// update the backup phrase validation flag
|
||||
|
|
|
@ -87,7 +87,7 @@ extension RootReducer {
|
|||
try mnemonic.isValid(storedWallet.seedPhrase.value())
|
||||
let seedBytes = try mnemonic.toSeed(storedWallet.seedPhrase.value())
|
||||
|
||||
let birthday = state.storedWallet?.birthday?.value() ?? zcashSDKEnvironment.defaultBirthday
|
||||
let birthday = state.storedWallet?.birthday?.value() ?? zcashSDKEnvironment.latestCheckpoint(zcashSDKEnvironment.network)
|
||||
|
||||
let initializer = try RootReducer.prepareInitializer(
|
||||
for: storedWallet.seedPhrase.value(),
|
||||
|
@ -142,7 +142,7 @@ extension RootReducer {
|
|||
do {
|
||||
// get the random english mnemonic
|
||||
let newRandomPhrase = try mnemonic.randomMnemonic()
|
||||
let birthday = try zcashSDKEnvironment.lightWalletService.latestBlockHeight()
|
||||
let birthday = zcashSDKEnvironment.latestCheckpoint(zcashSDKEnvironment.network)
|
||||
|
||||
// store the wallet to the keychain
|
||||
try walletStorage.importWallet(newRandomPhrase, birthday, .english, false)
|
||||
|
|
|
@ -134,6 +134,7 @@ extension RootReducer {
|
|||
|
||||
let initializer = Initializer(
|
||||
cacheDbURL: try databaseFiles.cacheDbURLFor(network),
|
||||
fsBlockDbRoot: try databaseFiles.fsBlockDbRootFor(network),
|
||||
dataDbURL: try databaseFiles.dataDbURLFor(network),
|
||||
pendingDbURL: try databaseFiles.pendingDbURLFor(network),
|
||||
endpoint: zcashSDKEnvironment.endpoint,
|
||||
|
|
|
@ -20,7 +20,7 @@ struct TransactionDetailView: View {
|
|||
header
|
||||
|
||||
switch transaction.status {
|
||||
case .paid(success: _):
|
||||
case .paid:
|
||||
plainText("You sent \(transaction.zecAmount.decimalString()) ZEC")
|
||||
plainText("fee \(transaction.fee.decimalString()) ZEC", mark: .inactive)
|
||||
plainText("total amount \(transaction.totalAmount.decimalString()) ZEC", mark: .inactive)
|
||||
|
|
|
@ -61,7 +61,7 @@ struct TransactionRowView: View {
|
|||
extension TransactionRowView {
|
||||
var operationTitle: String {
|
||||
switch transaction.status {
|
||||
case .paid(success: _):
|
||||
case .paid:
|
||||
return "You sent"
|
||||
case .received:
|
||||
return "Unknown paid you"
|
||||
|
@ -76,7 +76,7 @@ extension TransactionRowView {
|
|||
var icon: some View {
|
||||
HStack {
|
||||
switch transaction.status {
|
||||
case .paid(success: _), .received:
|
||||
case .paid, .received:
|
||||
Image(transaction.status == .received ? Asset.Assets.Icons.received.name : Asset.Assets.Icons.sent.name)
|
||||
.resizable()
|
||||
.frame(width: 60, height: 60)
|
||||
|
|
|
@ -27,7 +27,7 @@ struct Wedge: Shape {
|
|||
x: rect.midX,
|
||||
y: rect.midY
|
||||
),
|
||||
radius: rect.width / 2 ,
|
||||
radius: rect.width / 2,
|
||||
startAngle: Angle(degrees: Double(startAngle)),
|
||||
endAngle: Angle(degrees: Double(endAngle)),
|
||||
clockwise: clockwise
|
||||
|
|
|
@ -43,7 +43,7 @@ extension Binding {
|
|||
else { return nil }
|
||||
return `case`
|
||||
},
|
||||
// swiftlint:disable:next unused_closure_parameter
|
||||
|
||||
set: { `case` in
|
||||
if let `case` = `case` {
|
||||
self.wrappedValue = casePath.embed(`case`)
|
||||
|
|
|
@ -80,13 +80,13 @@ class ImportWalletTests: XCTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
func testInvalidBirthdayHeight_lessThanDefault() throws {
|
||||
func testInvalidBirthdayHeight_lessThanSaplingActivation() throws {
|
||||
let store = TestStore(
|
||||
initialState: .placeholder,
|
||||
reducer: ImportWalletReducer()
|
||||
)
|
||||
|
||||
let birthday = "1600000".redacted
|
||||
let birthday = "200000".redacted
|
||||
store.send(.birthdayInputChanged(birthday)) { state in
|
||||
state.birthdayHeight = birthday
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ class ImportWalletTests: XCTestCase {
|
|||
dependencies.mnemonic.isValid = { _ in throw "invalid mnemonic" }
|
||||
}
|
||||
|
||||
let birthday = "1600000".redacted
|
||||
let birthday = "200000".redacted
|
||||
store.send(.birthdayInputChanged(birthday)) { state in
|
||||
state.birthdayHeight = birthday
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ class ImportWalletTests: XCTestCase {
|
|||
$0.mnemonic = .noOp
|
||||
}
|
||||
|
||||
let birthday = "1600000".redacted
|
||||
let birthday = "200000".redacted
|
||||
store.send(.birthdayInputChanged(birthday)) { state in
|
||||
state.birthdayHeight = birthday
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class ProfileTests: XCTestCase {
|
|||
state.addressDetailsState.uAddress = uAddress
|
||||
state.appVersion = "0.0.1"
|
||||
state.appBuild = "31"
|
||||
state.sdkVersion = "0.17.0-beta"
|
||||
state.sdkVersion = "0.18.1-beta"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import ZcashLightClientKit
|
|||
extension DatabaseFiles.DatabaseFilesError {
|
||||
var debugValue: String {
|
||||
switch self {
|
||||
case .getFsBlockDbRoot: return "getFsBlockDbRoot"
|
||||
case .getDocumentsURL: return "getDocumentsURL"
|
||||
case .getCacheURL: return "getCacheURL"
|
||||
case .getDataURL: return "getDataURL"
|
||||
|
|
|
@ -328,7 +328,7 @@ private extension WalletStorageTests {
|
|||
) throws {
|
||||
let query = storage.baseQuery(forAccount: account, andKey: forKey)
|
||||
|
||||
let attributes:[ String: AnyObject ] = [
|
||||
let attributes: [String: AnyObject] = [
|
||||
kSecValueData as String: data as AnyObject
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in New Issue