Commit Graph

93 Commits

Author SHA1 Message Date
ok300
ef5cd28fa5 Add FiatAPI methods to Liquid SDK (#331)
* Add FiatAPI methods to Liquid SDK

* Add mirrored structs of fiat crate on Dart bindings

* Re-generate bindings

* Fix sdk-common imports

* Avoid using hardcoded Breez Server URL, re-use sdk-common constant

* Update Cargo.lock

---------

Co-authored-by: Erdem Yerebasmaz <erdem@yerebasmaz.com>
2024-06-26 13:55:44 +00:00
ok300
7bd9b6ddb2 Use swapper proxy to extract referral ID (#329)
* Use swapper proxy to extract referral ID

* Derive swapper API base URL from proxy URL

* Update RN bindings

* Remove referral_id from Config, move proxy_url parsing to swapper

* Fix tests

* Cache swapper proxy URL

* Move boltz_url from Config to swapper

* Silently fail when fetching proxy swapper URLs

* Update RN bindings

* Fix sdk-common dependency

* Fix dependency issues
2024-06-25 17:19:02 +00:00
Ross Savage
9da16fba78 Receive Chain Swaps (#310)
* Implement Chain Swaps for receiving

* Send: validate if we have sufficient funds (#321)

* Implement Chain Swaps for receiving

* Fix rebase of flutter_rust_bridge version

* Send: validate if we have sufficient funds

* Re-generate FRB

---------

Co-authored-by: Ross Savage <hello@satimoto.com>

* Chaim swap claim: remove refund_tx arg (#328)

---------

Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
2024-06-25 17:33:38 +02:00
Erdem Yerebasmaz
8c85ffcf69 Bump flutter_rust_bridge to 2.0.0 (#327) 2024-06-24 13:39:50 +03:00
ok300
bcb4743260 Integrate sdk-common (#308)
* Rename Network to LiquidSdkNetwork to avoid naming conflicts with sdk-common

* Integrate sdk-common: re-use parse_invoice

* Fix UDL bindings tests

* Add input parser support

* CLI: Add input parser support

* Integrate lnurl-pay

* Cargo format, re-generate FRB and RN bindings

* Duplicate LnUrlPayError, update FRB/UniFFI bindings

* Move duplicate LnUrlPayError to FRB bindings.rs

* Add support for lnurl-withdraw

* Lnurl-withdraw: convert units, incorporate fees

* Bump sdk-common, rename InputType::LnUrlError

* Bump sdk-common, remove Wrapped prefix from LnUrlPaySuccessData, LnUrlPayResult

* LNURL-withdraw: add missing UDL mappings

* Add support for LNURL-auth

* Move LNURL structs into models.rs

* Rename LiquidSdkNetwork to LiquidNetwork

* Fix binding tests

* Fix tests

* Move FRB mirroring structs to bindings.rs

* Remove TODO

* Bump sdk-common, remove sdk-common dependency on rusqlite

* Propagate LiquidNetwork rename into flutter example app

* CI: install protobuf before running clippy

* CI: add rust cache, protobuf for remaining rust steps
2024-06-20 16:18:50 +00:00
Ross Savage
428d69729b Implement Chain Swaps for sending (#298) 2024-06-19 12:48:13 +02:00
yse
2b64708e36 Receive: Switch payment to pending state when lockup is in the mempool (#301)
* feat: switch to pending state when receive lockup is in the mempool

* rebasing

* fix: move socket update logic to sub-crate

* Update payments query, to avoid duplicate Receive Swaps

This can happen if the app is stopped before the temporary lockup tx is removed from the DB. The Receive Swap would then forever result in two payments in list_payments.

* Add comments to clarify use of temp lockup txid

* Re-generate flutter bridge bindings

* feat: set Payment `tx_id` as optional and change `list_payments` logic

* fix: debug typo

* fix: undo `remove_temporary_tx` changes

* fix: switch to full join rather than manual filtering

* fix: bindings

* fix: improve error handling when tx data is not present

* fix: RN bindings

* fix: exclude Created receives from the list

* fix: fixing nits

* Re-generate FRB bindings

---------

Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
2024-06-12 20:44:31 +00:00
ok300
31e2ab44af get_info: remove with_scan argument (#306)
* get_info: remove with_scan argument

* Fix binding tests

* Update dart test and kotlin example app

* Update RN example app
2024-06-12 13:23:32 +00:00
Erdem Yerebasmaz
5e2a4fe342 Bump flutter_rust_bridge to 2.0.0-dev.38 (#304)
* Generate Dart bindings
* flutter_rust_bridge has relative path issues with this new approach introduced in 2.0.0-dev.38, we'll be using the default rust_output path until it's addressed.
2024-06-10 14:51:42 +03:00
ok300
2928e0fa58 Add magic routing hint support (#265)
* Receive: Add magic routing hint support

* Send: add MRH support

* Filter out and reject self-transfers

* Extract self-transfer validation in own fn

* PrepareSendResponse: use onchain fee as fees_sat if MRH present

* Use onchain tx fee as payment fee, if MRH used for direct onchain tx

* Fix swap fee calculation when MRH is used

* Apply boltz-client patch that aborts send if tx broadcast fails

* Send with MRH: return pending payment

* Receive with MRH: validate BIP21 amount, address

* Emit remaining events for MRH Send, Receive

* Sync: update swap info and emit events after new tx data is persisted

* Extract MRH send into its own send_payment_via_mrh()

* Pending Send via swap: store tx fees for pseudo-tx

* Fix clippy
2024-06-07 00:40:42 +00:00
Roei Erez
c093d54cac extractd out receive swap handling logic 2024-06-06 13:02:38 +03:00
Roei Erez
f7b7149187 Abstract swapper stream as part of swapper trait 2024-06-03 13:57:20 +03:00
ok300
1cc06cef74 Bump lwk-wollet to fix InsufficientFunds error (#268)
* Bump lwk-wollet to fix InsufficientFunds error

* Re-add swap tracking on Send

* Track Send swap even on re-connect
2024-06-01 11:53:35 +00:00
Ross Savage
5d9a8f18a3 Add Config (#267)
* Add config

* Add rustdocs to Config, send_payment (#271)

---------

Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
2024-06-01 06:32:45 +02:00
ok300
f6082f2aa5 Add global SDK logger (#242)
* Add SDK global logger

* Add bindings

* Fix path to internal uniffi log

* Exclude "set_log_stream" from generated RN methods

* Move logger-specific structs to a separate module

* Delegate init_logging to method in logger.rs

* Rename uniffi BindingLogger to UniffiBindingLogger

* Add set_log_stream for dart bindings

* Add SDK logger to Dart bindings

* Rename dart binding logger to DartBindingLogger

* Add rustdocs

* RN bindings: Add manual handling for setLogStream()

* Re-generate dart bindings

* Re-generate RN bindings

* Remove LOG_INIT cell

* Set global maximum log level once on initialization

Return a LiquidSdkError::Generic instead of Anyhow error when initializing log stream on Dart bindings

* Do not panic when initializing binding loggers

* Rename LogStream to Logger

---------

Co-authored-by: Erdem Yerebasmaz <erdem@yerebasmaz.com>
2024-05-31 18:01:39 +00:00
ok300
e5dba1043e Add ability to parse an invoice (#240)
* Add ability to parse an invoice

* Simplify LNInvoice initialization

* Add missing LNInvoice fields

* Cargo fmt

* Re-generate bindings after merging main branch

* Explicitly check the invoice signature

* Remove redundant signature check

* Strip potential lightning: prefix before parsing bolt11
2024-05-30 13:26:00 +00:00
ok300
434fb80d49 Add shutdown signal (#238)
* Add shutdown signal handling

Revert periodic sync interval change

Revert keep-alive interval change

CLI: Add disconnect command

SDK: Add scaffolding for is_started, shutdown()

Simplify instance init

* Rebase on savage-async-ws branch

* Avoid waiting when shutdown signal is received in the sync loop

* Directly use shutdown signal in background threads

* Acquire is_started lock at the very beginning of start()

* Fix cargo clippy warnings

* Update RN generator (kt): set bindingLiquidSdk to null on disconnect()

* Update RN generator (swift): set bindingLiquidSdk to nil on disconnect()

* Startup: only run foreground sync() if this could be the first run

* Start a sync() in background, before regular sync() loop

* Remove ensure_started check from start()

* Add bindings for disconnect()

* Remove foreground sync condition from startup

* Simplify background sync loop
2024-05-30 08:04:30 +00:00
Ross Savage
e986f75605 Convert the ws handling to async (#234) 2024-05-28 14:20:12 +02:00
Erdem Yerebasmaz
608f54ea69 Bump flutter_rust_bridge_codegen to 2.0.0-dev.36 and generate bindings (#237) 2024-05-28 14:41:47 +03:00
yse
9d2f6f0839 Fix cooperative refund and improve keypair generation (#223)
* feat: add random keypair generation

* Encapsulate decode_keypair in SendSwap::get_refund_keypair()

* Add refund_tx_id and refund_tx_amount_sat to Payment

* fix: remove blocking on refund

* fix: change `refund_private_key` order

* fix: rebasing

* fix: set `next_unused_address` as refund output

* Handle refunds in `get_info`, `list_payments` (#226)

* Exclude refund txs from payment list

* Adjust balance calculation to account for refunds

* fix: revert boltz changes and fix locktime

* Replace subquery with LEFT JOIN to get refund data

* Rewrite locktime check for more clarity

* Rewrite locktime check for more clarity

* Fix select_payment_query in case of refunds

* Include boltz-client fixes (handling of unwraps for failed broadcasts)

* Cargo.toml: Use boltz-client branch instead of commit

---------

Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
2024-05-28 08:07:29 +00:00
yse
2fcefee45e Add option to specify backup path (#228)
* feat: add backup_path to backup method

* Re-generate bindings with flutter_rust_bridge`@ 2.0.0-dev.35

* Rebased on main

* Update backup path description

---------

Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
2024-05-27 19:01:49 +00:00
Ross Savage
06b848a8f3 SDK events framework (#193)
* Add events framework

* Adapt RN codegen and add synced event

* Only use get_connection internally
2024-05-25 06:20:14 +02:00
ok300
ec88a9fb6a Pin security-framework dependencies in Cargo.toml 2024-05-24 11:48:25 +02:00
Ross Savage
e421b95bef Lock security-framework version 2024-05-24 11:22:49 +02:00
ok300
c7b46314f4 Send: Retrieve and store preimage for non-cooperative claim (#222)
* Bump LWK dependencies to v0.5.1

* Send: Retrieve and store preimage for non-cooperative claim

* Remove branch that could have not succeeded
2024-05-24 06:16:41 +00:00
Erdem Yerebasmaz
1fe5bb353c Stop using singleton instance on Dart bindings
Apply changes to test cases on Dart plugin
2024-05-23 10:10:42 +03:00
ok300
c975da5b3c Payment lifecycle (#184)
* Rename swap tables: remove ongoing_ prefix

* Add swap status enums and filtering

* Swap-in: add claim_txid

* Swap-out: add claim_txid

* resolve_swap: Don't remove swap when complete

* Fixups after rebase

* Remove unused method

* Consider payment as pending based on confirmations

An onchain payment with no confirmations is considered
pending. The previous logic of converting pending swaps
into pending payments is removed, since we may have
pending swaps that should not result in pending
payments (for example on Receive, before the invoice
is paid).

* Fix swap-in query

* GetInfoResponse: fix balance, include pending

* Remove unused method

* Re-generate flutter bridge files

* Re-generate RN bindings

* Fix payment_type detection in list_payments

* Send: persist to DB when claim tx is seen

* Receive: fix occasional error when broadcasting claim

* Remove fixed TODO

* Receive: only rescan on testnet, where Electrum is used to broadcast

* Log more details when broadcasting fails

* Improve AlreadyClaimed error detection and handling

* Rename SubmarineSwapStatus::Initial to Created

* Split pending payment types into separate field status

* Rename swap status enums

* Fix INSERT query

* Bump lwk libraries

* Simplify Receive try_handle_reverse_swap_status loop

* Change resolve_swap to insert_or_update_payment

* Refactor payment data persistence

* Remove unused dependency

* Bump LWK dependencies

* Rename reconcile_payments_with_onchain

* Rename try_claim_v2

* Rename address() to next_unused_address()

* Move all claim persistence writes in try_claim

* Flatten Payment struct

* Re-generate bindings

* Expose sync() in service interface

* Set Send ws stream as nonblocking, use singleton stream

* Send_payment: sync() before handling new state

* Sync() on sdk.connect()

* Remove unused args from list_payments()

* Receive: rename DB field redeem_script to response JSON

* Convert to and from internal structs to persist CreateResponse JSON

* De-duplicate internal CreateResponse structs to prevent storing same field twice

* Schedule a periodic sync() thread on startup

* Persist swap states and add methods to transition between them

* Handle unwrap() when subscribing for WS updates

* Status Stream: handle remaining unwraps() and TODOs

* Consolidate status transitions into two SDK methods

* Status Stream: reconnect and resume tracking on disconnect

* Remove superfluous TODO

* Send swaps: correctly transition to Complete even if app killed during send_payment()

* State transitions: Move SQL queries to persistence layer

* Send: handle edge TransactionClaimed edge-case

* Send: mark as Complete after we check the preimage

* Send: remove marking as Complete on TransactionClaimed
2024-05-22 20:00:38 +00:00
Ross Savage
7787267275 Build android fixes
Signed-off-by: Ross Savage <hello@satimoto.com>
2024-05-21 12:31:59 +02:00
yse
5a9dc1d5ce feat: fix fee calculation issues 2024-05-14 13:05:55 +02:00
yse
55804e88c5 feat: add double lockup checks and resolve on claim details 2024-05-14 13:05:55 +02:00
yse
a92e83a446 feat: improve send and refund 2024-05-14 13:05:54 +02:00
yse
28d4f264eb feat: add refund and improve send flow 2024-05-14 13:05:27 +02:00
ok300
6b58682a91 Receive: broadcast claim tx when lockup tx in mempool 2024-05-12 18:34:44 +02:00
ok300
fb7190032a Bump boltz-rust client to latest patch level 2024-05-09 21:22:57 +02:00
ok300
d67756bf43 Migrate receive-payment to V2 API, use WS to get status 2024-05-09 16:09:12 +00:00
yse
18257dbc91 feat: migrate send_payment to v2 (#171) 2024-05-09 15:47:23 +03:00
yse
be3120c935 feat: remove PrepareSendResponse fields
feat: add `PrepareSendRequest` object

fix: rename to `claim_tx_feerate`

fix: fix reverse submarine test

feat: improve prepare_send and prepare_receive interfaces

fix: use v2 to broadcast lowball tx

feat: finalize prepare_send and prepare_receive

feat: remove manual BTC pair from response

fix: remove `pair_hash` from PrepareReceive

rebasing

updating Cargo.lock

fix: update lbtc pair method names

fixing bindings

fix: re-add uniffi_macros

add comment to elements dependency

fix: switch back to v1 fee calculation

fix: revert to v1 pair hash

fix: simplify migrations

fix: rename `FeesExpired` to `InvalidOrExpiredFees`

Log error when list_ongoing_swaps() fails

Log swap ID when list_ongoing_swaps() succeeds

Migrations: add missing ongoing_receive_swaps field

Clarify swap type (reverse vs submarine) in logs
2024-05-09 11:26:10 +03:00
Erdem Yerebasmaz
05689299f0 Update flutter_rust_bridge to 2.0.0-dev.33
Update dependencies to latest & increase the supported range
2024-05-06 14:58:31 +03:00
ok300
8a1508ab07 Rename wallet to SDK or LiquidSdk (#157)
* Rename global instance in bindings.rs

* Rename wallet to SDK or LiquidSdk

* Rename BindingWallet to BindingLiquidSdk

* Rename wallet to lwk_wollet, signer to lwk_signer

* Rename LsSdkError to LiquidSdkError

* Cargo fmt

* Rename LsSdkError in RN generator

---------

Co-authored-by: Ross Savage <hello@satimoto.com>
2024-05-03 13:53:37 +00:00
Ross Savage
267819bb08 Change secp256k1-zkp dependency git source 2024-05-03 15:15:49 +02:00
ok300
708a3526c7 Add request, response to API methods (#153)
* Add request, response to get_info()

* Add request, response to prepare_send_payment()

* Add request, response to restore()

* Add request, response to connect()

* Update lib/bindings/src/breez_liquid_sdk.udl

Co-authored-by: Ross Savage <551697+dangeross@users.noreply.github.com>

* Update lib/bindings/src/breez_liquid_sdk.udl

Co-authored-by: Ross Savage <551697+dangeross@users.noreply.github.com>

* Update lib/core/src/bindings.rs

Co-authored-by: Ross Savage <551697+dangeross@users.noreply.github.com>

* Fix bindings.rs call

* Update connect to handle ConnectRequest

---------

Co-authored-by: Ross Savage <551697+dangeross@users.noreply.github.com>
Co-authored-by: Ross Savage <hello@satimoto.com>
2024-05-03 08:48:03 +00:00
ok300
92542876e5 Merge branch 'ok300-rename-lib-folders' 2024-05-02 21:11:55 +02:00
ok300
33815fac05 Integrate ureq fix from Boltz Client (#148) 2024-05-02 18:29:45 +00:00
ok300
3df6a5c3d4 CLI: Allow choosing custom network (#151)
* CLI: Allow choosing custom network

* Cargo fmt
2024-05-02 18:27:31 +00:00
ok300
6589a8799b Rename workspace members (subfolders) (#149)
* Rename ls-sdk-bindings workspace member

* Rename ls-sdk-core workspace member

* Rename ls-sdk-react-native
2024-05-02 18:22:32 +00:00
ok300
ce637b15bb Rename ls-sdk-core workspace member 2024-05-02 18:03:44 +02:00
ok300
a0a852b223 Merge branch 'ok300-rename-rust'
# Conflicts:
#	lib/ls-sdk-bindings/makefile
2024-05-02 08:11:44 +02:00
ok300
080698c2d1 Update receive to support only payer amount (#131) 2024-05-02 06:00:56 +00:00
ok300
cb7e753c95 Rename project: Rust, uniffi (#133)
* Rename rust crates, uniffi bindings

* Rename uniffi tests

* Rename uniffi UDL file
2024-05-02 05:44:47 +00:00
Ross Savage
7add324b2a Rename android, swift and react native bindings 2024-04-30 22:46:27 +02:00