Skip to content

Conversation

@danielgranhao
Copy link
Collaborator

@danielgranhao danielgranhao commented Sep 4, 2025

This PR adds support for token Payments on the Breez SDK API.

Main todos:

  • Implement transaction to payments conversion
  • Use spark address data if provided (sats vs tokens, amount)
  • Handle errors
  • Use sparkscan for syncing payments

Out of scope (left for separate PRs):

  • Support 128-bit token amounts in bindings.
  • Updating docs
  • Spark addresses allow encoding if the recipient expects Bitcoin/specific token and an optional amount, effectively turning them into invoices. I propose we support this in receive_payment in a follow-up PR: Spark invoice support #212

@danielgranhao danielgranhao force-pushed the daniel-breez-sdk-token-support branch 3 times, most recently from 45912a0 to 158783f Compare September 5, 2025 10:11
Copy link
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we'll hit issues with the u128 casting? Like with the max supply

@danielgranhao
Copy link
Collaborator Author

Do you think we'll hit issues with the u128 casting? Like with the max supply

Definitely! The idea is to address that in a separate PR. u128 is not natively supported by uniffi but we think it should be possible to expose it using custom types with custom lifting and lowering implementations

@danielgranhao danielgranhao force-pushed the daniel-breez-sdk-token-support branch from 0129e56 to 7d223d9 Compare September 7, 2025 11:59
@danielgranhao danielgranhao force-pushed the daniel-breez-sdk-token-support branch 2 times, most recently from 41a942c to fc35449 Compare September 8, 2025 13:27
@danielgranhao
Copy link
Collaborator Author

PR is ready for review - still keeping as a draft just because it's missing the query ordering field. As a result, payments are currently not properly synced, but they can still be received or sent.

@danielgranhao danielgranhao force-pushed the daniel-breez-sdk-token-support branch 3 times, most recently from 1865a79 to ba0a2df Compare September 9, 2025 10:44
@danielgranhao danielgranhao marked this pull request as ready for review September 9, 2025 10:44
@danielgranhao danielgranhao force-pushed the daniel-breez-sdk-token-support branch from ba0a2df to f5749cc Compare September 9, 2025 10:49
Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@danielgranhao danielgranhao marked this pull request as draft September 9, 2025 14:18
@danielgranhao danielgranhao force-pushed the daniel-breez-sdk-token-support branch from 9ed94d5 to e87a192 Compare September 12, 2025 16:36
@danielgranhao
Copy link
Collaborator Author

danielgranhao commented Sep 12, 2025

I've added a commit that introduces the use of sparkscan to sync payments. Unfortunately, for now, there's no good way for us to use SparkScan to query pending ones (no batch option to query transactions by id, and querying 1 by 1 will likely lead to reaching api limits), so to do that, we still use the SO api. We may switch to a full sparkscan-based approach when batching is available.

Other noteworthy changes:

  • Moved all model conversion logic out of models and into adaptors, separated into spark-sdk and sparkscan modules
  • When sending a tokens payment, we insert a locally constructed pending payment in the storage (if we try to immediately query sparkscan it may not yet know of the transaction)
  • Changed the default regtest env from loadtest to prod. We are forced to do this because it's the env that sparkscan runs on.

I still need to add tests and test more, but I would appreciate an initial pass of the current state of the PR.

Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I very like that. I like the fact we sync pending payments for now separately, seems less vulnerable to sync issues.

Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@danielgranhao danielgranhao force-pushed the daniel-breez-sdk-token-support branch from e87a192 to c5d08cb Compare September 15, 2025 12:18
@danielgranhao danielgranhao changed the base branch from main to daniel-fix-lnurl-signer-usage September 15, 2025 12:18
@danielgranhao danielgranhao changed the base branch from daniel-fix-lnurl-signer-usage to main September 15, 2025 12:20
@danielgranhao danielgranhao force-pushed the daniel-breez-sdk-token-support branch from c5d08cb to c36def8 Compare September 15, 2025 12:21
@danielgranhao danielgranhao force-pushed the daniel-breez-sdk-token-support branch from 9182f6b to 9c70b27 Compare October 6, 2025 12:08
Copy link
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Added my final comments.

@danielgranhao danielgranhao requested a review from roeierez October 7, 2025 18:21
Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@danielgranhao danielgranhao merged commit aea3bd9 into main Oct 7, 2025
8 checks passed
@danielgranhao danielgranhao deleted the daniel-breez-sdk-token-support branch October 7, 2025 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants