Skip to content
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

Use new Pay2Vout standard library feature #202

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ bp-std = { git = "https://github.com/BP-WG/bp-std", branch = "master" }
bp-wallet = { git = "https://github.com/BP-WG/bp-wallet", branch = "master" }
psbt = { git = "https://github.com/BP-WG/bp-std", branch = "master" }
descriptors = { git = "https://github.com/BP-WG/bp-std", branch = "master" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "master" }
rgb-invoice = { git = "https://github.com/RGB-WG/rgb-std", branch = "master" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "invoice-pay2vout" }
rgb-invoice = { git = "https://github.com/RGB-WG/rgb-std", branch = "invoice-pay2vout" }
rgb-interfaces = { git = "https://github.com/RGB-WG/rgb-interfaces", branch = "master" }

# invoice-pay2vout
7 changes: 5 additions & 2 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use rgb::containers::{
Transfer, UniversalFile,
};
use rgb::interface::{AmountChange, FilterExclude, IfaceId};
use rgb::invoice::{Beneficiary, RgbInvoice, RgbInvoiceBuilder, XChainNet};
use rgb::invoice::{Beneficiary, Pay2Vout, RgbInvoice, RgbInvoiceBuilder, XChainNet};
use rgb::persistence::StashReadProvider;
use rgb::schema::SchemaId;
use rgb::validation::Validity;
Expand Down Expand Up @@ -689,7 +689,10 @@ impl Exec for RgbArgs {
.next()
.expect("no addresses left")
.addr;
Beneficiary::WitnessVout(addr.payload)
Beneficiary::WitnessVout(Pay2Vout {
address: addr.payload,
method: wallet.wallet().seal_close_method(),
})
}
(_, Some(outpoint)) => {
let seal = XChain::Bitcoin(GraphSeal::new_random(
Expand Down
23 changes: 12 additions & 11 deletions src/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ where Self::Descr: DescriptorRgb<K>
};
let beneficiaries = match invoice.beneficiary.into_inner() {
Beneficiary::BlindedSeal(_) => vec![],
Beneficiary::WitnessVout(payload) => {
Beneficiary::WitnessVout(pay2vout) => {
vec![BpBeneficiary::new(
Address::new(payload, invoice.address_network()),
Address::new(pay2vout.address, invoice.address_network()),
params.min_amount,
)]
}
Expand All @@ -220,8 +220,8 @@ where Self::Descr: DescriptorRgb<K>
self.construct_psbt(prev_outpoints, &beneficiaries, params.tx)?;

let beneficiary_script =
if let Beneficiary::WitnessVout(addr) = invoice.beneficiary.into_inner() {
Some(addr.script_pubkey())
if let Beneficiary::WitnessVout(pay2vout) = invoice.beneficiary.into_inner() {
Some(pay2vout.address.script_pubkey())
} else {
None
};
Expand All @@ -246,8 +246,8 @@ where Self::Descr: DescriptorRgb<K>
}

let beneficiary_vout = match invoice.beneficiary.into_inner() {
Beneficiary::WitnessVout(addr) => {
let s = addr.script_pubkey();
Beneficiary::WitnessVout(pay2vout) => {
let s = pay2vout.address.script_pubkey();
let vout = psbt
.outputs()
.find(|output| output.script == s)
Expand Down Expand Up @@ -297,16 +297,17 @@ where Self::Descr: DescriptorRgb<K>

let witness_txid = psbt.txid();
let (beneficiary1, beneficiary2) = match invoice.beneficiary.into_inner() {
Beneficiary::WitnessVout(addr) => {
let s = addr.script_pubkey();
Beneficiary::WitnessVout(pay2vout) => {
let s = pay2vout.address.script_pubkey();
let vout = psbt
.outputs()
.position(|output| output.script == s)
.ok_or(CompletionError::NoBeneficiaryOutput)?;
let vout = Vout::from_u32(vout as u32);
let method = self.descriptor().seal_close_method();
let seal =
XChain::Bitcoin(ExplicitSeal::new(method, Outpoint::new(witness_txid, vout)));
let seal = XChain::Bitcoin(ExplicitSeal::new(
pay2vout.method,
Outpoint::new(witness_txid, vout),
));
(vec![], vec![seal])
}
Beneficiary::BlindedSeal(seal) => (vec![XChain::Bitcoin(seal)], vec![]),
Expand Down
Loading