Skip to content

Commit

Permalink
Merge pull request #276 from zoedberg/v0.11_fixes
Browse files Browse the repository at this point in the history
Experiments on v0.11
  • Loading branch information
dr-orlovsky authored Feb 19, 2025
2 parents 4339095 + 6bc86a4 commit 85c23d7
Show file tree
Hide file tree
Showing 18 changed files with 382 additions and 532 deletions.
305 changes: 100 additions & 205 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ baid64 = "0.2.2"
strict_encoding = "2.7.0"
strict_types = "2.7.2"
commit_verify = "0.11.0-beta.9"
bp-core = "0.11.0-beta.9"
bp-std = { version = "0.11.0-beta.9", features = ["client-side-validation"] }
bp-electrum = "0.11.0-beta.9"
bp-esplora = { version = "0.11.0-beta.9", default-features = false }
bp-wallet = { version = "0.11.0-beta.9" }
rgb-std = { version = "0.11.0-beta.9" }
bp-core = "0.11.1-alpha.1"
bp-std = { version = "0.11.1-alpha.1", features = ["client-side-validation"] }
bp-electrum = "0.11.1-alpha.1"
bp-esplora = { version = "0.11.1-alpha.1", default-features = false }
bp-wallet = { version = "0.11.1-alpha.1" }
rgb-std = { version = "0.11.1-alpha.1" }
rgb-psbt = { version = "0.11.0-beta.9", path = "psbt" }
indexmap = "2.4.0"
chrono = "0.4.38"
Expand Down Expand Up @@ -90,7 +90,7 @@ default = []
all = ["esplora_blocking", "electrum_blocking", "mempool_blocking", "serde", "log", "fs", "cli"]
fs = ["serde", "bp-wallet/fs", "rgb-std/fs"]
cli = ["fs", "bp-wallet/cli"]
esplora_blocking = ["bp-esplora", "bp-esplora/blocking"]
esplora_blocking = ["bp-esplora", "bp-esplora/blocking", "bp-esplora/blocking-https"]
esplora_blocking-wasm = ["bp-esplora", "bp-esplora/blocking-wasm"]
electrum_blocking = ["bp-electrum"]
mempool_blocking = ["esplora_blocking"]
Expand Down
10 changes: 5 additions & 5 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ from source
```
$ git clone <https://github.com/RGB-WG/rgb>
$ cd rgb/cli
$ cargo install --path --all-features .
$ cargo install --all-features --path .
```

## Data Directory
Expand Down Expand Up @@ -274,14 +274,14 @@ globals:

assignments:
assetOwner:
seal: tapret1st:fb9ae7ae4b70a27e7fdfdefac91b37967b549d65007dbf25470b0817a2ae810a:1
seal: fb9ae7ae4b70a27e7fdfdefac91b37967b549d65007dbf25470b0817a2ae810a:1
amount: 100000000 # this is 1 million (we have two digits for cents)

```

Here, we observe a seal value in the form of `closing_method:txid:vout` and here closing method is `tapret1st` (can also
be `opret1st`). This hash, in reality, represents the txid of the previously created PSBT. And `txid:vout` is the
outpoint of a valid UTXO.
Here, we observe a seal value in the form of `txid:vout`. This hash, in
reality, represents the txid of the previously created PSBT. And `txid:vout` is
the outpoint of a valid UTXO.

Compile the contract:

Expand Down
18 changes: 14 additions & 4 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ use std::io::ErrorKind;
use std::ops::{Deref, DerefMut};
use std::path::PathBuf;

use bpstd::{Wpkh, XpubDerivable};
use bpstd::{Network, Wpkh, XpubDerivable};
use bpwallet::cli::{Args as BpArgs, Config, DescriptorOpts};
use bpwallet::Wallet;
use rgb::persistence::Stock;
use rgb::resolvers::AnyResolver;
use rgb::{RgbDescr, RgbWallet, TapretKey, WalletError};
use rgb::{ChainNet, RgbDescr, RgbWallet, TapretKey, WalletError};
use rgbstd::persistence::fs::FsBinStore;
use strict_types::encoding::{DecodeError, DeserializeError};

Expand Down Expand Up @@ -131,7 +131,7 @@ impl RgbArgs {
let resolver = self.resolver()?;
let from_height = self.from_height.unwrap_or(1);
eprint!("Updating witness information starting from height {from_height} ... ");
let res = stock.update_witnesses(resolver, from_height)?;
let res = stock.update_witnesses(resolver, from_height, vec![])?;
eprint!("{} transactions were checked and updated", res.succeeded);
if res.failed.is_empty() {
eprintln!();
Expand Down Expand Up @@ -189,7 +189,17 @@ impl RgbArgs {
--esplora --mempool or --electrum argument")),
}
.map_err(WalletError::Resolver)?;
resolver.check(self.general.network)?;
resolver.check_chain_net(self.chain_net())?;
Ok(resolver)
}

pub fn chain_net(&self) -> ChainNet {
match self.general.network {
Network::Mainnet => ChainNet::BitcoinMainnet,
Network::Regtest => ChainNet::BitcoinRegtest,
Network::Signet => ChainNet::BitcoinSignet,
Network::Testnet3 => ChainNet::BitcoinTestnet3,
Network::Testnet4 => ChainNet::BitcoinTestnet4,
}
}
}
72 changes: 33 additions & 39 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use amplify::confinement::{SmallOrdMap, TinyOrdMap, TinyOrdSet, U16 as MAX16};
use baid64::DisplayBaid64;
use bpstd::psbt::{Psbt, PsbtVer};
use bpstd::seals::SecretSeal;
use bpstd::{Sats, XpubDerivable};
use bpstd::{Sats, Txid, XpubDerivable};
use bpwallet::cli::{BpCommand, Config, Exec};
use bpwallet::Wallet;
use rgb::containers::{
Expand All @@ -44,9 +44,9 @@ use rgb::schema::SchemaId;
use rgb::validation::Validity;
use rgb::vm::{RgbIsa, WitnessOrd};
use rgb::{
Allocation, BundleId, ContractId, DescriptorRgb, GenesisSeal, GraphSeal, Identity, OpId,
OutputSeal, OwnedFraction, RgbDescr, RgbKeychain, RgbWallet, StateType, TokenIndex,
TransferParams, WalletError, WalletProvider, XChain, XOutpoint, XWitnessId,
Allocation, BundleId, ContractId, GenesisSeal, GraphSeal, Identity, OpId, Outpoint, OutputSeal,
OwnedFraction, RgbDescr, RgbKeychain, RgbWallet, StateType, TokenIndex, TransferParams,
WalletError, WalletProvider,
};
use rgbstd::interface::{AllocatedState, ContractIface, OwnedIface};
use rgbstd::persistence::{MemContractState, StockError};
Expand Down Expand Up @@ -476,12 +476,12 @@ impl Exec for RgbArgs {
eprintln!("Importing consignment {id}:");
let resolver = self.resolver()?;
eprint!("- validating the contract {} ... ", contract.contract_id());
let contract = contract
.validate(&resolver, self.general.network.is_testnet())
.map_err(|(status, _)| {
let contract = contract.validate(&resolver, self.chain_net()).map_err(
|(status, _)| {
eprintln!("failure");
status.to_string()
})?;
},
)?;
eprintln!("success");
stock.import_contract(contract, &resolver)?;
eprintln!("Consignment is imported");
Expand Down Expand Up @@ -574,11 +574,11 @@ impl Exec for RgbArgs {
WalletAll(&'w RgbWallet<Wallet<XpubDerivable, RgbDescr>>),
NoWallet,
}
impl<'w> AssignmentsFilter for Filter<'w> {
impl AssignmentsFilter for Filter<'_> {
fn should_include(
&self,
outpoint: impl Into<XOutpoint>,
id: Option<XWitnessId>,
outpoint: impl Into<Outpoint>,
id: Option<Txid>,
) -> bool {
match self {
Filter::Wallet(wallet) => wallet
Expand All @@ -589,12 +589,8 @@ impl Exec for RgbArgs {
}
}
}
impl<'w> Filter<'w> {
fn comment(&self, outpoint: XOutpoint) -> &'static str {
let outpoint = outpoint
.into_bp()
.into_bitcoin()
.expect("liquid is not yet supported");
impl Filter<'_> {
fn comment(&self, outpoint: Outpoint) -> &'static str {
match self {
Filter::Wallet(rgb) if rgb.wallet().is_unspent(outpoint) => "",
Filter::WalletAll(rgb) if rgb.wallet().is_unspent(outpoint) => {
Expand Down Expand Up @@ -704,7 +700,12 @@ impl Exec for RgbArgs {
))
})?;

let mut builder = stock.contract_builder(issuer.clone(), *schema_id, iface_id)?;
let mut builder = stock.contract_builder(
issuer.clone(),
*schema_id,
iface_id,
self.chain_net(),
)?;
let types = builder.type_system().clone();

if let Some(globals) = code.get("globals") {
Expand Down Expand Up @@ -732,6 +733,7 @@ impl Exec for RgbArgs {
.typify(val, sem_id)
.expect("global type doesn't match type definition");

#[allow(deprecated)]
let serialized = types
.strict_serialize_type::<MAX16>(&typed_val)
.expect("internal error");
Expand Down Expand Up @@ -771,7 +773,7 @@ impl Exec for RgbArgs {
.as_str()
.expect("seal must be a string");
let seal = OutputSeal::from_str(seal).expect("invalid seal definition");
let seal = GenesisSeal::new_random(seal.method, seal.txid, seal.vout);
let seal = GenesisSeal::new_random(seal.txid, seal.vout);

// Workaround for borrow checker:
let field_name =
Expand All @@ -784,7 +786,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));
let seal = BuilderSeal::Revealed(seal);
builder = builder
.add_fungible_state(field_name, seal, amount)
.expect("invalid global state data");
Expand Down Expand Up @@ -835,19 +837,12 @@ impl Exec for RgbArgs {
.next()
.expect("no addresses left")
.addr;
Beneficiary::WitnessVout(Pay2Vout {
address: addr.payload,
method: wallet.wallet().seal_close_method(),
})
Beneficiary::WitnessVout(Pay2Vout::new(addr.payload))
}
(_, Some(outpoint)) => {
let seal = XChain::Bitcoin(GraphSeal::new_random(
wallet.wallet().seal_close_method(),
outpoint.txid,
outpoint.vout,
));
let seal = GraphSeal::new_random(outpoint.txid, outpoint.vout);
wallet.stock_mut().store_secret_seal(seal)?;
Beneficiary::BlindedSeal(*seal.to_secret_seal().as_reduced_unsafe())
Beneficiary::BlindedSeal(seal.to_secret_seal())
}
};

Expand Down Expand Up @@ -1049,7 +1044,7 @@ impl Exec for RgbArgs {
pub struct ConsignmentInspection {
version: ContainerVer,
transfer: bool,
terminals: SmallOrdMap<BundleId, XChain<SecretSeal>>,
terminals: SmallOrdMap<BundleId, SecretSeal>,
supplements: TinyOrdSet<Supplement>,
signatures: TinyOrdMap<ContentId, ContentSigs>,
}
Expand Down Expand Up @@ -1250,12 +1245,11 @@ impl Exec for RgbArgs {
Command::Validate { file } => {
let mut resolver = self.resolver()?;
let consignment = Transfer::load_file(file)?;
resolver.add_terminals(&consignment);
let status =
match consignment.validate(&resolver, self.general.network.is_testnet()) {
Ok(consignment) => consignment.into_validation_status(),
Err((status, _)) => status,
};
resolver.add_consignment_txes(&consignment);
let status = match consignment.validate(&resolver, self.chain_net()) {
Ok(consignment) => consignment.into_validation_status(),
Err((status, _)) => status,
};
if status.validity() == Validity::Valid {
eprintln!("The provided consignment is valid")
} else {
Expand All @@ -1267,9 +1261,9 @@ impl Exec for RgbArgs {
let mut stock = self.rgb_stock()?;
let mut resolver = self.resolver()?;
let transfer = Transfer::load_file(file)?;
resolver.add_terminals(&transfer);
resolver.add_consignment_txes(&transfer);
let valid = transfer
.validate(&resolver, self.general.network.is_testnet())
.validate(&resolver, self.chain_net())
.map_err(|(status, _)| status)?;
stock.accept_transfer(valid, &resolver)?;
eprintln!("Transfer accepted into the stash");
Expand Down
1 change: 0 additions & 1 deletion examples/rgb20-demo.con
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ contract Test: NonInflatableAsset
owned assetOwner
state = 1_000_000__000_000_00
seal =
method := tapret1st
txid = #01d46e52c4bdb51931a0eae83e958c78bdef9cac2057b36d55370410edafdd42
vout = 0
2 changes: 1 addition & 1 deletion examples/rgb20-demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ globals:

assignments:
assetOwner:
seal: tapret1st:b449f7eaa3f98c145b27ad0eeb7b5679ceb567faef7a52479bc995792b65f804:1
seal: b449f7eaa3f98c145b27ad0eeb7b5679ceb567faef7a52479bc995792b65f804:1
amount: 100000000 # this is 1 million (we have two digits for cents)
36 changes: 12 additions & 24 deletions psbt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ mod rgb;

use bp::dbc::opret::OpretProof;
use bp::dbc::tapret::TapretProof;
use bp::seals::txout::CloseMethod;
pub use bpstd::psbt::*;
pub use rgb::*;
use rgbstd::containers::{AnchorSet, Batch, CloseMethodSet, Fascia, PubWitness, XPubWitness};
use rgbstd::XChain;
use rgbstd::containers::{AnchorSet, Batch, Fascia, PubWitness};

pub use self::rgb::{
ProprietaryKeyRgb, RgbExt, RgbInExt, RgbOutExt, RgbPsbtError, PSBT_GLOBAL_RGB_TRANSITION,
Expand Down Expand Up @@ -77,7 +77,7 @@ impl RgbPsbt for Psbt {
let contract_id = info.transition.contract_id;
let mut inputs = info.inputs.release();
for input in self.inputs_mut() {
if inputs.remove(&XChain::Bitcoin(input.prevout().outpoint())) {
if inputs.remove(&input.prevout().outpoint()) {
input
.set_rgb_consumer(contract_id, info.id)
.map_err(|_| EmbedError::PsbtRepeatedInputs)?;
Expand All @@ -86,7 +86,7 @@ impl RgbPsbt for Psbt {
if !inputs.is_empty() {
return Err(EmbedError::AbsentInputs);
}
self.push_rgb_transition(info.transition, info.method)
self.push_rgb_transition(info.transition)
.expect("transitions are unique since they are in BTreeMap indexed by opid");
}
Ok(())
Expand All @@ -96,30 +96,18 @@ impl RgbPsbt for Psbt {
// Convert RGB data to MPCs? Or should we do it at the moment we add them... No,
// since we may require more DBC methods with each additional state transition
let bundles = self.rgb_bundles_to_mpc()?;
// DBC commitment for the required methods
let methods = bundles
.values()
.flat_map(|b| b.iter())
.map(|b| CloseMethodSet::from(b.close_method))
.reduce(|methods, method| methods | method)
.ok_or(RgbPsbtError::NoContracts)?;
let (mut tapret_anchor, mut opret_anchor) = (None, None);
if methods.has_tapret_first() {
tapret_anchor = Some(self.dbc_commit::<TapretProof>()?);
}
if methods.has_opret_first() {
opret_anchor = Some(self.dbc_commit::<OpretProof>()?);
}
let anchor = match (tapret_anchor, opret_anchor) {
(None, None) => return Err(RgbPsbtError::NoContracts.into()),
(Some(tapret), None) => AnchorSet::Tapret(tapret),
(None, Some(opret)) => AnchorSet::Opret(opret),
(Some(tapret), Some(opret)) => AnchorSet::Double { tapret, opret },
// DBC commitment for the correct close method
let close_method = self
.rgb_close_method()?
.ok_or(RgbPsbtError::NoCloseMethod)?;
let anchor = match close_method {
CloseMethod::TapretFirst => AnchorSet::Tapret(self.dbc_commit::<TapretProof>()?),
CloseMethod::OpretFirst => AnchorSet::Opret(self.dbc_commit::<OpretProof>()?),
};
// TODO: Use signed transaction here!
let witness = PubWitness::with(self.to_unsigned_tx().into());
Ok(Fascia {
witness: XPubWitness::Bitcoin(witness),
witness,
anchor,
bundles,
})
Expand Down
Loading

0 comments on commit 85c23d7

Please sign in to comment.