Skip to content

Commit

Permalink
Merge pull request #15 from nicbus/psbt_bundle_update
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky authored Jan 18, 2023
2 parents a6c39b5 + 0c3f9af commit a697618
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions 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 @@ -23,6 +23,7 @@ required-features = ["cli", "serde"]

[dependencies]
amplify = "3.13.0"
bitcoin_scripts = "0.9.0-rc.1"
lnpbp_bech32 = "~0.9.0-rc.1"
strict_encoding = { version = "~0.9.0-rc.2", features = ["crypto", "chrono", "bitcoin"] }
commit_verify = "~0.9.0-rc.1"
Expand Down
37 changes: 35 additions & 2 deletions src/bin/rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::str::FromStr;
use amplify::hex::{FromHex, ToHex};
use bitcoin::psbt::serialize::{Deserialize, Serialize};
use bitcoin::OutPoint;
use bitcoin_scripts::taproot::{DfsOrder, DfsPath};
use bp::seals::txout::CloseMethod;
use clap::Parser;
use commit_verify::ConsensusCommit;
Expand Down Expand Up @@ -193,6 +194,10 @@ pub enum PsbtCommand {
/// Output file to save the PSBT updated with state transition(s)
/// information. If not given, the source PSBT file is overwritten.
psbt_out: Option<PathBuf>,

/// Method for seal closing ('tapret1st' or 'opret1st')
#[clap(short, long, default_value = "tapret1st")]
method: CloseMethod,
},

/// Analyze PSBT file and print out all RGB-related information from it
Expand Down Expand Up @@ -382,11 +387,39 @@ fn main() -> Result<(), Error> {
}
},
Command::Psbt { subcommand } => match subcommand {
PsbtCommand::Bundle { psbt_in, psbt_out } => {
PsbtCommand::Bundle {
psbt_in,
psbt_out,
method,
} => {
let psbt_bytes = fs::read(&psbt_in)?;
let mut psbt = Psbt::deserialize(&psbt_bytes)?;

let count = psbt.rgb_bundle_to_lnpbp4()?;
let mut count: usize = 0;
match method {
CloseMethod::TapretFirst => {
if let Some(output) =
psbt.outputs.iter_mut().find(|o| o.script.is_v1_p2tr())
{
if output.tapret_dfs_path().is_none() {
output.set_tapret_dfs_path(&DfsPath::with([&DfsOrder::Last]))?;
}
}
count = psbt.rgb_bundle_to_lnpbp4()?;
}
CloseMethod::OpretFirst => {
count = psbt.rgb_bundle_to_lnpbp4()?;
if let Some(output) =
psbt.outputs.iter_mut().find(|o| o.script.is_op_return())
{
if !output.is_opret_host() {
output.set_opret_host()?;
}
}
}
_ => {}
};

println!("Total {} bundles converted", count);

let psbt_bytes = psbt.serialize();
Expand Down

0 comments on commit a697618

Please sign in to comment.