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

v0.11 fixes #276

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ amplify = { workspace = true }
baid64 = { workspace = true }
strict_types = { workspace = true, features = ["serde"] }
commit_verify = { workspace = true }
bp-core = { workspace = true }
bp-std = { workspace = true, features = ["serde"] }
bp-wallet = { workspace = true, features = ["cli"] }
rgb-std = { workspace = true, features = ["serde"] }
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
4 changes: 2 additions & 2 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
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,7 @@ impl RgbArgs {
--esplora --mempool or --electrum argument")),
}
.map_err(WalletError::Resolver)?;
resolver.check(self.general.network)?;
resolver.check_chain_net(self.general.network.into())?;
Ok(resolver)
}
}
61 changes: 28 additions & 33 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::str::FromStr;

use amplify::confinement::{SmallOrdMap, TinyOrdMap, TinyOrdSet, U16 as MAX16};
use baid64::DisplayBaid64;
use bp::Txid;
use bpstd::psbt::{Psbt, PsbtVer};
use bpstd::seals::SecretSeal;
use bpstd::{Sats, XpubDerivable};
Expand All @@ -44,9 +45,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 @@ -477,7 +478,7 @@ impl Exec for RgbArgs {
let resolver = self.resolver()?;
eprint!("- validating the contract {} ... ", contract.contract_id());
let contract = contract
.validate(&resolver, self.general.network.is_testnet())
.validate(&resolver, self.general.network.into())
.map_err(|(status, _)| {
eprintln!("failure");
status.to_string()
Expand Down Expand Up @@ -574,11 +575,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 +590,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 +701,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.general.network.into(),
)?;
let types = builder.type_system().clone();

if let Some(globals) = code.get("globals") {
Expand Down Expand Up @@ -732,6 +734,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 +774,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 +787,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 +838,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 +1045,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 @@ -1251,11 +1247,10 @@ impl Exec for RgbArgs {
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,
};
let status = match consignment.validate(&resolver, self.general.network.into()) {
Ok(consignment) => consignment.into_validation_status(),
Err((status, _)) => status,
};
if status.validity() == Validity::Valid {
eprintln!("The provided consignment is valid")
} else {
Expand All @@ -1269,7 +1264,7 @@ impl Exec for RgbArgs {
let transfer = Transfer::load_file(file)?;
resolver.add_terminals(&transfer);
let valid = transfer
.validate(&resolver, self.general.network.is_testnet())
.validate(&resolver, self.general.network.into())
.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
Loading