-
Notifications
You must be signed in to change notification settings - Fork 130
Add Payjoin Receiver Support (BIP 77) #746
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
Open
Camillarhi
wants to merge
1
commit into
lightningdevkit:main
Choose a base branch
from
Camillarhi:payjoin-receiver
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,13 +18,16 @@ use bdk_wallet::{KeychainKind as BdkKeyChainKind, Update as BdkUpdate}; | |
| use bitcoin::{FeeRate, Network, Script, ScriptBuf, Transaction, Txid}; | ||
| use electrum_client::{ | ||
| Batch, Client as ElectrumClient, ConfigBuilder as ElectrumConfigBuilder, ElectrumApi, | ||
| Error as ElectrumError, | ||
| }; | ||
| use lightning::chain::{Confirm, Filter, WatchedOutput}; | ||
| use lightning::util::ser::Writeable; | ||
| use lightning_transaction_sync::ElectrumSyncClient; | ||
|
|
||
| use super::WalletSyncStatus; | ||
| use crate::config::{Config, ElectrumSyncConfig, BDK_CLIENT_STOP_GAP}; | ||
| use crate::config::{ | ||
| Config, ElectrumSyncConfig, BDK_CLIENT_STOP_GAP, DEFAULT_TX_LOOKUP_TIMEOUT_SECS, | ||
| }; | ||
| use crate::error::Error; | ||
| use crate::fee_estimator::{ | ||
| apply_post_estimation_adjustments, get_all_conf_targets, get_num_block_defaults_for_target, | ||
|
|
@@ -288,6 +291,21 @@ impl ElectrumChainSource { | |
| electrum_client.broadcast(tx).await; | ||
| } | ||
| } | ||
|
|
||
| pub(crate) async fn get_transaction(&self, txid: &Txid) -> Result<Option<Transaction>, Error> { | ||
| let electrum_client: Arc<ElectrumRuntimeClient> = | ||
| if let Some(client) = self.electrum_runtime_status.read().unwrap().client().as_ref() { | ||
| Arc::clone(client) | ||
| } else { | ||
| debug_assert!( | ||
| false, | ||
| "We should have started the chain source before getting transactions" | ||
| ); | ||
| return Err(Error::TxLookupTimeout); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we returning a |
||
| }; | ||
|
|
||
| electrum_client.get_transaction(txid).await | ||
| } | ||
| } | ||
|
|
||
| impl Filter for ElectrumChainSource { | ||
|
|
@@ -652,6 +670,37 @@ impl ElectrumRuntimeClient { | |
|
|
||
| Ok(new_fee_rate_cache) | ||
| } | ||
|
|
||
| async fn get_transaction(&self, txid: &Txid) -> Result<Option<Transaction>, Error> { | ||
| let electrum_client = Arc::clone(&self.electrum_client); | ||
| let txid_copy = *txid; | ||
|
|
||
| let spawn_fut = | ||
| self.runtime.spawn_blocking(move || electrum_client.transaction_get(&txid_copy)); | ||
| let timeout_fut = | ||
| tokio::time::timeout(Duration::from_secs(DEFAULT_TX_LOOKUP_TIMEOUT_SECS), spawn_fut); | ||
|
|
||
| match timeout_fut.await { | ||
| Ok(res) => match res { | ||
| Ok(inner_res) => match inner_res { | ||
| Ok(tx) => Ok(Some(tx)), | ||
| Err(ElectrumError::Protocol(_)) => Ok(None), | ||
| Err(e) => { | ||
| log_error!(self.logger, "Failed to get transaction {}: {}", txid, e); | ||
| Err(Error::TxLookupFailed) | ||
| }, | ||
| }, | ||
| Err(e) => { | ||
| log_error!(self.logger, "Failed to get transaction {}: {}", txid, e); | ||
| Err(Error::TxLookupFailed) | ||
| }, | ||
| }, | ||
| Err(e) => { | ||
| log_error!(self.logger, "Failed to get transaction {} due to timeout: {}", txid, e); | ||
| Err(Error::TxLookupTimeout) | ||
| }, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Filter for ElectrumRuntimeClient { | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given we're about to finally drop the
reqwest/urldependencies from our dependency tree soon, it's a bit unfortunate that payjoin might take some more time to do so. I guess that's however expected.I do however wonder about the other dependencies, e.g., are there any further efforts to reduce the dependency tree? (cc @spacebear21 @bc1cindy)