Skip to content

Commit

Permalink
Merge pull request #163 from RGB-WG/asset_tags
Browse files Browse the repository at this point in the history
Move asset tags to genesis
  • Loading branch information
dr-orlovsky authored Apr 11, 2024
2 parents ec0b4e4 + ad18a86 commit bb98f0e
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 112 deletions.
42 changes: 14 additions & 28 deletions Cargo.lock

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

15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,18 @@ serde = ["serde_crate", "serde_with", "serde_yaml", "bp-std/serde", "bp-wallet/s

[package.metadata.docs.rs]
features = ["all"]

[patch.crates-io]
strict_types = { git = "https://github.com/strict-types/strict-types", branch = "master" }
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-std = { git = "https://github.com/BP-WG/bp-std", 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" }
bp-wallet = { git = "https://github.com/BP-WG/bp-wallet", branch = "v0.11" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "asset_tags" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "asset_tags" }
rgb-invoice = { git = "https://github.com/RGB-WG/rgb-std", branch = "asset_tags" }
26 changes: 14 additions & 12 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use rgbstd::persistence::{Inventory, Stash};
use rgbstd::schema::SchemaId;
use rgbstd::validation::Validity;
use rgbstd::vm::RgbIsa;
use rgbstd::{AssetTag, AssignmentType, BundleId, OutputSeal, XChain, XOutputSeal};
use rgbstd::{BundleId, OutputSeal, XChain, XOutputSeal};
use seals::txout::CloseMethod;
use serde_crate::{Deserialize, Serialize};
use strict_types::encoding::{FieldName, TypeName};
Expand Down Expand Up @@ -784,7 +784,6 @@ impl Exec for RgbArgs {
pub struct ConsignmentInspection {
version: ContainerVer,
transfer: bool,
asset_tags: TinyOrdMap<AssignmentType, AssetTag>,
terminals: SmallOrdMap<BundleId, Terminal>,
supplements: TinyOrdSet<ContractSuppl>,
signatures: TinyOrdMap<ContentId, ContentSigs>,
Expand Down Expand Up @@ -838,7 +837,6 @@ impl Exec for RgbArgs {
let contract = ConsignmentInspection {
version: contract.version,
transfer: contract.transfer,
asset_tags: contract.asset_tags,
terminals: contract.terminals,
supplements: contract.supplements,
signatures: contract.signatures,
Expand Down Expand Up @@ -890,6 +888,7 @@ impl Exec for RgbArgs {
fs::create_dir_all(format!("{root_dir}/stash/ifaces"))?;
fs::create_dir_all(format!("{root_dir}/stash/geneses"))?;
fs::create_dir_all(format!("{root_dir}/stash/bundles"))?;
fs::create_dir_all(format!("{root_dir}/stash/witnesses"))?;
fs::create_dir_all(format!("{root_dir}/stash/anchors"))?;
fs::create_dir_all(format!("{root_dir}/stash/extensions"))?;
fs::create_dir_all(format!("{root_dir}/state"))?;
Expand Down Expand Up @@ -924,22 +923,21 @@ impl Exec for RgbArgs {
serde_yaml::to_string(suppl)?,
)?;
}
let tags = runtime.contract_asset_tags(id)?;
fs::write(
format!("{root_dir}/stash/geneses/{id}.tags.yaml"),
serde_yaml::to_string(tags)?,
)?;
}
for id in runtime.bundle_ids()? {
fs::write(
format!("{root_dir}/stash/bundles/{id}.yaml"),
serde_yaml::to_string(runtime.bundle(id)?)?,
)?;
fs::write(
format!("{root_dir}/stash/witnesses/{id}.yaml"),
serde_yaml::to_string(&runtime.bundled_witness(id)?.pub_witness)?,
)?;
}
for id in runtime.witness_ids()? {
fs::write(
format!("{root_dir}/stash/anchors/{id}.yaml"),
serde_yaml::to_string(runtime.anchor(id)?)?,
serde_yaml::to_string(&runtime.anchor(id)?)?,
)?;
}
for id in runtime.extension_ids()? {
Expand All @@ -961,11 +959,15 @@ impl Exec for RgbArgs {
// Index
fs::write(
format!("{root_dir}/index/op-to-bundle.yaml"),
serde_yaml::to_string(runtime.debug_bundle_op_index())?,
serde_yaml::to_string(runtime.debug_op_bundle_index())?,
)?;
fs::write(
format!("{root_dir}/index/bundle-to-contract.yaml"),
serde_yaml::to_string(runtime.debug_bundle_contract_index())?,
)?;
fs::write(
format!("{root_dir}/index/bundle-to-anchor.yaml"),
serde_yaml::to_string(runtime.debug_anchor_bundle_index())?,
format!("{root_dir}/index/bundle-to-witness.yaml"),
serde_yaml::to_string(runtime.debug_bundle_witness_index())?,
)?;
fs::write(
format!("{root_dir}/index/contracts.yaml"),
Expand Down
5 changes: 3 additions & 2 deletions psbt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use bp::dbc::tapret::TapretProof;
pub use psbt::*;

Check failure on line 29 in psbt/src/lib.rs

View workflow job for this annotation

GitHub Actions / testing

multiple candidates for `rlib` dependency `psbt` found
pub use rgb::*;
use rgbstd::containers::{Batch, Fascia};
use rgbstd::{AnchorSet, XAnchor, XChain};
use rgbstd::{AnchorSet, XChain, XWitnessId};

pub use self::rgb::{
ProprietaryKeyRgb, RgbExt, RgbInExt, RgbOutExt, RgbPsbtError, PSBT_GLOBAL_RGB_TRANSITION,
Expand Down Expand Up @@ -106,7 +106,8 @@ impl RgbPsbt for Psbt {
let anchor = AnchorSet::from_split(tapret_anchor, opret_anchor)
.expect("at least one of DBC are present due to CloseMethodSet type guarantees");
Ok(Fascia {
anchor: XAnchor::Bitcoin(anchor),
witness_id: XWitnessId::Bitcoin(self.txid()),
anchor,
bundles,
})
}
Expand Down
16 changes: 2 additions & 14 deletions src/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use std::collections::{BTreeMap, BTreeSet};
use std::convert::Infallible;

use amplify::confinement::Confined;
use bp::dbc::tapret::TapretProof;
use bp::seals::txout::{CloseMethod, ExplicitSeal};
use bp::{Outpoint, Sats, ScriptPubkey, Vout};
Expand All @@ -35,7 +34,7 @@ use rgbstd::invoice::{Amount, Beneficiary, InvoiceState, RgbInvoice};
use rgbstd::persistence::{
ComposeError, ConsignerError, Inventory, InventoryError, Stash, StashError,
};
use rgbstd::{WitnessId, XChain};
use rgbstd::XChain;

use crate::{
ContractOutpointsFilter, DescriptorRgb, RgbKeychain, Runtime, TapTweakAlreadyAssigned,
Expand Down Expand Up @@ -342,20 +341,9 @@ impl Runtime {
};

self.stock_mut().consume(fascia)?;
let mut transfer = self
let 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_unchecked() == WitnessId::Bitcoin(witness_txid) {
// TODO: Use unsigned tx
terminal.witness_tx = Some(XChain::Bitcoin(psbt.to_unsigned_tx().into()));
}
}
transfer.terminals = Confined::from_collection_unsafe(terminals);

Ok(transfer)
}
Expand Down
16 changes: 8 additions & 8 deletions src/resolvers/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use rgbstd::containers::Consignment;
use rgbstd::resolvers::ResolveHeight;
use rgbstd::validation::{ResolveWitness, WitnessResolverError};
use rgbstd::{WitnessAnchor, WitnessId, XAnchor, XPubWitness};
use rgbstd::{WitnessAnchor, XWitnessId, XWitnessTx};

#[cfg(feature = "electrum")]
use crate::electrum;
Expand Down Expand Up @@ -73,31 +73,31 @@ impl AnyResolver {
pub fn add_terminals<const TYPE: bool>(&mut self, consignment: &Consignment<TYPE>) {
match self {
#[cfg(feature = "electrum")]
AnyResolver::Electrum(inner) => inner.add_terminals(consignment),
AnyResolver::Electrum(inner) => inner.add_witnesses(consignment),
#[cfg(feature = "esplora_blocking")]
AnyResolver::Esplora(inner) => inner.add_terminals(consignment),
AnyResolver::Esplora(inner) => inner.add_witnesses(consignment),
}
}
}

impl ResolveHeight for AnyResolver {
type Error = AnyAnchorResolverError;

fn resolve_anchor(&mut self, anchor: &XAnchor) -> Result<WitnessAnchor, Self::Error> {
fn resolve_height(&mut self, witness_id: XWitnessId) -> Result<WitnessAnchor, Self::Error> {
match self {
#[cfg(feature = "electrum")]
AnyResolver::Electrum(inner) => inner.resolve_anchor(anchor).map_err(|e| e.into()),
AnyResolver::Electrum(inner) => inner.resolve_height(witness_id).map_err(|e| e.into()),
#[cfg(feature = "esplora_blocking")]
AnyResolver::Esplora(inner) => inner.resolve_anchor(anchor).map_err(|e| e.into()),
AnyResolver::Esplora(inner) => inner.resolve_height(witness_id).map_err(|e| e.into()),
}
}
}

impl ResolveWitness for AnyResolver {
fn resolve_pub_witness(
&self,
witness_id: WitnessId,
) -> Result<XPubWitness, WitnessResolverError> {
witness_id: XWitnessId,
) -> Result<XWitnessTx, WitnessResolverError> {
match self {
#[cfg(feature = "electrum")]
AnyResolver::Electrum(inner) => inner.resolve_pub_witness(witness_id),
Expand Down
Loading

0 comments on commit bb98f0e

Please sign in to comment.