From 8283594905265554e537f6379fbe9535928f6741 Mon Sep 17 00:00:00 2001 From: Lukas Korba Date: Tue, 20 Aug 2024 13:09:24 +0200 Subject: [PATCH] [#1475] Adopt transaction data requests - SpendsFromAddress endHeight is an optional UInt32 [#1475] Adopt transaction data requests - ignoring the getSubtreeRoots error for now so I can test tex send [#1475] Adopt transaction data requests - ignoring error of getSubtreeRoots [#1475] Adopt transaction data requests - reverting the DemoAppConfig [#1475] Adopt transaction data requests - FFI dependency set to 0.9.0 --- .../xcshareddata/swiftpm/Package.resolved | 3 ++- Package.swift | 5 +---- .../Block/Actions/UpdateSubtreeRootsAction.swift | 4 +++- .../ZcashLightClientKit/Block/Enhance/BlockEnhancer.swift | 8 +++++++- .../Model/TransactionDataRequest.swift | 2 +- Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift | 5 ++++- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index e0773c28..296284d8 100644 --- a/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -176,7 +176,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/zcash-hackworks/zcash-light-client-ffi", "state" : { - "revision" : "36cb5d9a0ac2812cbc6ada0a33ed9dff90a10b1f" + "revision" : "6521af353b63299d32d010195302dac50074f918", + "version" : "0.9.0" } } ], diff --git a/Package.swift b/Package.swift index faca3f0d..9091bbd4 100644 --- a/Package.swift +++ b/Package.swift @@ -16,10 +16,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/grpc/grpc-swift.git", from: "1.19.1"), .package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.14.1"), - // .package(url: "https://github.com/zcash-hackworks/zcash-light-client-ffi", exact: "0.8.1") - // Compiled from 2516a94f8bdc540d951c38b66e9c07e2b8c29cb4 -// .package(url: "https://github.com/zcash-hackworks/zcash-light-client-ffi", branch: "ffi_transaction_requests_preview") - .package(url: "https://github.com/zcash-hackworks/zcash-light-client-ffi", revision: "36cb5d9a0ac2812cbc6ada0a33ed9dff90a10b1f") + .package(url: "https://github.com/zcash-hackworks/zcash-light-client-ffi", exact: "0.9.0") ], targets: [ .target( diff --git a/Sources/ZcashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift b/Sources/ZcashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift index 24e980c8..da04c500 100644 --- a/Sources/ZcashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift +++ b/Sources/ZcashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift @@ -30,7 +30,7 @@ extension UpdateSubtreeRootsAction: Action { logger.debug("Attempt to get subtree roots, this may fail because lightwalletd may not support Spend before Sync.") let stream = service.getSubtreeRoots(request) - + var saplingRoots: [SubtreeRoot] = [] do { @@ -39,6 +39,8 @@ extension UpdateSubtreeRootsAction: Action { } } catch ZcashError.serviceSubtreeRootsStreamFailed(LightWalletServiceError.timeOut) { throw ZcashError.serviceSubtreeRootsStreamFailed(LightWalletServiceError.timeOut) + } catch { + await context.update(state: .updateChainTip) } logger.debug("Sapling tree has \(saplingRoots.count) subtrees") diff --git a/Sources/ZcashLightClientKit/Block/Enhance/BlockEnhancer.swift b/Sources/ZcashLightClientKit/Block/Enhance/BlockEnhancer.swift index adc8b531..b47c788b 100644 --- a/Sources/ZcashLightClientKit/Block/Enhance/BlockEnhancer.swift +++ b/Sources/ZcashLightClientKit/Block/Enhance/BlockEnhancer.swift @@ -113,9 +113,15 @@ extension BlockEnhancerImpl: BlockEnhancer { } case .spendsFromAddress(let sfa): + guard let blockRangeEnd = sfa.blockRangeEnd else { + logger.error("spendsFromAddress \(sfa) is missing blockRangeEnd, ignoring the request.") + continue + } + var filter = TransparentAddressBlockFilter() filter.address = sfa.address - filter.range = BlockRange(startHeight: Int(sfa.blockRangeStart), endHeight: Int(sfa.blockRangeEnd - 1)) + filter.range = BlockRange(startHeight: Int(sfa.blockRangeStart), endHeight: Int(blockRangeEnd - 1)) + let stream = service.getTaddressTxids(filter) for try await rawTransaction in stream { diff --git a/Sources/ZcashLightClientKit/Model/TransactionDataRequest.swift b/Sources/ZcashLightClientKit/Model/TransactionDataRequest.swift index 487a5f5b..cb7a6da5 100644 --- a/Sources/ZcashLightClientKit/Model/TransactionDataRequest.swift +++ b/Sources/ZcashLightClientKit/Model/TransactionDataRequest.swift @@ -10,7 +10,7 @@ import Foundation struct SpendsFromAddress: Equatable { let address: String let blockRangeStart: UInt32 - let blockRangeEnd: Int64 + let blockRangeEnd: UInt32? } enum TransactionDataRequest: Equatable { diff --git a/Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift b/Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift index 2752dcc6..04fde49f 100644 --- a/Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift +++ b/Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift @@ -871,11 +871,14 @@ struct ZcashRustBackend: ZcashRustBackendWelding { } else if tDataRequestPtr.tag == 1 { tDataRequest = TransactionDataRequest.enhancement(FfiTxId(tuple: tDataRequestPtr.enhancement).array) } else if tDataRequestPtr.tag == 2, let address = String(validatingUTF8: tDataRequestPtr.spends_from_address.address) { + let end = tDataRequestPtr.spends_from_address.block_range_end + let blockRangeEnd: UInt32? = end > UInt32.max || end == -1 ? nil : UInt32(end) + tDataRequest = TransactionDataRequest.spendsFromAddress( SpendsFromAddress( address: address, blockRangeStart: tDataRequestPtr.spends_from_address.block_range_start, - blockRangeEnd: tDataRequestPtr.spends_from_address.block_range_end + blockRangeEnd: blockRangeEnd ) ) }