diff --git a/Cargo.lock b/Cargo.lock index 3e50340..438a0fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -311,7 +311,8 @@ dependencies = [ [[package]] name = "bp-consensus" version = "0.11.0-beta.3" -source = "git+https://github.com/BP-WG/bp-core?branch=v0.11#50630d40828c522f78066c6ca473f0f3291b977d" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190ac89a2a3c79d5bfb677f48e5393691832c540973341831572edaffdce0881" dependencies = [ "amplify", "chrono", @@ -324,8 +325,9 @@ dependencies = [ [[package]] name = "bp-core" -version = "0.11.0-beta.2" -source = "git+https://github.com/BP-WG/bp-core?branch=v0.11#50630d40828c522f78066c6ca473f0f3291b977d" +version = "0.11.0-beta.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69269d27e32d784e37f7ca7cdf964fe5e30c5bff1ca2e229a118c84c8efdd179" dependencies = [ "amplify", "bp-consensus", @@ -340,8 +342,9 @@ dependencies = [ [[package]] name = "bp-dbc" -version = "0.11.0-beta.2" -source = "git+https://github.com/BP-WG/bp-core?branch=v0.11#50630d40828c522f78066c6ca473f0f3291b977d" +version = "0.11.0-beta.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cef9a98c7ae4f1bb333ad8e55c9d8a91f071c347d35b62e19959faa07572b11" dependencies = [ "amplify", "base85", @@ -355,7 +358,8 @@ dependencies = [ [[package]] name = "bp-derive" version = "0.11.0-beta.3" -source = "git+https://github.com/BP-WG/bp-std?branch=v0.11#b0665890eec9507ad315da94fd8866855d0cf313" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497e2b7324e0c7a65bdaabccd0fc7d05b003cca4ae3f3a1520e023aab3a9a24f" dependencies = [ "amplify", "bitcoin_hashes", @@ -385,7 +389,8 @@ dependencies = [ [[package]] name = "bp-invoice" version = "0.11.0-beta.3" -source = "git+https://github.com/BP-WG/bp-std?branch=v0.11#b0665890eec9507ad315da94fd8866855d0cf313" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a40b7fb87b58b2371b7b3b010568baa9ba463007707f9af9bb9b77a63d77e8f" dependencies = [ "amplify", "bech32", @@ -396,8 +401,9 @@ dependencies = [ [[package]] name = "bp-seals" -version = "0.11.0-beta.2" -source = "git+https://github.com/BP-WG/bp-core?branch=v0.11#50630d40828c522f78066c6ca473f0f3291b977d" +version = "0.11.0-beta.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d211bb77e320abf4bba6c272fc85d73e5203140ca39e299271f4714d8b6029fe" dependencies = [ "amplify", "baid58", @@ -413,7 +419,8 @@ dependencies = [ [[package]] name = "bp-std" version = "0.11.0-beta.3" -source = "git+https://github.com/BP-WG/bp-std?branch=v0.11#b0665890eec9507ad315da94fd8866855d0cf313" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d6847d1e7359ed49947092fd319433c82b9cced1a2d780a9415d212770cf93c" dependencies = [ "amplify", "bp-consensus", @@ -426,8 +433,9 @@ dependencies = [ [[package]] name = "bp-util" -version = "0.11.0-beta.3" -source = "git+https://github.com/BP-WG/bp-wallet?branch=v0.11#967d9cc439ba33710d5f8e2794d7a1b698c1c997" +version = "0.11.0-beta.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32a1745e168059aee08e54417a89d8430de5470a492b226fbe19eb7a3b4a2ee" dependencies = [ "amplify", "base64", @@ -448,8 +456,9 @@ dependencies = [ [[package]] name = "bp-wallet" -version = "0.11.0-beta.3" -source = "git+https://github.com/BP-WG/bp-wallet?branch=v0.11#967d9cc439ba33710d5f8e2794d7a1b698c1c997" +version = "0.11.0-beta.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a0baa9e09b52085f7d1cd27df92395e06a8016a8ccb8cdc68556ba2b5ac831" dependencies = [ "amplify", "bp-esplora", @@ -524,9 +533,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.11" +version = "4.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2" +checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d" dependencies = [ "clap_builder", "clap_derive", @@ -534,9 +543,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.11" +version = "4.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb" +checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" dependencies = [ "anstream", "anstyle", @@ -583,9 +592,9 @@ dependencies = [ [[package]] name = "commit_verify" -version = "0.11.0-beta.2" +version = "0.11.0-beta.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5598661b1d90b149f0b944faef8c1d1d131f847678a6c450b9540b629ac11291" +checksum = "85e001679b9be6a5df24facdae179e6ba1cffb503c875d691eac024db8d0f8d1" dependencies = [ "amplify", "commit_encoding_derive", @@ -711,7 +720,8 @@ dependencies = [ [[package]] name = "descriptors" version = "0.11.0-beta.3" -source = "git+https://github.com/BP-WG/bp-std?branch=v0.11#b0665890eec9507ad315da94fd8866855d0cf313" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58cfb07301f4982a5470167155c186586871d21693a791078cfa15c173657626" dependencies = [ "amplify", "bp-derive", @@ -1127,13 +1137,13 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "is-terminal" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" dependencies = [ "hermit-abi", "rustix", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1188,9 +1198,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "mime" @@ -1373,8 +1383,9 @@ dependencies = [ [[package]] name = "psbt" -version = "0.11.0-beta.3" -source = "git+https://github.com/BP-WG/bp-std?branch=v0.11#b0665890eec9507ad315da94fd8866855d0cf313" +version = "0.11.0-beta.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d1f67ff8093b5ca985100452af2dd181aa5b29bc635792f4101750250674fc1" dependencies = [ "amplify", "base64", @@ -1517,8 +1528,9 @@ dependencies = [ [[package]] name = "rgb-core" -version = "0.11.0-beta.3" -source = "git+https://github.com/RGB-WG/rgb-core?branch=v0.11#67fefef855cecc2eb5aa1f5145267b672de71f3c" +version = "0.11.0-beta.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb0581f9bc33b509400aa9225d2308dfd45af413a4fe38f7c4b823a7e09e6036" dependencies = [ "aluvm", "amplify", @@ -1537,8 +1549,9 @@ dependencies = [ [[package]] name = "rgb-invoice" -version = "0.11.0-beta.3" -source = "git+https://github.com/RGB-WG/rgb-std?branch=v0.11#ab6aacef5ce1a3f3c04525abc9c7807f7a493bee" +version = "0.11.0-beta.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4898f1ca45d70ed18f3f1977ef35ffe8ee35870c982ad9fb842a6fbaeb512490" dependencies = [ "amplify", "baid58", @@ -1606,8 +1619,9 @@ dependencies = [ [[package]] name = "rgb-std" -version = "0.11.0-beta.3" -source = "git+https://github.com/RGB-WG/rgb-std?branch=v0.11#ab6aacef5ce1a3f3c04525abc9c7807f7a493bee" +version = "0.11.0-beta.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bc24f24f2e942d1c20f46a68b331d7864fbdf94ab334c6fac20840816d30a54" dependencies = [ "amplify", "baid58", @@ -1617,6 +1631,7 @@ dependencies = [ "commit_verify", "getrandom", "indexmap 2.1.0", + "rand", "rgb-core", "rgb-invoice", "serde", @@ -1957,9 +1972,9 @@ dependencies = [ [[package]] name = "single_use_seals" -version = "0.11.0-beta.2" +version = "0.11.0-beta.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c30647a1342641c45ca7c1dcd5ae7db16533b86744e827c84cfed875db2de3fe" +checksum = "1b14ebe6be1e12070208a6f2ceb49f946d835b1f7dfb809a4db025de8f5ffe0a" dependencies = [ "amplify_derive", ] @@ -2002,9 +2017,9 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "strict_encoding" -version = "2.6.1" +version = "2.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab7b75b4af0aff9dd97b68df262bf0e807b7d007cc860fa217943f898a05a5ab" +checksum = "fa76decc8ac190a56ba7857c023b69ed52b781ed974c5a181eac62cdbfc99521" dependencies = [ "amplify", "half", diff --git a/Cargo.toml b/Cargo.toml index ab5d49b..a87b18f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,17 +26,17 @@ license = "Apache-2.0" [workspace.dependencies] amplify = "4.5.0" baid58 = "0.4.4" -commit_verify = "0.11.0-beta.2" -strict_encoding = "2.6.1" +commit_verify = "0.11.0-beta.3" +strict_encoding = "2.6.2" strict_types = "1.6.3" -bp-core = "0.11.0-beta.2" -bp-seals = "0.11.0-beta.2" +bp-core = "0.11.0-beta.3" +bp-seals = "0.11.0-beta.3" bp-std = "0.11.0-beta.3" -bp-wallet = "0.11.0-beta.3" -bp-util = "0.11.0-beta.3" +bp-wallet = "0.11.0-beta.4" +bp-util = "0.11.0-beta.4" bp-esplora = "0.11.0-beta.2" -descriptors = "0.11.0-beta.2" -psbt = { version = "0.11.0-beta.2", features = ["client-side-validation"] } +descriptors = "0.11.0-beta.3" +psbt = { version = "0.11.0-beta.3", features = ["client-side-validation"] } rgb-std = { version = "0.11.0-beta.3", features = ["fs"] } rgb-psbt = { version = "0.11.0-beta.2", path = "psbt" } indexmap = "2.0.2" @@ -91,19 +91,3 @@ serde = ["serde_crate", "serde_with", "serde_yaml", "bp-std/serde", "bp-wallet/s [package.metadata.docs.rs] features = [ "all" ] - -[patch.crates-io] -bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" } -bp-dbc = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" } -bp-seals = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" } -bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" } -bp-invoice = { git = "https://github.com/BP-WG/bp-std", branch = "v0.11" } -bp-derive = { git = "https://github.com/BP-WG/bp-std", branch = "v0.11" } -bp-std = { 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" } -psbt = { git = "https://github.com/BP-WG/bp-std", branch = "v0.11" } -descriptors = { git = "https://github.com/BP-WG/bp-std", branch = "v0.11" } -rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "v0.11" } -rgb-invoice = { git = "https://github.com/RGB-WG/rgb-std", branch = "v0.11" } -rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "v0.11" } diff --git a/cli/src/command.rs b/cli/src/command.rs index a97868c..6a84f9e 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -25,19 +25,19 @@ use std::path::PathBuf; use std::str::FromStr; use amplify::confinement::U16; -use bp_util::{Config, Exec}; -use bpstd::{Sats, Txid}; +use bp_util::{BpCommand, Config, Exec}; +use bpstd::Sats; use psbt::{Psbt, PsbtVer}; use rgb_rt::{DescriptorRgb, RgbKeychain, RuntimeError, TransferParams}; -use rgbstd::containers::{Bindle, Transfer, UniversalBindle}; +use rgbstd::containers::{Bindle, BuilderSeal, Transfer, UniversalBindle}; use rgbstd::contract::{ContractId, GenesisSeal, GraphSeal, StateType}; use rgbstd::interface::{ContractBuilder, FilterExclude, IfaceId, SchemaIfaces}; -use rgbstd::invoice::{Beneficiary, InvoiceState, RgbInvoice, RgbTransport}; +use rgbstd::invoice::{Beneficiary, RgbInvoice, RgbInvoiceBuilder, XChainNet}; use rgbstd::persistence::{Inventory, Stash}; use rgbstd::schema::SchemaId; use rgbstd::validation::Validity; -use rgbstd::XSeal; -use seals::txout::{CloseMethod, ExplicitSeal}; +use rgbstd::{OutputSeal, XChain}; +use seals::txout::CloseMethod; use strict_types::encoding::{FieldName, TypeName}; use strict_types::StrictVal; @@ -286,7 +286,7 @@ impl Exec for RgbArgs { const CONF_FILE_NAME: &'static str = "rgb.toml"; fn exec(self, config: Config, _name: &'static str) -> Result<(), RuntimeError> { - match &self.command { + if let Some(mut runtime) = match &self.command { Command::General(cmd) => { self.inner.translate(cmd).exec(config, "rgb")?; None @@ -327,7 +327,7 @@ impl Exec for RgbArgs { Command::Utxos => { self.inner - .translate(&bp_util::BpCommand::Balance { + .translate(&BpCommand::Balance { addr: true, utxo: true, }) @@ -335,7 +335,7 @@ impl Exec for RgbArgs { None } - Command::History { contract_id } => { + Command::History { contract_id: _ } => { todo!(); } @@ -579,9 +579,8 @@ impl Exec for RgbArgs { .expect("assignment doesn't provide seal information") .as_str() .expect("seal must be a string"); - let seal = - ExplicitSeal::::from_str(seal).expect("invalid seal definition"); - let seal = XSeal::Bitcoin(GenesisSeal::from(seal)); + let seal = OutputSeal::from_str(seal).expect("invalid seal definition"); + let seal = GenesisSeal::new_random(seal.method, seal.txid, seal.vout); // Workaround for borrow checker: let field_name = @@ -594,6 +593,7 @@ impl Exec for RgbArgs { .expect("owned state must be a fungible amount") .as_u64() .expect("fungible state must be an integer"); + let seal = BuilderSeal::Revealed(XChain::Bitcoin(seal)); builder = builder .add_fungible_state(field_name, seal, amount) .expect("invalid global state data"); @@ -640,6 +640,7 @@ impl Exec for RgbArgs { RgbKeychain::contains_rgb(utxo.terminal.keychain) }) .next(); + let network = runtime.wallet().network(); let beneficiary = match (address_based, outpoint) { (true, _) | (false, None) => { let addr = runtime @@ -648,30 +649,23 @@ impl Exec for RgbArgs { .next() .expect("no addresses left") .addr; - Beneficiary::WitnessVoutBitcoin(addr) + Beneficiary::WitnessVout(addr.payload) } (_, Some(outpoint)) => { - let seal = GraphSeal::new( + let seal = XChain::Bitcoin(GraphSeal::new_random( runtime.wallet().seal_close_method(), outpoint.txid, outpoint.vout, - ); - runtime.store_seal_secret(XSeal::Bitcoin(seal))?; - Beneficiary::BlindedSeal(seal.to_concealed_seal()) + )); + runtime.store_seal_secret(seal)?; + Beneficiary::BlindedSeal(*seal.to_secret_seal().as_reduced_unsafe()) } }; - let invoice = RgbInvoice { - transports: vec![RgbTransport::UnspecifiedMeans], - contract: Some(*contract_id), - iface: Some(iface), - operation: None, - assignment: None, - beneficiary, - owned_state: InvoiceState::Amount(*value), - network: None, - expiry: None, - unknown_query: none!(), - }; + let invoice = RgbInvoiceBuilder::new(XChainNet::bitcoin(network, beneficiary)) + .set_contract(*contract_id) + .set_interface(iface) + .set_amount_raw(*value) + .finish(); println!("{invoice}"); Some(runtime) } @@ -905,8 +899,9 @@ impl Exec for RgbArgs { eprintln!("Transfer accepted into the stash"); Some(runtime) } + } { + runtime.store() } - .map(|mut runtime| runtime.store()); println!(); diff --git a/examples/rgb20-demo.yaml b/examples/rgb20-demo.yaml index b3dfa74..89c828a 100644 --- a/examples/rgb20-demo.yaml +++ b/examples/rgb20-demo.yaml @@ -28,5 +28,5 @@ globals: assignments: assetOwner: - seal: tapret1st:0713113471eb25ee121167c22ee4f22f5190b50fbcaaa5de576d75a8e3ed8bb1:1 + seal: tapret1st:fb9ae7ae4b70a27e7fdfdefac91b37967b549d65007dbf25470b0817a2ae810a:1 amount: 100000000 # this is 1 million (we have two digits for cents) diff --git a/psbt/src/lib.rs b/psbt/src/lib.rs index 6643f72..86e97f2 100644 --- a/psbt/src/lib.rs +++ b/psbt/src/lib.rs @@ -27,8 +27,8 @@ mod rgb; use bp::dbc::opret::OpretProof; use bp::dbc::tapret::TapretProof; pub use psbt::*; -use rgbstd::containers::{Batch, Fascia, XchainOutpoint}; -use rgbstd::{AnchorSet, XAnchor}; +use rgbstd::containers::{Batch, Fascia}; +use rgbstd::{AnchorSet, XAnchor, XChain}; pub use self::rgb::{ ProprietaryKeyRgb, RgbExt, RgbInExt, RgbOutExt, RgbPsbtError, PSBT_GLOBAL_RGB_TRANSITION, @@ -77,10 +77,7 @@ impl RgbPsbt for Psbt { let mut inputs = info.inputs.into_inner(); for input in self.inputs_mut() { let outpoint = input.prevout().outpoint(); - if let Some(pos) = inputs - .iter() - .position(|i| i == &XchainOutpoint::Bitcoin(outpoint)) - { + if let Some(pos) = inputs.iter().position(|i| i == &XChain::Bitcoin(outpoint)) { inputs.remove(pos); input .set_rgb_consumer(contract_id, info.id) diff --git a/src/pay.rs b/src/pay.rs index cf70c98..ee61fbd 100644 --- a/src/pay.rs +++ b/src/pay.rs @@ -25,15 +25,16 @@ use amplify::confinement::Confined; use bp::dbc::tapret::TapretProof; use bp::seals::txout::{CloseMethod, ExplicitSeal}; use bp::{Outpoint, Sats, ScriptPubkey, Vout}; +use bpstd::Address; use bpwallet::{Beneficiary as BpBeneficiary, ConstructionError, PsbtMeta, TxParams}; use psbt::{CommitError, EmbedError, Psbt, RgbPsbt, TapretKeyError}; -use rgbstd::containers::{Bindle, BuilderSeal, Transfer}; +use rgbstd::containers::{Bindle, Transfer}; use rgbstd::interface::ContractError; use rgbstd::invoice::{Beneficiary, InvoiceState, RgbInvoice}; use rgbstd::persistence::{ ComposeError, ConsignerError, Inventory, InventoryError, Stash, StashError, }; -use rgbstd::{WitnessId, XSeal}; +use rgbstd::{WitnessId, XChain}; use crate::{ ContractOutpointsFilter, DescriptorRgb, RgbKeychain, Runtime, TapTweakAlreadyAssigned, @@ -224,27 +225,30 @@ impl Runtime { } _ => return Err(CompositionError::Unsupported), }; - let beneficiaries = match invoice.beneficiary { + let beneficiaries = match invoice.beneficiary.into_inner() { Beneficiary::BlindedSeal(_) => vec![], - Beneficiary::WitnessVoutBitcoin(addr) => { - vec![BpBeneficiary::new(addr, params.min_amount)] + Beneficiary::WitnessVout(payload) => { + vec![BpBeneficiary::new( + Address::new(payload, invoice.address_network()), + params.min_amount, + )] } }; let outpoints = outputs .iter() - .filter_map(|o| o.reduce_to_bp()) + .map(|o| o.as_reduced_unsafe()) .map(|o| Outpoint::new(o.txid, o.vout)); params.tx.change_keychain = RgbKeychain::for_method(method).into(); let (mut psbt, mut meta) = self.wallet_mut() .construct_psbt(outpoints, &beneficiaries, params.tx)?; - let beneficiary_script = if let Beneficiary::WitnessVoutBitcoin(addr) = invoice.beneficiary - { - Some(addr.script_pubkey()) - } else { - None - }; + let beneficiary_script = + if let Beneficiary::WitnessVout(addr) = invoice.beneficiary.into_inner() { + Some(addr.script_pubkey()) + } else { + None + }; let output = psbt .outputs_mut() .find(|o| o.script.is_p2tr() && Some(&o.script) != beneficiary_script.as_ref()) @@ -267,8 +271,8 @@ impl Runtime { } } - let beneficiary_vout = match invoice.beneficiary { - Beneficiary::WitnessVoutBitcoin(addr) => { + let beneficiary_vout = match invoice.beneficiary.into_inner() { + Beneficiary::WitnessVout(addr) => { let s = addr.script_pubkey(); let vout = psbt .outputs() @@ -313,8 +317,8 @@ impl Runtime { } let witness_txid = psbt.txid(); - let beneficiary = match invoice.beneficiary { - Beneficiary::WitnessVoutBitcoin(addr) => { + let (beneficiary1, beneficiary2) = match invoice.beneficiary.into_inner() { + Beneficiary::WitnessVout(addr) => { let s = addr.script_pubkey(); let vout = psbt .outputs() @@ -323,22 +327,27 @@ impl Runtime { let vout = Vout::from_u32(vout as u32); let method = self.wallet().seal_close_method(); let seal = - XSeal::Bitcoin(ExplicitSeal::new(method, Outpoint::new(witness_txid, vout))); - BuilderSeal::Revealed(seal) + XChain::Bitcoin(ExplicitSeal::new(method, Outpoint::new(witness_txid, vout))); + (vec![], vec![seal]) } - Beneficiary::BlindedSeal(seal) => BuilderSeal::Concealed(seal), + Beneficiary::BlindedSeal(seal) => (vec![XChain::Bitcoin(seal)], vec![]), }; self.stock_mut().consume(fascia)?; - let mut transfer = self.stock().transfer(contract_id, [beneficiary])?; + let mut transfer = self + .stock() + .transfer(contract_id, beneficiary2, beneficiary1)?; let mut terminals = transfer.terminals.to_inner(); for (bundle_id, terminal) in terminals.iter_mut() { let Some(ab) = transfer.anchored_bundle(*bundle_id) else { continue; }; - if ab.anchor.witness_id() == WitnessId::Bitcoin(witness_txid) { + if ab.anchor.witness_id_unchecked() == WitnessId::Bitcoin(witness_txid) { // TODO: Use unsigned tx - terminal.tx = Some(psbt.to_unsigned_tx().into()) + match terminal { + XChain::Bitcoin(term) => term.tx = Some(psbt.to_unsigned_tx().into()), + XChain::Liquid(_) => unreachable!(), + } } } transfer.terminals = Confined::from_collection_unsafe(terminals); diff --git a/src/resolver.rs b/src/resolver.rs index 16dcf4b..4a4d4fe 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -25,8 +25,8 @@ use bpstd::{Tx, Txid}; pub use esplora::Error as ResolverError; use rgbstd::containers::Consignment; use rgbstd::resolvers::ResolveHeight; -use rgbstd::validation::{ResolveTx, TxResolverError}; -use rgbstd::{Layer1, WitnessAnchor, WitnessId, WitnessOrd, WitnessPos, XAnchor}; +use rgbstd::validation::{ResolveWitness, WitnessResolverError}; +use rgbstd::{WitnessAnchor, WitnessId, WitnessOrd, WitnessPos, XAnchor, XChain, XPubWitness}; pub struct Resolver { esplora_client: esplora::BlockingClient, @@ -60,7 +60,7 @@ impl Resolver { consignment .terminals .values() - .filter_map(|t| t.tx.as_ref()) + .filter_map(|t| t.as_reduced_unsafe().tx.as_ref()) .map(|tx| (tx.txid(), tx.clone())), ); } @@ -101,17 +101,23 @@ impl ResolveHeight for Resolver { } } -impl ResolveTx for Resolver { - fn resolve_bp_tx(&self, layer1: Layer1, txid: Txid) -> Result { - assert_eq!(layer1, Layer1::Bitcoin, "Liquid is not yet supported"); +impl ResolveWitness for Resolver { + fn resolve_pub_witness( + &self, + witness_id: WitnessId, + ) -> Result { + let WitnessId::Bitcoin(txid) = witness_id else { + panic!("Liquid is not yet supported"); + }; if let Some(tx) = self.terminal_txes.get(&txid) { - return Ok(tx.clone()); + return Ok(XPubWitness::Bitcoin(tx.clone())); } self.esplora_client .tx(&txid) - .map_err(|err| TxResolverError::Other(txid, err.to_string()))? - .ok_or(TxResolverError::Unknown(txid)) + .map_err(|err| WitnessResolverError::Other(witness_id, err.to_string()))? + .ok_or(WitnessResolverError::Unknown(witness_id)) + .map(XChain::Bitcoin) } } diff --git a/src/runtime.rs b/src/runtime.rs index 76213cb..29377ea 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -31,12 +31,12 @@ use amplify::IoError; use bpstd::{Network, XpubDerivable}; use bpwallet::Wallet; use rgbfs::StockFs; -use rgbstd::containers::{Contract, LoadError, Transfer, XchainOutpoint}; +use rgbstd::containers::{Contract, LoadError, Transfer}; use rgbstd::interface::{BuilderError, OutpointFilter}; use rgbstd::persistence::{Inventory, InventoryDataError, InventoryError, StashError, Stock}; use rgbstd::resolvers::ResolveHeight; -use rgbstd::validation::{self, ResolveTx}; -use rgbstd::ContractId; +use rgbstd::validation::{self, ResolveWitness}; +use rgbstd::{ContractId, XChain, XOutpoint}; use strict_types::encoding::{DecodeError, DeserializeError, Ident, SerializeError}; use crate::{DescriptorRgb, RgbDescr}; @@ -126,11 +126,11 @@ impl, K> DerefMut for Runtime { } impl, K> OutpointFilter for Runtime { - fn include_output(&self, output: impl Into) -> bool { + fn include_output(&self, output: impl Into) -> bool { let output = output.into(); self.wallet() .coins() - .any(|utxo| XchainOutpoint::Bitcoin(utxo.outpoint) == output) + .any(|utxo| XChain::Bitcoin(utxo.outpoint) == output) } } @@ -140,12 +140,12 @@ pub struct ContractOutpointsFilter<'runtime, D: DescriptorRgb, K> { } impl<'runtime, D: DescriptorRgb, K> OutpointFilter for ContractOutpointsFilter<'runtime, D, K> { - fn include_output(&self, output: impl Into) -> bool { + fn include_output(&self, output: impl Into) -> bool { let output = output.into(); if !self.filter.include_output(output) { return false; } - matches!(self.filter.stock.state_for_outputs(self.contract_id, [output]), Ok(list) if !list.is_empty()) + matches!(self.filter.stock.state_for_outpoints(self.contract_id, [output]), Ok(list) if !list.is_empty()) } } @@ -213,7 +213,7 @@ impl, K> Runtime { pub fn validate_transfer( &mut self, transfer: Transfer, - resolver: &mut impl ResolveTx, + resolver: &mut impl ResolveWitness, ) -> Result { transfer .validate(resolver, self.network().is_testnet())