Skip to content

Commit

Permalink
Get payjoin working with 0.20 cut-through
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Sep 24, 2024
1 parent e88ee73 commit be0420f
Show file tree
Hide file tree
Showing 10 changed files with 728 additions and 513 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/api/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl BriaService for Bria {
) -> Result<Response<NewUriResponse>, Status> {
crate::tracing::record_error(|| async move {
extract_tracing(&request);
println!("REQ");
dbg!("REQ");

let key = extract_api_token(&request)?;
let profile = self.app.authenticate(key).await?;
Expand Down
11 changes: 5 additions & 6 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ impl App {
let keychain_wallet = wallet.current_keychain_wallet(&self.pool);
let addr = keychain_wallet.new_external_address().await?;
let address = Address::from(addr.address.clone());
println!("got address: {:?}", addr.address);
dbg!("got address: {:?}", addr.address);
let mut builder = NewAddress::builder();
builder
.address(address.clone())
Expand All @@ -546,11 +546,10 @@ impl App {
}
let new_address = builder.build().expect("Couldn't build NewUri");
self.addresses.persist_new_address(new_address).await?;
println!("init payjoin");
let (session, ohttp_keys) = crate::payjoin::init_payjoin_session(payjoin::bitcoin::Address::from_str(&address.to_string()).unwrap().assume_checked(), self.pj.clone(), profile.account_id).await?;
println!("init'd payjoin");
// TODO save session to DB
let uri = session.pj_uri_builder().amount(payjoin::bitcoin::Amount::from_sat(600_000)).build().to_string();
dbg!("init payjoin");
let (session, ohttp_keys) = self.pj.init_payjoin_session(&profile.account_id, payjoin::bitcoin::Address::from_str(&address.to_string()).unwrap().assume_checked()).await?;
dbg!("init'd payjoin");
let uri = session.session.pj_uri_builder().amount(payjoin::bitcoin::Amount::from_sat(600_000)).build().to_string();
Ok((wallet.id, uri))
}

Expand Down
2 changes: 2 additions & 0 deletions src/batch/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Batch {
pub wallet_summaries: HashMap<WalletId, WalletSummary>,
pub unsigned_psbt: bitcoin::psbt::PartiallySignedTransaction,
pub signed_tx: Option<bitcoin::Transaction>,
pub provisional_proposal: Option<payjoin::receive::v2::ProvisionalProposal>,
}

impl Batch {
Expand All @@ -31,6 +32,7 @@ pub struct NewBatch {
pub(super) total_fee_sats: Satoshis,
pub(super) unsigned_psbt: bitcoin::psbt::PartiallySignedTransaction,
pub(super) wallet_summaries: HashMap<WalletId, WalletSummary>,
pub(super) provisional_proposal: Option<payjoin::receive::v2::ProvisionalProposal>,
}

impl NewBatch {
Expand Down
2 changes: 2 additions & 0 deletions src/job/batch_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub async fn execute(
let mut stalled = false;
let mut last_err = None;
let mut current_keychain = None;
// get provisional proposal psbt to replace batch.unsigned_psbt out with an mpsc channel, sign it, and replace it with the result with a channel back into the finalize_psbt wallet_process_psbt closure
let (mut sessions, mut account_xpub_cache) = if let Some(batch_session) = signing_sessions
.list_for_batch(data.account_id, data.batch_id)
.await?
Expand Down Expand Up @@ -112,6 +113,7 @@ pub async fn execute(
continue;
}
};
// switch session.unsigned_psbt to provisional_proposal.finalize_psbt(|psbt|)
match client.sign_psbt(&session.unsigned_psbt).await {
Ok(psbt) => {
session.remote_signing_complete(psbt);
Expand Down
29 changes: 13 additions & 16 deletions src/job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,6 @@ pub async fn spawn_process_payout_queue(
.await
}

pub async fn spawn_payjoin_payout_queue(
pool: &sqlx::PgPool,
data: impl Into<ProcessPayoutQueueData>,
) -> Result<ProcessPayoutQueueData, JobError> {
let data = data.into();
onto_account_main_channel(
pool,
data.account_id,
Uuid::new_v4(),
"payjoin_payout_queue",
data,
)
.await
}

#[job(name = "schedule_process_payout_queue")]
async fn schedule_process_payout_queue(mut current_job: CurrentJob) -> Result<(), JobError> {
let pool = current_job.pool().clone();
Expand Down Expand Up @@ -716,7 +701,19 @@ impl From<(AccountId, PayoutQueueId)> for ProcessPayoutQueueData {
payout_queue_id,
account_id,
batch_id: BatchId::new(),
payjoin: None,
payjoin_session: None,
tracing_data: crate::tracing::extract_tracing_data(),
}
}
}

impl From<(AccountId, PayoutQueueId, payjoin::receive::v2::WantsOutputs)> for ProcessPayoutQueueData {
fn from((account_id, payout_queue_id, session): (AccountId, PayoutQueueId, payjoin::receive::v2::WantsOutputs)) -> Self {
Self {
payout_queue_id,
account_id,
batch_id: BatchId::new(),
payjoin_session: Some(session),
tracing_data: crate::tracing::extract_tracing_data(),
}
}
Expand Down
Loading

0 comments on commit be0420f

Please sign in to comment.