Skip to content

Commit

Permalink
Merge pull request #7 from dapperlabs/seanlee/latest_purchase
Browse files Browse the repository at this point in the history
Add latest transaction fetcher
  • Loading branch information
seanlee-dapper authored Feb 9, 2024
2 parents 44c4710 + 2ff25b1 commit 149cd72
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Sources/Mercato/Mercato.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Mercato {
private var updateListenerTask: Task<(), Never>? = nil

public init() {}

fileprivate func listenForUnfinishedTransactions(updateBlock: @escaping TransactionUpdate) {
let task = Task.detached
{
Expand Down Expand Up @@ -189,6 +189,19 @@ extension Mercato
{
return try await activeSubscriptions(onlyRenewable: onlyRenewable).map { $0.productID}
}

public static func fetchLatestTransaction(for productId: String) async throws -> (transaction: Transaction, jwsRepresentation: String) {
let result = await Transaction.latest(for: productId)
guard let result else {
throw MercatoError.failedVerification
}
switch result {
case .verified(let verifiedTransaction):
return (transaction: verifiedTransaction, jwsRepresentation: result.jwsRepresentation)
case .unverified:
throw MercatoError.failedVerification
}
}
}


Expand Down

0 comments on commit 149cd72

Please sign in to comment.