Skip to content

Commit

Permalink
added psbt::input crate
Browse files Browse the repository at this point in the history
  • Loading branch information
willowens14 committed Sep 20, 2023
1 parent d2b67e1 commit 5cc9dd4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cont_integration.yml
Expand Up @@ -61,6 +61,7 @@ jobs:
cargo update -p flate2 --precise 1.0.26
cargo update -p reqwest --precise "0.11.18"
cargo update -p h2 --precise "0.3.20"
cargo update -p rustls --precise "0.20.8"
- name: Build
run: cargo build --no-default-features --features repl,${{ matrix.features }}
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Expand Up @@ -12,7 +12,6 @@ readme = "README.md"
license = "MIT"

[dependencies]
# right here set path
bdk = { version = "0.27.1", default-features = false, features = ["all-keys"] }
bdk-macros = "0.6"
clap = { version = "3.2.22", features = ["derive"] }
Expand All @@ -25,7 +24,7 @@ base64 = "^0.13"
# payjoin dependencies
payjoin = { version = "=0.8.2", features = ["send"] }
# reqwest
reqwest = { version = "0.11.4", features = ["blocking"] }
reqwest = { version = "0.10.10", features = ["blocking"] }



Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -143,6 +143,8 @@ cargo update -p flate2 --precise 1.0.26
cargo update -p reqwest --precise "0.11.18"
# h2 0.3.21 has MSRV 1.63.0+
cargo update -p h2 --precise "0.3.20"
# rustls 0.20.9 has MSRV 1.60.0+
cargo update -p rustls --precise "0.20.8"
```

## Resources
Expand Down
1 change: 1 addition & 0 deletions src/commands.rs
Expand Up @@ -527,6 +527,7 @@ pub enum OnlineWalletSubCommand {
#[clap(name = "CONFIRMATIONS", long = "confirmations", default_value = "6")]
confirmations: u32,
},
#[cfg(not(feature = "async-interface"))]
/// Sends a Payjoin Transaction. Takes a valid payjoin bip21 uri.
SendPayjoin {
/// Sets the bip21 uri to send to.
Expand Down
16 changes: 10 additions & 6 deletions src/handlers.rs
Expand Up @@ -26,7 +26,6 @@ use bdk::{database::BatchDatabase, wallet::AddressIndex, Error, FeeRate, Keychai

use clap::Parser;


use bdk::bitcoin::consensus::encode::{deserialize, serialize, serialize_hex};
#[cfg(any(
feature = "electrum",
Expand Down Expand Up @@ -88,9 +87,9 @@ use rustyline::error::ReadlineError;
use rustyline::Editor;
use serde_json::json;
use std::str::FromStr;
// Import some modules for payjoin functionality from payjoin crate
// Import some modules for payjoin functionality

/// Execute an offline wallet sub-command
// Execute an offline wallet sub-command
///
/// Offline wallet sub-commands are described in [`OfflineWalletSubCommand`].
pub fn handle_offline_wallet_subcommand<D>(
Expand Down Expand Up @@ -323,7 +322,11 @@ where
B: Blockchain,
D: BatchDatabase,
{
use bdk::{signer::InputSigner, wallet::tx_builder, SyncOptions};
use crate::bitcoin::psbt::Input;
use bdk::SyncOptions;
use payjoin::PjUriExt;
use payjoin::UriExt;
use std::convert::TryFrom;

match online_subcommand {
Sync => {
Expand Down Expand Up @@ -396,6 +399,7 @@ where
Ok(json!({ "spendable": spendable }))
}

#[cfg(not(feature = "async-interface"))]
// Payjoin Logic goes here
SendPayjoin { uri } => {
// convert the bip21 uri into a payjoin uri, and handle error if necessary
Expand All @@ -406,7 +410,7 @@ where
// ensure uri is payjoin capable
let uri = uri
.check_pj_supported()
.map_err(|e| Error::Generic(format!("Payjoin not supported: {}", e)))?;
.map_err(|e| Error::Generic(format!("Payjoin not supported: {}", e.to_string())))?;

// ensure amount of satoshis is specified in uri, handle error if not
let sats = match uri.amount {
Expand Down Expand Up @@ -483,7 +487,7 @@ where
// get original inputs from original psbt clone (ocean_psbt)
let mut original_inputs = input_pairs(&mut ocean_psbt).peekable();

for (proposed_txin, mut proposed_psbtin) in input_pairs(&mut payjoin_psbt) {
for (proposed_txin, proposed_psbtin) in input_pairs(&mut payjoin_psbt) {
if let Some((original_txin, original_psbtin)) = original_inputs.peek() {
if proposed_txin.previous_output == original_txin.previous_output {
proposed_psbtin.witness_utxo = original_psbtin.witness_utxo.clone();
Expand Down

0 comments on commit 5cc9dd4

Please sign in to comment.