Skip to content

Commit

Permalink
psbt: avoid dependencies on bpstd when bp feature is not active
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jan 25, 2025
1 parent c2870c8 commit 97f780a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ nonasync = "0.1.2"
strict_encoding = "2.8.1"
strict_types = "2.8.1"
commit_verify = "=0.12.0-beta.4"
bp-core = "=0.12.0-beta.4"
bp-std = { version = "=0.12.0-beta.4", features = ["client-side-validation"] }
bp-electrum = "=0.12.0-beta.4"
bp-esplora = { version = "=0.12.0-beta.4", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion psbt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ name = "rgpsbt"

[dependencies]
amplify = { workspace = true }
commit_verify = { workspace = true }
rgb-std = { workspace = true, features = ["bitcoin"] }
bp-core = { workspace = true }
bp-std = { workspace = true, optional = true }

[features]
Expand Down
9 changes: 6 additions & 3 deletions psbt/src/bp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@

use amplify::ByteArray;
use bpstd::seals::{mmb, mpc};
use bpstd::{Psbt, Sats, ScriptPubkey, Unmodifiable, Vout};
use bpstd::{Psbt, Sats, ScriptPubkey, Vout};
use rgb::popls::bp::PrefabBundle;

use crate::common::RgbPsbtUnfinalizable;
use crate::{RgbPsbt, RgbPsbtError, ScriptResolver};

impl RgbPsbt for Psbt {
Expand All @@ -48,9 +49,11 @@ impl RgbPsbt for Psbt {
Ok(())
}

fn rgb_complete(&mut self) -> Result<(), Unmodifiable> {
fn rgb_complete(&mut self) -> Result<(), RgbPsbtUnfinalizable> {

Check warning on line 52 in psbt/src/bp.rs

View check run for this annotation

Codecov / codecov/patch

psbt/src/bp.rs#L52

Added line #L52 was not covered by tests
if self.outputs().all(|out| !out.is_opret_host()) && self.opret_hosts().count() == 0 {
let host = self.construct_output(ScriptPubkey::op_return(&[]), Sats::ZERO)?;
let host = self
.construct_output(ScriptPubkey::op_return(&[]), Sats::ZERO)
.map_err(|_| RgbPsbtUnfinalizable)?;

Check warning on line 56 in psbt/src/bp.rs

View check run for this annotation

Codecov / codecov/patch

psbt/src/bp.rs#L54-L56

Added lines #L54 - L56 were not covered by tests
host.set_opret_host().ok();
}
self.complete_construction();
Expand Down
10 changes: 8 additions & 2 deletions psbt/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@
// or implied. See the License for the specific language governing permissions and limitations under
// the License.

use bpstd::{ScriptPubkey, Unmodifiable, Vout};
use bp::{ScriptPubkey, Vout};
use rgb::popls::bp::PrefabBundle;
use rgb::{ContractId, Outpoint};

#[derive(Copy, Clone, Eq, PartialEq, Debug, Display, Error)]
#[display(
"in order to complete RGB processing the PSBT must have PSBT_GLOBAL_TX_MODIFIABLE flag set on"
)]
pub struct RgbPsbtUnfinalizable;

pub trait RgbPsbt {
// TODO: Add rgb_embed to embed operations for hardware signers
fn rgb_fill_csv(&mut self, bundle: &PrefabBundle) -> Result<(), RgbPsbtError>;

fn rgb_complete(&mut self) -> Result<(), Unmodifiable>;
fn rgb_complete(&mut self) -> Result<(), RgbPsbtUnfinalizable>;
}

/// Errors embedding RGB-related information.
Expand Down

0 comments on commit 97f780a

Please sign in to comment.