Skip to content

Commit

Permalink
wip on PSBT changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 17, 2023
1 parent db31a8e commit 7fd48dd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 68 deletions.
57 changes: 26 additions & 31 deletions Cargo.lock

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

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ serde = ["serde_crate", "serde_yaml", "bp-std/serde", "bp-wallet/serde",]
features = [ "all" ]

[patch.crates-io]
bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
commit_verify = { git = "https://github.com/LNP-BP/client_side_validation", branch = "v0.11" }
bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "doubleanchors" }
bp-dbc = { git = "https://github.com/BP-WG/bp-core", branch = "doubleanchors" }
bp-seals = { git = "https://github.com/BP-WG/bp-core", branch = "doubleanchors" }
bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "doubleanchors" }
bp-invoice = { git = "https://github.com/BP-WG/bp-std", branch = "v0.11" }
bp-std = { git = "https://github.com/BP-WG/bp-std", branch = "v0.11" }
descriptors = { git = "https://github.com/BP-WG/bp-std", branch = "v0.11" }
Expand All @@ -97,6 +101,7 @@ bp-derive = { git = "https://github.com/BP-WG/bp-std", branch = "v0.11" }
bp-wallet = { git = "https://github.com/BP-WG/bp-wallet", branch = "v0.11" }
bp-util = { git = "https://github.com/BP-WG/bp-wallet", branch = "v0.11" }
bp-esplora = { git = "https://github.com/BP-WG/bp-esplora-client", branch = "master" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "v0.11" }
aluvm = { git = "https://github.com/AluVM/rust-aluvm", branch = "v0.11" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "canary" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "v0.11" }
rgb-invoice = { git = "https://github.com/RGB-WG/rgb-std", branch = "v0.11" }
24 changes: 7 additions & 17 deletions psbt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod rgb;
use std::collections::HashMap;

use bpstd::secp256k1::serde::{Deserialize, Serialize};
use psbt::Psbt;
use rgbstd::{AnchoredBundle, ContractId, Outpoint, Transition};
use rgbstd::containers::{Batch, Fascia};
use rgbstd::{ContractId, Outpoint};

/// A batch of state transitions under different contracts which are associated
/// with some specific transfer and will be anchored within a single layer 1
/// transaction.
#[derive(Clone, PartialEq, Eq, Hash, Debug, Default)]
pub struct Batch {
pub transitions: Vec<Transition>,
}

/// Structure exported from a PSBT for merging into the stash. It contains a set
/// of finalized state transitions, packed into bundles, and anchored to a
/// single layer 1 transaction.
#[derive(Clone, PartialEq, Eq, Hash, Debug, Default)]
pub struct Fascia {
pub bundles: Vec<AnchoredBundle>,
}
pub use self::rgb::{
ProprietaryKeyRgb, RgbExt, RgbInExt, RgbOutExt, RgbPsbtError, PSBT_GLOBAL_RGB_TRANSITION,
PSBT_IN_RGB_CONSUMED_BY, PSBT_OUT_RGB_VELOCITY_HINT, PSBT_RGB_PREFIX,
};

pub enum EmbedError {}
pub enum ExtractError {}
Expand Down
24 changes: 10 additions & 14 deletions src/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::HashMap;
use std::convert::Infallible;
use std::iter;

use bp::seals::txout::CloseMethod;
use bp::{Sats, Vout};
use bpwallet::{Invoice, PsbtMeta, TxParams};
use bp::Sats;
use bpwallet::{PsbtMeta, TxParams};
use psbt::Psbt;
use rgbstd::containers::{Bindle, BuilderSeal, Transfer};
use rgbstd::interface::{BuilderError, ContractSuppl, FilterIncludeAll, TypedState, VelocityHint};
use rgbstd::interface::{BuilderError, FilterIncludeAll};
use rgbstd::invoice::{Beneficiary, InvoiceState, RgbInvoice};
use rgbstd::persistence::{ConsignerError, Inventory, InventoryError, Stash};
use rgbstd::{
AssignmentType, ContractId, GraphSeal, Operation, Opout, SealDefinition,
RGB_NATIVE_DERIVATION_INDEX, RGB_TAPRET_DERIVATION_INDEX,
};

use crate::Runtime;

Expand Down Expand Up @@ -78,7 +72,7 @@ pub enum PayError {
Consigner(ConsignerError<Infallible, Infallible>),
}

#[derive(Clone, Eq, PartialEq, Hash, Debug)]
#[derive(Clone, PartialEq, Debug)]
pub struct TransferParams {
pub tx: TxParams,
pub min_amount: Sats,
Expand Down Expand Up @@ -142,11 +136,13 @@ impl Runtime {
}
_ => return Err(PayError::Unsupported),
};
let inv = match invoice.beneficiary {
Beneficiary::BlindedSeal(_) => Invoice::with_max(self.wallet().next_address()),
Beneficiary::WitnessVoutBitcoin(addr) => Invoice::new(addr, params.min_amount),
let beneficiary = match invoice.beneficiary {
Beneficiary::BlindedSeal(_) => Beneficiary::with_max(self.wallet().next_address()),
Beneficiary::WitnessVoutBitcoin(addr) => Beneficiary::new(addr, params.min_amount),
};
let (mut psbt, meta) = self.wallet().construct_psbt(&outputs, inv, params.tx)?;
let (mut psbt, meta) = self
.wallet()
.construct_psbt(&outputs, beneficiary, params.tx)?;

let batch =
self.compose(&invoice, outputs, method, meta.change_vout, |_, _, _| meta.change_vout)?;
Expand Down
7 changes: 3 additions & 4 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ use std::{fs, io};
use bpstd::{AddressNetwork, Network, XpubDerivable};
use bpwallet::Wallet;
use rgbfs::StockFs;
use rgbstd::containers::{Contract, LoadError, Transfer};
use rgbstd::containers::{Contract, LoadError, Transfer, XchainOutpoint};
use rgbstd::interface::{BuilderError, OutpointFilter};
use rgbstd::persistence::{Inventory, InventoryDataError, InventoryError, StashError, Stock};
use rgbstd::resolvers::ResolveHeight;
use rgbstd::validation::{self, ResolveTx};
use rgbstd::Output;
use strict_types::encoding::{DeserializeError, Ident, SerializeError};

use crate::{DescriptorRgb, RgbDescr};
Expand Down Expand Up @@ -118,10 +117,10 @@ impl<D: DescriptorRgb<K>, K> DerefMut for Runtime<D, K> {
}

impl<D: DescriptorRgb<K>, K> OutpointFilter for Runtime<D, K> {
fn include_output(&self, output: Output) -> bool {
fn include_output(&self, output: impl Into<XchainOutpoint>) -> bool {
self.wallet
.coins()
.any(|utxo| Output::Bitcoin(utxo.outpoint) == output)
.any(|utxo| XchainOutpoint::Bitcoin(utxo.outpoint) == output)
}
}

Expand Down

0 comments on commit 7fd48dd

Please sign in to comment.