Skip to content

Commit

Permalink
[#1475] Adopt transaction data requests
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
LukasKorba committed Aug 20, 2024
1 parent e5e1fdf commit 8283594
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
],
Expand Down
5 changes: 1 addition & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
struct SpendsFromAddress: Equatable {
let address: String
let blockRangeStart: UInt32
let blockRangeEnd: Int64
let blockRangeEnd: UInt32?
}

enum TransactionDataRequest: Equatable {
Expand Down
5 changes: 4 additions & 1 deletion Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
}
Expand Down

0 comments on commit 8283594

Please sign in to comment.