Repository navigation
feat: pay contacts via spark #1754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
121 commits
Select commit
Hold shift + click to select a range
f00fb41
feat: pay contacts via spark
ovitrif ba97f20
chore: merge feat/breez-spark-lightning
ovitrif 648403b
chore: merge feat/breez-spark-lightning
ovitrif 2541718
chore: merge feat/breez-spark-lightning
ovitrif abe553d
chore: merge feat/breez-spark-lightning
ovitrif 125feaa
chore: merge feat/breez-spark-lightning
ovitrif 6c86082
chore: merge feat/breez-spark-lightning
ovitrif 735b5a9
feat: route paykit payments with bitkit-core spark.2
ovitrif 2c2d29f
chore: merge feat/breez-spark-lightning
ovitrif 26d976e
fix: record spark withdrawals to contacts
ovitrif 1cbb4b6
fix: offer spark when savings cannot pay a contact
ovitrif a7fcf69
chore: merge feat/breez-spark-lightning
ovitrif bd755b8
feat: route every contact payment through the paykit router
ovitrif a792f94
fix: show the app's copy when no route pays a contact
ovitrif b37ea91
fix: tell an unpayable contact from a short balance
ovitrif 47bf675
chore: merge feat/breez-spark-lightning
ovitrif 25b40e0
chore: move to bitkit-core 0.8.0-spark.3
ovitrif 964218c
chore: translate the no-route copy
ovitrif 47a1484
feat: pay payment requests from spark through the router
ovitrif c106fb0
fix: keep a spark withdrawal proof through backup
ovitrif d49fc3f
fix: keep contact withdrawals out of transfers to savings
ovitrif 154f273
fix: tie spark withdrawals to their attempt and confirmed fee
ovitrif 12ae219
fix: pay requests savings cannot cover from spark
ovitrif 32d546d
test: keep the spark leg for onchain and usdt contacts
ovitrif adabea8
fix: keep an uncertain spark send in flight
ovitrif a800647
fix: settle the withdrawal journal only after a fresh sync
ovitrif 49439d2
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif 634d66d
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif 127c617
fix: block the swipe when a source switch finds no route
ovitrif 30ca31d
fix: release the private list of an unsent spark withdrawal
ovitrif 951c0a6
fix: recheck a spark-routed request's amount before confirm
ovitrif 72ee2a5
fix: keep a listed spark withdrawal's journal until it saves
ovitrif 9b5b1c4
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif f354717
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif 5020923
fix: keep a starting spark withdrawal's proof from reconcile
ovitrif 8c601a0
fix: keep an unlisted spark withdrawal open for a grace period
ovitrif 3543bc8
fix: reroute every source switch after spark finds no route
ovitrif a7bef98
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif 590f925
fix: settle a spark send's allowance attempt on reconcile
ovitrif 1e3aa5d
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif b22c249
fix: resolve a pending spark send once reconcile finds it sent
ovitrif 03f22e6
fix: fail a pending spark send once reconcile finds it unsent
ovitrif 20ac89e
fix: end a spark withdrawal spark returns as failed as a refusal
ovitrif d79cced
fix: drop a paykit route that returns after its payment changed
ovitrif 4439a24
fix: settle an uncertain spark send to a contact from its journal
ovitrif 5584e40
fix: settle an expired spark withdrawal journal on each sync
ovitrif b905364
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif 0c74a5b
fix: keep an unselected lnurl's limits off a spark leg
ovitrif 4bd0732
fix: keep a spark withdrawal journal until spark lists it
ovitrif 370653f
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif cac9d12
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif 55e4991
fix: drop a late spark settlement once its send sheet closed
ovitrif 31298c4
fix: register an uncertain spark send before reading its outcome
ovitrif 2b34a65
fix: open success for a request's spark send spark already lists
ovitrif 6d38782
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif bc0db90
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif 9ab62cf
fix: clear a spark withdrawal journal only while it is still open
ovitrif 3a77a65
chore: log private payment list publication
ovitrif e329c25
fix: keep a dismissed payment request from popping up again
ovitrif 2d13bba
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif de768f8
fix: announce a spark withdrawal's settlement only when its journal c…
ovitrif 5a98c0a
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif 038668a
Merge remote-tracking branch 'origin/feat/breez-spark-lightning' into…
ovitrif 7521d5f
fix: check the quote deadline right before a spark withdrawal sends
ovitrif d15dc9f
fix: release a spark proof refused at its deadline at once
ovitrif 2bd07b7
chore: merge feat/breez-spark-lightning into feat/paykit-spark-route
ovitrif 13d95cb
fix: keep a spark withdrawal journal until a sync reaches spark
ovitrif 4369e44
fix: price a spark-funded onchain request at its onchain rate
ovitrif 33db490
fix: keep a failed spark withdrawal open after a sync that never reac…
ovitrif fb33851
chore: merge feat/breez-spark-lightning into feat/paykit-spark-route
ovitrif ee69de3
chore: merge feat/breez-spark-lightning into feat/paykit-spark-route
ovitrif 81fdf50
fix: keep an accepted spark withdrawal sent after a restart
ovitrif 0f5d7e5
fix: drop a paykit route quote once its amount or source changed
ovitrif 49e1aea
chore: merge feat/breez-spark-lightning into feat/paykit-spark-route
ovitrif 5bac80a
fix: restore the endpoint a paykit reroute picks
ovitrif 2674c84
fix: weigh a spark withdrawal leg against the whole balance
ovitrif 352a129
fix: keep a cached spark withdrawal from settling a retry
ovitrif 47296c6
fix: check a spark withdrawal's deadline after its journal
ovitrif 62c6424
fix: keep a spark withdrawal's journal until its tags save
ovitrif eee7d23
refactor: drop a private list release that never runs
ovitrif 6056afe
refactor: hold paykit route endpoints in an immutable list
ovitrif 82c446d
fix: hide boost on a pending spark withdrawal
ovitrif cf8840e
fix: settle a deleted spark withdrawal it cannot tag
ovitrif 801b660
fix: keep a spark send pending when its outcome read fails
ovitrif ed3bffc
fix: validate a spark withdrawal against its debit and spark's balance
ovitrif bc76a61
Merge remote-tracking branch 'origin/master' into HEAD
ovitrif 7ff99a2
fix: check a rerouted lnurl's minimum before confirm
ovitrif c73f0cd
fix: check a rerouted lnurl's maximum before confirm
ovitrif 4642457
fix: offer the spark leg when lightning pays the lnurl minimum
ovitrif 218000b
fix: skip the spark quote when lightning pays a contact
ovitrif 3d58693
fix: route mixed bitcoin contacts through spark
ovitrif db16625
fix: hold a pending spark withdrawal until spark completes it
ovitrif 76ed400
fix: close a spark withdrawal spark refuses before sending at once
ovitrif b6dba15
fix: refuse a second spark withdrawal while one prepares
ovitrif a4a35f6
fix: keep boost on the savings receipt of a spark withdrawal
ovitrif bd4b727
fix: keep an lnurl its limits refuse out of the contact route
ovitrif 5a168c5
fix: show a short balance when the spark fee does not fit
ovitrif 7374cec
fix: keep confirm closed for a request past the lnurl maximum
ovitrif 37979f8
Merge remote-tracking branch 'origin/master' into HEAD
ovitrif 5042f41
fix: let savings pay a contact below its lnurl minimum
ovitrif eb6e8e1
fix: leave an open contact withdrawal off spark's transfers to savings
ovitrif 6370c37
fix: close a contact withdrawal spark refuses for a fee rise at once
ovitrif d1b899a
fix: skip the lnurl invoice fetch for an on-chain contact payment
ovitrif a5022fe
fix: refuse a spark contact leg while an earlier withdrawal settles
ovitrif 315cd03
fix: confirm an on-chain contact payment with its on-chain details
ovitrif b43fae9
fix: drop a spark leg's fee when the router picks the lnurl
ovitrif ba94a58
fix: show a spark leg's address as its confirm recipient
ovitrif f2654b0
Merge remote-tracking branch 'origin/master' into HEAD
ovitrif 1f1a42e
fix: route paykit payments with bitkit-core rc14
ovitrif 37276e7
fix: show tags and hide the lnurl comment on a spark leg
ovitrif 3815386
fix: drop the spark leg fee on a direct bolt11 pick
ovitrif f9ad001
fix: confirm a spark withdrawal from the chain
ovitrif aa09b77
fix: keep a returned spark withdrawal in flight until it is recorded
ovitrif e0221f9
fix: match a spark withdrawal by its idempotency key
ovitrif c220ce5
chore: merge master into the paykit spark route branch
ovitrif b7c748f
test: stub spark sends with their idempotency key
ovitrif 8cb1a6d
fix: confirm a spark payout the contact already spent
ovitrif 82ef38a
docs: move the spark withdrawal journal kdoc onto clearJournal
ovitrif 3ab29cd
test: pass the payout chain to the spark repo in lightning repo tests
ovitrif 2511a60
fix: show a spark leg's fee on request confirm
ovitrif b5fa153
fix: confirm a spark payout when electrum fails, keeping its seen time
ovitrif File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package to.bitkit.data | ||
|
|
||
| import io.ktor.client.HttpClient | ||
| import io.ktor.client.request.get | ||
| import io.ktor.client.statement.bodyAsText | ||
| import io.ktor.http.HttpStatusCode | ||
| import io.ktor.http.isSuccess | ||
| import kotlinx.serialization.json.Json | ||
| import kotlinx.serialization.json.boolean | ||
| import kotlinx.serialization.json.jsonObject | ||
| import kotlinx.serialization.json.jsonPrimitive | ||
| import org.lightningdevkit.ldknode.Network | ||
| import to.bitkit.env.Env | ||
| import to.bitkit.ext.runSuspendCatching | ||
| import to.bitkit.utils.Logger | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| /** | ||
| * Whether a Spark withdrawal's payout transaction is mined, asked of the Esplora chain Spark reads. Unlike the payout | ||
| * address's unspent outputs, the transaction's status still answers once the contact has spent the payout. | ||
| */ | ||
| @Singleton | ||
| class SparkPayoutChain @Inject constructor( | ||
| private val client: HttpClient, | ||
| ) { | ||
| companion object { | ||
| private const val TAG = "SparkPayoutChain" | ||
| private const val SPARK_REGTEST_ESPLORA_URL = "https://regtest-mempool.us-west-2.sparkinfra.net/api" | ||
| private val json = Json { ignoreUnknownKeys = true } | ||
|
|
||
| /** The Esplora to ask on [network]: the one Spark reads there, or null where the app knows none. */ | ||
| fun esploraUrl(network: Network): String? = when (network) { | ||
| Network.BITCOIN -> Env.bitkitEsploraUrl | ||
| Network.REGTEST -> SPARK_REGTEST_ESPLORA_URL | ||
| else -> null | ||
| } | ||
| } | ||
|
|
||
| /** Whether [txid] is in a block; null when this network has no Esplora to ask or the lookup failed. */ | ||
| suspend fun isMined(txid: String): Boolean? { | ||
| val baseUrl = esploraUrl(Env.network) ?: return null | ||
| return runSuspendCatching { | ||
| val response = client.get("$baseUrl/tx/$txid/status") | ||
| // Spark can list a payout before it is broadcast, and the chain then knows no such transaction yet. | ||
| if (response.status == HttpStatusCode.NotFound) return@runSuspendCatching false | ||
| check(response.status.isSuccess()) { "status ${response.status.value}" } | ||
| json.parseToJsonElement(response.bodyAsText()).jsonObject.getValue("confirmed").jsonPrimitive.boolean | ||
| }.getOrElse { | ||
| Logger.warn("Failed to look up Spark payout transaction '$txid'", it, context = TAG) | ||
| null | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.