Skip to content

Commit

Permalink
Update Breez SDK Flutter package to version v0.5.1-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jul 16, 2024
1 parent a75433e commit 133dbdf
Show file tree
Hide file tree
Showing 12 changed files with 723 additions and 166 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.breez.breez_sdk'
version '0.5.0'
version '0.5.1-rc1'

buildscript {
ext.kotlin_version = '1.8.20'
Expand Down
4 changes: 4 additions & 0 deletions ios/Classes/bridge_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ typedef struct wire_LnUrlPayRequest {
uint64_t amount_msat;
struct wire_uint_8_list *comment;
struct wire_uint_8_list *payment_label;
bool *validate_success_action_url;
} wire_LnUrlPayRequest;

typedef struct wire_LnUrlWithdrawRequestData {
Expand Down Expand Up @@ -405,6 +406,8 @@ void wire_in_progress_swap(int64_t port_);

void wire_in_progress_reverse_swaps(int64_t port_);

void wire_claim_reverse_swap(int64_t port_, struct wire_uint_8_list *lockup_address);

void wire_open_channel_fee(int64_t port_, struct wire_OpenChannelFeeRequest *req);

void wire_fetch_reverse_swap_fees(int64_t port_, struct wire_ReverseSwapFeesRequest *req);
Expand Down Expand Up @@ -556,6 +559,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) wire_redeem_swap);
dummy_var ^= ((int64_t) (void*) wire_in_progress_swap);
dummy_var ^= ((int64_t) (void*) wire_in_progress_reverse_swaps);
dummy_var ^= ((int64_t) (void*) wire_claim_reverse_swap);
dummy_var ^= ((int64_t) (void*) wire_open_channel_fee);
dummy_var ^= ((int64_t) (void*) wire_fetch_reverse_swap_fees);
dummy_var ^= ((int64_t) (void*) wire_onchain_payment_limits);
Expand Down
201 changes: 127 additions & 74 deletions ios/bindings-swift/Sources/BreezSDK/BreezSDK.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ios/bindings-swift/Sources/BreezSDK/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Foundation

struct Constants {
// Notification Threads
static let NOTIFICATION_THREAD_ADDRESS_TXS_CONFIRMED = "ADDRESS_TXS_CONFIRMED"
static let NOTIFICATION_THREAD_LNURL_PAY = "LNURL_PAY"
static let NOTIFICATION_THREAD_PAYMENT_RECEIVED = "PAYMENT_RECEIVED"
static let NOTIFICATION_THREAD_SWAP_TX_CONFIRMED = "SWAP_TX_CONFIRMED"

// Message Data
static let MESSAGE_DATA_TYPE = "notification_type"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ open class SDKNotificationService: UNNotificationServiceExtension {
self.logger.log(tag: TAG, line: "\(notificationType) data string: \(payload)", level: "INFO")
switch(notificationType) {
case Constants.MESSAGE_TYPE_ADDRESS_TXS_CONFIRMED:
return RedeemSwapTask(payload: payload, logger: self.logger, contentHandler: contentHandler, bestAttemptContent: bestAttemptContent)
return ConfirmTransactionTask(payload: payload, logger: self.logger, contentHandler: contentHandler, bestAttemptContent: bestAttemptContent)
case Constants.MESSAGE_TYPE_LNURL_PAY_INFO:
return LnurlPayInfoTask(payload: payload, logger: self.logger, config: self.config, contentHandler: contentHandler, bestAttemptContent: bestAttemptContent)
case Constants.MESSAGE_TYPE_LNURL_PAY_INVOICE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ struct AddressTxsConfirmedRequest: Codable {
let address: String
}

class RedeemSwapTask : TaskProtocol {
fileprivate let TAG = "RedeemSwapTask"
class ConfirmTransactionTask : TaskProtocol {
fileprivate let TAG = "ConfirmTransactionTask"

internal var payload: String
internal var contentHandler: ((UNNotificationContent) -> Void)?
internal var bestAttemptContent: UNMutableNotificationContent?
internal var logger: ServiceLogger
internal var swapAddress: String? = nil
internal var bitcoinAddress: String? = nil

init(payload: String, logger: ServiceLogger, contentHandler: ((UNNotificationContent) -> Void)? = nil, bestAttemptContent: UNMutableNotificationContent? = nil) {
self.payload = payload
Expand All @@ -22,15 +22,19 @@ class RedeemSwapTask : TaskProtocol {
}

public func onEvent(e: BreezEvent) {
if let address = self.swapAddress {
if let address = self.bitcoinAddress {
switch e {
case .reverseSwapUpdated(details: let revSwapInfo):
self.logger.log(tag: TAG, line: "Received reverse swap updated event: \(revSwapInfo.id), current address: \(address) status: \(revSwapInfo.status)\n", level: "INFO")
if case .completedSeen = revSwapInfo.status, case .completedConfirmed = revSwapInfo.status {
self.notifySuccess()
}
break
case .swapUpdated(details: let swapInfo):
self.logger.log(tag: TAG, line: "Received swap updated event: \(swapInfo.bitcoinAddress), current address: \(address) status: \(swapInfo.status)\n", level: "INFO")
if address == swapInfo.bitcoinAddress {
if (swapInfo.paidMsat > 0) {
self.logger.log(tag: TAG, line: "Swap address \(swapInfo.bitcoinAddress) redeemed succesfully", level: "INFO")
let notificationTitle = ResourceHelper.shared.getString(key: Constants.SWAP_TX_CONFIRMED_NOTIFICATION_TITLE, fallback: Constants.DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_TITLE)
self.displayPushNotification(title: notificationTitle, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_SWAP_TX_CONFIRMED)
self.notifySuccess()
}
}
break
Expand All @@ -43,30 +47,44 @@ class RedeemSwapTask : TaskProtocol {
func start(breezSDK: BlockingBreezServices) throws {
do {
let addressTxsConfirmedRequest = try JSONDecoder().decode(AddressTxsConfirmedRequest.self, from: self.payload.data(using: .utf8)!)
swapAddress = addressTxsConfirmedRequest.address
self.bitcoinAddress = addressTxsConfirmedRequest.address
} catch let e {
self.logger.log(tag: TAG, line: "failed to decode payload: \(e)", level: "ERROR")
self.logger.log(tag: TAG, line: "Failed to decode payload: \(e)", level: "ERROR")
self.onShutdown()
throw e
}

guard let address = swapAddress else {
self.logger.log(tag: TAG, line: "Failed to process swap notification: swap address not in payload", level: "ERROR")
guard let address = bitcoinAddress else {
self.logger.log(tag: TAG, line: "Address not in payload", level: "ERROR")
self.onShutdown()
return
}

do {
try breezSDK.redeemSwap(swapAddress: address)
self.logger.log(tag: TAG, line: "Found swap for \(address)", level: "DEBUG")
return
} catch let e {
self.logger.log(tag: TAG, line: "Failed to manually redeem swap notification: \(e)", level: "ERROR")
self.logger.log(tag: TAG, line: "Failed to redeem swap: \(e)", level: "ERROR")
}

do {
try breezSDK.processReverseSwap(lockupAddress: address)
self.logger.log(tag: TAG, line: "Found reverse swap for \(address)", level: "DEBUG")
} catch let e {
self.logger.log(tag: TAG, line: "Failed to process reverse swap: \(e)", level: "ERROR")
}
}

func onShutdown() {
let notificationTitle = ResourceHelper.shared.getString(key: Constants.SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE, fallback: Constants.DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE)
let notificationBody = ResourceHelper.shared.getString(key: Constants.SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TEXT, fallback: Constants.DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TEXT)
self.displayPushNotification(title: notificationTitle, body: notificationBody, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_SWAP_TX_CONFIRMED)
self.displayPushNotification(title: notificationTitle, body: notificationBody, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_ADDRESS_TXS_CONFIRMED)
}

func notifySuccess() {
self.logger.log(tag: TAG, line: "Address \(self.bitcoinAddress) processed successfully", level: "INFO")
let notificationTitle = ResourceHelper.shared.getString(key: Constants.SWAP_TX_CONFIRMED_NOTIFICATION_TITLE, fallback: Constants.DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_TITLE)
self.displayPushNotification(title: notificationTitle, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_ADDRESS_TXS_CONFIRMED)
}
}
Loading

0 comments on commit 133dbdf

Please sign in to comment.