diff --git a/Cargo.lock b/Cargo.lock index 0a9e056f..f6826ccd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aluvm" -version = "0.10.6" +version = "0.11.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e624a600eaf54f24da48e42604ffb0fbd543808a078e5081a9441243077233df" +checksum = "14a99358b65b74973749140c2bd657e960d54ba3925c5a56afdbf544317f12f6" dependencies = [ "amplify", "baid58", @@ -32,6 +32,7 @@ dependencies = [ "amplify_num", "amplify_syn", "ascii", + "rand", "serde", "serde_json", "serde_yaml", @@ -193,14 +194,14 @@ dependencies = [ [[package]] name = "bp-consensus" -version = "0.10.11" +version = "0.11.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d7b87840e5fc65bcbcd3881e0a0150ecef4a9b18b1356eb7a8a9adc85280c63" +checksum = "8ab8f217830b75d84b06b2a82bb42109b441b552bf8b871de8d735a60bf9717f" dependencies = [ "amplify", "chrono", "commit_verify", - "secp256k1", + "secp256k1 0.28.0", "serde", "strict_encoding", "strict_types", @@ -208,9 +209,9 @@ dependencies = [ [[package]] name = "bp-core" -version = "0.10.11" +version = "0.11.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a8b5219d96064b5d277c166fd5321ce6ee3e8a74e50bf2281d47726f365ead4" +checksum = "ece2f2e6f91bdbf5684f26a105c078e50394f98e37dc173c20b23eba53e7be09" dependencies = [ "amplify", "bp-consensus", @@ -225,24 +226,24 @@ dependencies = [ [[package]] name = "bp-dbc" -version = "0.10.11" +version = "0.11.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e265b111f61acb39cf36778c4da9a3d3c49fcc7a7e4116fd40ab250d598b1280" +checksum = "e0d9d7bbc4dc2debd9c30469752963410b44adee55af807378589e88c5fd913a" dependencies = [ "amplify", "base85", "bp-consensus", "commit_verify", - "secp256k1", + "secp256k1 0.28.0", "serde", "strict_encoding", ] [[package]] name = "bp-seals" -version = "0.10.11" +version = "0.11.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb60735209233ece5927a5c66355037af8479104b5ff55371ae4a0f53c96b2" +checksum = "3661c2c7bddda0b6fd37dafa1a56c863ba0ff9787ebc06d05eb8ac676f1d469e" dependencies = [ "amplify", "baid58", @@ -311,9 +312,9 @@ dependencies = [ [[package]] name = "commit_verify" -version = "0.10.6" +version = "0.11.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91d9d6e86f6cec8d4af19a0e418bac9cb266a6dc70660bcdcdac1e0fa924e0d1" +checksum = "82c1a7d13181451d927abcc477d4565f23eb06ab36820599cc75ed3161147daa" dependencies = [ "amplify", "commit_encoding_derive", @@ -597,9 +598,8 @@ dependencies = [ [[package]] name = "rgb-core" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74ace164ee5d1a2ba5224aee07cf365a69ca028b7bd1b3dc4906a4d1b889c246" +version = "0.11.0-beta.1" +source = "git+https://github.com/RGB-WG/rgb-core?branch=v0.11#bc626178003ce95cd36ae2d014230e4899602366" dependencies = [ "aluvm", "amplify", @@ -618,7 +618,7 @@ dependencies = [ [[package]] name = "rgb-std" -version = "0.10.10" +version = "0.11.0-beta.1" dependencies = [ "amplify", "baid58", @@ -639,7 +639,7 @@ dependencies = [ [[package]] name = "rgb-stl" -version = "0.10.10" +version = "0.11.0-beta.1" dependencies = [ "rgb-std", "strict_types", @@ -673,7 +673,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" dependencies = [ "rand", - "secp256k1-sys", + "secp256k1-sys 0.8.1", + "serde", +] + +[[package]] +name = "secp256k1" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acea373acb8c21ecb5a23741452acd2593ed44ee3d343e72baaa143bc89d0d5" +dependencies = [ + "rand", + "secp256k1-sys 0.9.0", "serde", ] @@ -686,6 +697,15 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09e67c467c38fd24bd5499dc9a18183b31575c12ee549197e3e20d57aa4fe3b7" +dependencies = [ + "cc", +] + [[package]] name = "secp256k1-zkp" version = "0.9.2" @@ -694,7 +714,7 @@ checksum = "026efcdacb95ee6aae5cc19144dc1549973eac36a4972700c28493de1ee5d69f" dependencies = [ "bitcoin-private", "rand", - "secp256k1", + "secp256k1 0.27.0", "secp256k1-zkp-sys", "serde", ] @@ -706,7 +726,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d03ab1ca75a18e1899e8d9b8d28b5998ae1ddcb42fec5956769718543293c723" dependencies = [ "cc", - "secp256k1-sys", + "secp256k1-sys 0.8.1", ] [[package]] @@ -785,9 +805,9 @@ dependencies = [ [[package]] name = "single_use_seals" -version = "0.10.1" +version = "0.11.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed7655b4b597fca10d2cf7579d3dfee1987a45342bdeecf90cab5affec1c7197" +checksum = "a46b0f289450dc06e7b94f048a55ac437177532f2c6c9bed12c1de7ac948f5a5" dependencies = [ "amplify_derive", ] diff --git a/Cargo.toml b/Cargo.toml index 54e76ca3..bb07e5fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ default-members = [ resolver = "2" [workspace.package] +version = "0.11.0-beta.1" authors = ["Dr Maxim Orlovsky "] homepage = "https://github.com/RGB-WG" repository = "https://github.com/RGB-WG/rgb-wallet" @@ -21,14 +22,14 @@ amplify = "4.5.0" baid58 = "0.4.4" strict_encoding = "2.6.1" strict_types = "1.6.3" -commit_verify = { version = "0.10.6", features = ["stl"] } -bp-core = { version = "0.10.11", features = ["stl"] } -rgb-core = { version = "0.10.8", features = ["stl"] } +commit_verify = { version = "0.11.0-beta.1", features = ["stl"] } +bp-core = { version = "0.11.0-beta.1", features = ["stl"] } +rgb-core = { version = "0.11.0-beta.1", features = ["stl"] } serde_crate = { package = "serde", version = "1", features = ["derive"] } [package] name = "rgb-std" -version = "0.10.10" +version = { workspace = true } description = "RGB standard library for working with smart contracts on Bitcoin & Lightning" keywords = ["bitcoin", "lightning", "rgb", "smart-contracts", "lnp-bp"] categories = ["cryptography::cryptocurrencies"] @@ -81,3 +82,6 @@ wasm-bindgen-test = "0.3" [package.metadata.docs.rs] features = [ "all" ] + +[patch.crates-io] +rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "v0.11" } diff --git a/src/accessors/assignments.rs b/src/accessors/assignments.rs index 0faed20e..70981052 100644 --- a/src/accessors/assignments.rs +++ b/src/accessors/assignments.rs @@ -20,22 +20,23 @@ // limitations under the License. use amplify::confinement::SmallVec; +use commit_verify::Conceal; use rgb::{ Assign, AssignAttach, AssignData, AssignFungible, AssignRights, ExposedSeal, ExposedState, - TypedAssigns, + SealDefinition, TypedAssigns, }; pub trait TypedAssignsExt { - fn reveal_seal(&mut self, seal: Seal); + fn reveal_seal(&mut self, seal: SealDefinition); - fn filter_revealed_seals(&self) -> Vec; + fn filter_revealed_seals(&self) -> Vec>; } impl TypedAssignsExt for TypedAssigns { - fn reveal_seal(&mut self, seal: Seal) { + fn reveal_seal(&mut self, seal: SealDefinition) { fn reveal( vec: &mut SmallVec>, - revealed: Seal, + revealed: SealDefinition, ) { for assign in vec.iter_mut() { match assign { @@ -64,7 +65,7 @@ impl TypedAssignsExt for TypedAssigns { } } - fn filter_revealed_seals(&self) -> Vec { + fn filter_revealed_seals(&self) -> Vec> { match self { TypedAssigns::Declarative(s) => { s.iter().filter_map(AssignRights::revealed_seal).collect() diff --git a/src/accessors/bundle.rs b/src/accessors/bundle.rs index bd6634b4..190d40da 100644 --- a/src/accessors/bundle.rs +++ b/src/accessors/bundle.rs @@ -19,7 +19,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use rgb::{GraphSeal, OpId, Operation, Transition, TransitionBundle}; +use rgb::{GraphSeal, OpId, Operation, SealDefinition, Transition, TransitionBundle}; use crate::accessors::TypedAssignsExt; @@ -32,7 +32,7 @@ pub enum RevealError { pub trait BundleExt { /// Ensures that the seal is revealed inside the bundle. - fn reveal_seal(&mut self, seal: GraphSeal); + fn reveal_seal(&mut self, seal: SealDefinition); /// Ensures that the transition is revealed inside the bundle. /// @@ -44,7 +44,7 @@ pub trait BundleExt { } impl BundleExt for TransitionBundle { - fn reveal_seal(&mut self, seal: GraphSeal) { + fn reveal_seal(&mut self, seal: SealDefinition) { for (_, item) in self.keyed_values_mut() { if let Some(transition) = &mut item.transition { for (_, assign) in transition.assignments.keyed_values_mut() { diff --git a/src/accessors/merge_reveal.rs b/src/accessors/merge_reveal.rs index 12361d9b..0d51d350 100644 --- a/src/accessors/merge_reveal.rs +++ b/src/accessors/merge_reveal.rs @@ -24,7 +24,7 @@ use std::collections::BTreeMap; use amplify::confinement::Confined; use amplify::Wrapper; use bp::dbc::anchor::MergeError; -use commit_verify::{mpc, CommitmentId}; +use commit_verify::CommitmentId; use rgb::{ Anchor, AnchoredBundle, Assign, Assignments, BundleItem, ExposedSeal, ExposedState, Extension, Genesis, OpId, Transition, TransitionBundle, TypedAssigns, @@ -64,7 +64,7 @@ pub trait MergeReveal: Sized { fn merge_reveal(self, other: Self) -> Result; } -impl MergeReveal for Anchor { +impl MergeReveal for Anchor { fn merge_reveal(self, other: Self) -> Result { self.merge_reveal(other).map_err(MergeRevealError::from) } diff --git a/src/containers/consignment.rs b/src/containers/consignment.rs index e1ed428a..6819e749 100644 --- a/src/containers/consignment.rs +++ b/src/containers/consignment.rs @@ -26,9 +26,9 @@ use amplify::confinement::{LargeVec, MediumBlob, SmallOrdMap, TinyOrdMap, TinyOr use commit_verify::Conceal; use rgb::validation::{AnchoredBundle, ConsignmentApi}; use rgb::{ - validation, AttachId, BundleId, ContractHistory, ContractId, Extension, Genesis, GraphSeal, - OpId, OpRef, Operation, Schema, SchemaId, SecretSeal, SubSchema, Transition, TransitionBundle, - WitnessAnchor, + validation, AssetTag, AssignmentType, AttachId, BundleId, ContractHistory, ContractId, + Extension, Genesis, GraphSeal, OpId, OpRef, Operation, Schema, SchemaId, SealDefinition, + SecretSeal, SubSchema, Transition, TransitionBundle, WitnessAnchor, }; use strict_encoding::{StrictDeserialize, StrictDumb, StrictSerialize}; @@ -87,6 +87,9 @@ pub struct Consignment { /// Known supplements. pub supplements: TinyOrdSet, + /// Confidential asset tags. + pub asset_tags: SmallOrdMap, + /// Genesis data. pub genesis: Genesis, @@ -120,11 +123,12 @@ impl Consignment { assert_eq!(schema.schema_id(), genesis.schema_id); Consignment { validation_status: None, - version: ContainerVer::V1, + version: ContainerVer::V2, transfer: TYPE, schema, ifaces: none!(), supplements: none!(), + asset_tags: none!(), genesis, terminals: none!(), bundles: none!(), @@ -214,7 +218,7 @@ impl Consignment { Ok(history) } - pub fn reveal_bundle_seal(&mut self, bundle_id: BundleId, revealed: GraphSeal) { + pub fn reveal_bundle_seal(&mut self, bundle_id: BundleId, revealed: SealDefinition) { for anchored_bundle in &mut self.bundles { if anchored_bundle.bundle.bundle_id() == bundle_id { anchored_bundle.bundle.reveal_seal(revealed); @@ -230,6 +234,7 @@ impl Consignment { schema: self.schema, ifaces: self.ifaces, supplements: self.supplements, + asset_tags: self.asset_tags, genesis: self.genesis, terminals: self.terminals, bundles: self.bundles, @@ -246,6 +251,9 @@ impl ConsignmentApi for Consignment { fn schema(&self) -> &SubSchema { &self.schema } + #[inline] + fn asset_tags(&self) -> &BTreeMap { self.asset_tags.as_inner() } + fn operation(&self, opid: OpId) -> Option { if opid == self.genesis.id() { return Some(OpRef::Genesis(&self.genesis)); diff --git a/src/containers/seal.rs b/src/containers/seal.rs index 1fb19bb0..0975e269 100644 --- a/src/containers/seal.rs +++ b/src/containers/seal.rs @@ -29,9 +29,9 @@ use bp::seals::txout::{CloseMethod, TxPtr}; use bp::secp256k1::rand::{thread_rng, RngCore}; use bp::Vout; use commit_verify::Conceal; -use rgb::{ExposedSeal, GenesisSeal, GraphSeal, SecretSeal}; +use rgb::{ExposedSeal, GraphSeal, SealDefinition, SecretSeal}; -use crate::{Outpoint, LIB_NAME_RGB_STD}; +use crate::LIB_NAME_RGB_STD; /// Seal definition which re-uses witness transaction id of some other seal, /// which is not known at the moment of seal construction. Thus, the definition @@ -136,31 +136,65 @@ pub enum TerminalSeal { /// Seal contained within the witness transaction #[strict_type(tag = 1)] - WitnessVout(VoutSeal), + BitcoinWitnessVout(VoutSeal), + + /// Seal contained within the witness transaction + #[strict_type(tag = 2)] + LiquidWitnessVout(VoutSeal), } impl From for TerminalSeal { fn from(seal: GraphSeal) -> Self { match seal.txid { - TxPtr::WitnessTx => { - TerminalSeal::WitnessVout(VoutSeal::with(seal.method, seal.vout, seal.blinding)) - } + TxPtr::WitnessTx => TerminalSeal::BitcoinWitnessVout(VoutSeal::with( + seal.method, + seal.vout, + seal.blinding, + )), TxPtr::Txid(_) => TerminalSeal::ConcealedUtxo(seal.conceal()), } } } +impl From> for TerminalSeal { + fn from(seal: SealDefinition) -> Self { + match seal { + SealDefinition::Bitcoin( + seal @ GraphSeal { + txid: TxPtr::WitnessTx, + .. + }, + ) => TerminalSeal::BitcoinWitnessVout(VoutSeal::with( + seal.method, + seal.vout, + seal.blinding, + )), + SealDefinition::Liquid( + seal @ GraphSeal { + txid: TxPtr::WitnessTx, + .. + }, + ) => TerminalSeal::LiquidWitnessVout(VoutSeal::with( + seal.method, + seal.vout, + seal.blinding, + )), + _ => TerminalSeal::ConcealedUtxo(seal.conceal()), + } + } +} + impl TerminalSeal { /// Constructs [`TerminalSeal`] for the witness transaction. Uses /// `thread_rng` to initialize blinding factor. pub fn new_vout(method: CloseMethod, vout: impl Into) -> TerminalSeal { - TerminalSeal::WitnessVout(VoutSeal::new(method, vout)) + TerminalSeal::BitcoinWitnessVout(VoutSeal::new(method, vout)) } pub fn secret_seal(&self) -> Option { match self { TerminalSeal::ConcealedUtxo(seal) => Some(*seal), - TerminalSeal::WitnessVout(_) => None, + TerminalSeal::BitcoinWitnessVout(_) | TerminalSeal::LiquidWitnessVout(_) => None, } } } @@ -171,7 +205,12 @@ impl Conceal for TerminalSeal { fn conceal(&self) -> Self::Concealed { match *self { TerminalSeal::ConcealedUtxo(hash) => hash, - TerminalSeal::WitnessVout(seal) => GraphSeal::from(seal).conceal(), + TerminalSeal::BitcoinWitnessVout(seal) => { + SealDefinition::Bitcoin(GraphSeal::from(seal)).conceal() + } + TerminalSeal::LiquidWitnessVout(seal) => { + SealDefinition::Liquid(GraphSeal::from(seal)).conceal() + } } } } @@ -180,7 +219,8 @@ impl Display for TerminalSeal { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match *self { TerminalSeal::ConcealedUtxo(ref seal) => Display::fmt(seal, f), - TerminalSeal::WitnessVout(seal) => Display::fmt(&GraphSeal::from(seal), f), + TerminalSeal::BitcoinWitnessVout(seal) => Display::fmt(&GraphSeal::from(seal), f), + TerminalSeal::LiquidWitnessVout(seal) => Display::fmt(&GraphSeal::from(seal), f), } } } @@ -198,25 +238,8 @@ impl FromStr for TerminalSeal { /// Seal used by operation builder which can be either revealed or concealed. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, From)] pub enum BuilderSeal { - Revealed(Seal), + #[from] + Revealed(SealDefinition), #[from] Concealed(SecretSeal), } - -impl From for BuilderSeal -where Seal: From -{ - fn from(seal: Outpoint) -> Self { BuilderSeal::Revealed(seal.into()) } -} - -impl From for BuilderSeal -where Seal: From -{ - fn from(seal: GraphSeal) -> Self { BuilderSeal::Revealed(seal.into()) } -} - -impl From for BuilderSeal -where Seal: From -{ - fn from(seal: GenesisSeal) -> Self { BuilderSeal::Revealed(seal.into()) } -} diff --git a/src/containers/util.rs b/src/containers/util.rs index 66a6dfb9..c0063130 100644 --- a/src/containers/util.rs +++ b/src/containers/util.rs @@ -65,7 +65,7 @@ impl Terminal { #[non_exhaustive] #[repr(u8)] pub enum ContainerVer { - // V0 was a previous version before v0.10, which is now not supported. + // V0 and V1 was a previous version before v0.11, currently not supported. #[default] - V1 = 1, + V2 = 2, } diff --git a/src/containers/validate.rs b/src/containers/validate.rs index b22b7a3f..fe4eb41e 100644 --- a/src/containers/validate.rs +++ b/src/containers/validate.rs @@ -27,8 +27,9 @@ impl Consignment { pub fn validate( mut self, resolver: &mut R, + testnet: bool, ) -> Result, Consignment> { - let mut status = Validator::validate(&self, resolver); + let mut status = Validator::validate(&self, resolver, testnet); let validity = status.validity(); diff --git a/src/interface/builder.rs b/src/interface/builder.rs index e7459e01..6a89107c 100644 --- a/src/interface/builder.rs +++ b/src/interface/builder.rs @@ -19,16 +19,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::HashMap; +use std::collections::{BTreeMap, HashMap}; use amplify::confinement::{Confined, TinyOrdMap, U16, U8}; use amplify::{confinement, Wrapper}; -use bp::secp256k1::rand::thread_rng; -use bp::Chain; use rgb::{ - Assign, AssignmentType, Assignments, ContractId, ExposedSeal, FungibleType, Genesis, - GenesisSeal, GlobalState, GraphSeal, Input, Inputs, Opout, RevealedData, RevealedValue, - StateSchema, SubSchema, Transition, TransitionType, TypedAssigns, BLANK_TRANSITION_ID, + AltLayer1, AltLayer1Set, AssetTag, Assign, AssignmentType, Assignments, ContractId, + ExposedSeal, FungibleType, Genesis, GenesisSeal, GlobalState, GraphSeal, Input, Inputs, Opout, + RevealedData, RevealedValue, SealDefinition, StateSchema, SubSchema, Transition, + TransitionType, TypedAssigns, }; use strict_encoding::{FieldName, SerializeError, StrictSerialize, TypeName}; use strict_types::decode; @@ -40,28 +39,35 @@ use crate::interface::{Iface, IfaceImpl, IfacePair, TransitionIface, TypedState} #[display(doc_comments)] pub enum BuilderError { /// interface implementation references different interface that the one - /// provided to the forge. + /// provided to the builder. InterfaceMismatch, /// interface implementation references different schema that the one - /// provided to the forge. + /// provided to the builder. SchemaMismatch, - /// Global state `{0}` is not known to the schema. + /// contract already has too many layers1. + TooManyLayers1, + + /// global state `{0}` is not known to the schema. GlobalNotFound(FieldName), - /// Assignment `{0}` is not known to the schema. + /// assignment `{0}` is not known to the schema. AssignmentNotFound(FieldName), /// transition `{0}` is not known to the schema. TransitionNotFound(TypeName), - /// state `{0}` provided to the builder has invalid name + /// state `{0}` provided to the builder has invalid name. InvalidStateField(FieldName), - /// state `{0}` provided to the builder has invalid name + /// state `{0}` provided to the builder has invalid name. InvalidState(AssignmentType), + /// can't add asset of type `{0}`: you need to register the type with asset + /// type firtst using `add_asset_tag` method. + AssetTagUnknown(AssignmentType), + /// interface doesn't specifies default operation name, thus an explicit /// operation type must be provided with `set_operation_type` method. NoOperationSubtype, @@ -85,20 +91,39 @@ pub enum BuilderError { #[derive(Clone, Debug)] pub struct ContractBuilder { builder: OperationBuilder, - chain: Chain, + testnet: bool, + alt_layers1: AltLayer1Set, } impl ContractBuilder { - pub fn with(iface: Iface, schema: SubSchema, iimpl: IfaceImpl) -> Result { + pub fn mainnet( + iface: Iface, + schema: SubSchema, + iimpl: IfaceImpl, + ) -> Result { Ok(Self { builder: OperationBuilder::with(iface, schema, iimpl)?, - chain: default!(), + testnet: false, + alt_layers1: none!(), + }) + } + pub fn testnet( + iface: Iface, + schema: SubSchema, + iimpl: IfaceImpl, + ) -> Result { + Ok(Self { + builder: OperationBuilder::with(iface, schema, iimpl)?, + testnet: true, + alt_layers1: none!(), }) } - pub fn set_chain(mut self, chain: Chain) -> Self { - self.chain = chain; - self + pub fn add_layer1(mut self, layer1: AltLayer1) -> Result { + self.alt_layers1 + .push(layer1) + .map(|_| self) + .map_err(|_| BuilderError::TooManyLayers1) } pub fn assignments_type(&self, name: &FieldName) -> Option { @@ -126,7 +151,7 @@ impl ContractBuilder { pub fn add_fungible_state( mut self, name: impl Into, - seal: impl Into, + seal: impl Into>, value: u64, ) -> Result { let name = name.into(); @@ -142,7 +167,7 @@ impl ContractBuilder { pub fn add_data_state( mut self, name: impl Into, - seal: impl Into, + seal: impl Into>, value: impl StrictSerialize, ) -> Result { let name = name.into(); @@ -164,7 +189,8 @@ impl ContractBuilder { let genesis = Genesis { ffv: none!(), schema_id: schema.schema_id(), - chain: self.chain, + testnet: self.testnet, + alt_layers1: self.alt_layers1, metadata: empty!(), globals: global, assignments, @@ -193,7 +219,7 @@ impl TransitionBuilder { schema: SubSchema, iimpl: IfaceImpl, ) -> Result { - Self::with(iface, schema, iimpl, BLANK_TRANSITION_ID) + Self::with(iface, schema, iimpl, TransitionType::BLANK) } pub fn default_transition( @@ -364,6 +390,7 @@ struct OperationBuilder { schema: SubSchema, iface: Iface, iimpl: IfaceImpl, + asset_tags: BTreeMap, global: GlobalState, // rights: TinyOrdMap>, 1, U8>>, @@ -391,6 +418,7 @@ impl OperationBuilder { schema, iface, iimpl, + asset_tags: none!(), global: none!(), fungible: none!(), @@ -398,6 +426,12 @@ impl OperationBuilder { }) } + #[inline] + pub fn add_asset_tag(mut self, assignment_type: AssignmentType, asset_tag: AssetTag) -> Self { + self.asset_tags.insert(assignment_type, asset_tag); + self + } + pub fn add_global_state( mut self, name: impl Into, @@ -442,7 +476,11 @@ impl OperationBuilder { todo!() } TypedState::Amount(value) => { - let state = RevealedValue::new(value, &mut thread_rng()); + let tag = *self + .asset_tags + .get(&type_id) + .ok_or(BuilderError::AssetTagUnknown(type_id))?; + let state = RevealedValue::new_random_blinding(value, tag); let state_schema = self.schema.owned_types.get(&type_id).expect( diff --git a/src/lib.rs b/src/lib.rs index a4c7bc32..51060fcf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,7 +88,7 @@ pub mod accessors; pub mod descriptor; mod reserved; -pub use bp::{Chain, Outpoint, Txid}; +pub use bp::{Outpoint, Txid}; pub(crate) use reserved::ReservedBytes; pub use rgb::*; pub use stl::{LIB_NAME_RGB_CONTRACT, LIB_NAME_RGB_STD}; diff --git a/src/persistence/hoard.rs b/src/persistence/hoard.rs index 6e10a5ee..c65cf08b 100644 --- a/src/persistence/hoard.rs +++ b/src/persistence/hoard.rs @@ -26,7 +26,6 @@ use amplify::confinement; use amplify::confinement::{Confined, LargeOrdMap, SmallOrdMap, TinyOrdMap, TinyOrdSet}; use bp::dbc::anchor::MergeError; use commit_verify::mpc; -use commit_verify::mpc::MerkleBlock; use rgb::{ Anchor, AnchorId, AnchoredBundle, BundleId, ContractId, Extension, Genesis, OpId, Operation, SchemaId, TransitionBundle, @@ -70,7 +69,7 @@ pub struct Hoard { pub(super) suppl: TinyOrdMap>, pub(super) bundles: LargeOrdMap, pub(super) extensions: LargeOrdMap, - pub(super) anchors: LargeOrdMap>, + pub(super) anchors: LargeOrdMap, pub(super) sigs: SmallOrdMap, } @@ -199,7 +198,7 @@ impl Hoard { } // TODO: Move into Stash trait and re-implement using trait accessor methods - pub fn consume_anchor(&mut self, anchor: Anchor) -> Result<(), ConsumeError> { + pub fn consume_anchor(&mut self, anchor: Anchor) -> Result<(), ConsumeError> { let anchor_id = anchor.anchor_id(); match self.anchors.get_mut(&anchor_id) { Some(a) => *a = a.clone().merge_reveal(anchor)?, @@ -301,7 +300,7 @@ impl Stash for Hoard { Ok(self.anchors.keys().copied().collect()) } - fn anchor(&self, anchor_id: AnchorId) -> Result<&Anchor, StashError> { + fn anchor(&self, anchor_id: AnchorId) -> Result<&Anchor, StashError> { self.anchors .get(&anchor_id) .ok_or(StashInconsistency::AnchorAbsent(anchor_id).into()) diff --git a/src/persistence/inventory.rs b/src/persistence/inventory.rs index 3344857b..b48cd741 100644 --- a/src/persistence/inventory.rs +++ b/src/persistence/inventory.rs @@ -26,10 +26,11 @@ use std::ops::Deref; use amplify::confinement::{self, Confined}; use bp::seals::txout::blind::SingleBlindSeal; use bp::Txid; -use commit_verify::mpc; +use commit_verify::{mpc, Conceal}; use rgb::{ validation, Anchor, AnchoredBundle, BundleId, ContractId, ExposedSeal, GraphSeal, OpId, - Operation, Opout, SchemaId, SecretSeal, SubSchema, Transition, TransitionBundle, + Operation, Opout, SchemaId, SealDefinition, SecretSeal, SubSchema, Transition, + TransitionBundle, }; use strict_encoding::TypeName; @@ -303,10 +304,7 @@ pub trait Inventory: Deref { /// Assumes that the bundle belongs to a non-mined witness transaction. Must /// be used only to consume locally-produced bundles before witness /// transactions are mined. - fn consume_anchor( - &mut self, - anchor: Anchor, - ) -> Result<(), InventoryError>; + fn consume_anchor(&mut self, anchor: Anchor) -> Result<(), InventoryError>; /// # Safety /// @@ -469,8 +467,13 @@ pub trait Inventory: Deref { outpoints: impl IntoIterator>, ) -> Result, InventoryError>; - fn store_seal_secret(&mut self, seal: GraphSeal) -> Result<(), InventoryError>; - fn seal_secrets(&mut self) -> Result, InventoryError>; + fn store_seal_secret( + &mut self, + seal: SealDefinition, + ) -> Result<(), InventoryError>; + fn seal_secrets( + &mut self, + ) -> Result>, InventoryError>; #[allow(clippy::type_complexity)] fn export_contract( @@ -481,7 +484,7 @@ pub trait Inventory: Deref { ConsignerError::Target as Stash>::Error>, > { let mut consignment = - self.consign::(contract_id, [] as [GraphSeal; 0])?; + self.consign::(contract_id, [] as [SealDefinition; 0])?; consignment.transfer = false; Ok(consignment.into()) // TODO: Add known sigs to the bindle diff --git a/src/persistence/stash.rs b/src/persistence/stash.rs index a91daecb..e5277be3 100644 --- a/src/persistence/stash.rs +++ b/src/persistence/stash.rs @@ -25,7 +25,6 @@ use std::collections::{BTreeMap, BTreeSet}; use std::error::Error; use amplify::confinement::TinyOrdSet; -use commit_verify::mpc; use rgb::{ Anchor, AnchorId, BundleId, ContractId, Extension, Genesis, OpId, SchemaId, TransitionBundle, }; @@ -125,8 +124,5 @@ pub trait Stash { fn anchor_ids(&self) -> Result, Self::Error>; - fn anchor( - &self, - anchor_id: AnchorId, - ) -> Result<&Anchor, StashError>; + fn anchor(&self, anchor_id: AnchorId) -> Result<&Anchor, StashError>; } diff --git a/src/persistence/stock.rs b/src/persistence/stock.rs index 02ece7e0..264e9622 100644 --- a/src/persistence/stock.rs +++ b/src/persistence/stock.rs @@ -25,15 +25,13 @@ use std::ops::{Deref, DerefMut}; use amplify::confinement::{MediumOrdMap, MediumOrdSet, TinyOrdMap}; use amplify::ByteArray; -use bp::dbc::Anchor; use bp::Txid; -use commit_verify::mpc::MerkleBlock; use rgb::validation::{Status, Validity, Warning}; use rgb::{ - validation, AnchorId, AnchoredBundle, Assign, AssignmentType, BundleId, ContractHistory, - ContractId, ContractState, ExposedState, Extension, Genesis, GenesisSeal, GraphSeal, OpId, - Operation, Opout, SecretSeal, SubSchema, Transition, TransitionBundle, TxoSeal, TypedAssigns, - WitnessAnchor, + validation, Anchor, AnchorId, AnchoredBundle, Assign, AssignmentType, BundleId, + ContractHistory, ContractId, ContractState, ExposedState, Extension, Genesis, GenesisSeal, + GraphSeal, OpId, Operation, Opout, SealDefinition, SecretSeal, SubSchema, Transition, + TransitionBundle, TxoSeal, TypedAssigns, WitnessAnchor, }; use strict_encoding::{StrictDeserialize, StrictSerialize}; @@ -80,7 +78,7 @@ pub struct Stock { contract_index: TinyOrdMap, terminal_index: MediumOrdMap, // secrets - seal_secrets: MediumOrdSet, + seal_secrets: MediumOrdSet>, } impl Default for Stock { @@ -491,10 +489,7 @@ impl Inventory for Stock { self.consume_consignment(transfer, resolver, force) } - fn consume_anchor( - &mut self, - anchor: Anchor, - ) -> Result<(), InventoryError> { + fn consume_anchor(&mut self, anchor: Anchor) -> Result<(), InventoryError> { let anchor_id = anchor.anchor_id(); for (_, bundle_id) in anchor.mpc_proof.to_known_message_map() { self.anchor_bundle_index @@ -703,12 +698,17 @@ impl Inventory for Stock { Ok(res) } - fn store_seal_secret(&mut self, seal: GraphSeal) -> Result<(), InventoryError> { + fn store_seal_secret( + &mut self, + seal: SealDefinition, + ) -> Result<(), InventoryError> { self.seal_secrets.push(seal)?; Ok(()) } - fn seal_secrets(&mut self) -> Result, InventoryError> { + fn seal_secrets( + &mut self, + ) -> Result>, InventoryError> { Ok(self.seal_secrets.to_inner()) } } diff --git a/src/stl/specs.rs b/src/stl/specs.rs index f3ec0407..bd5fde75 100644 --- a/src/stl/specs.rs +++ b/src/stl/specs.rs @@ -685,7 +685,7 @@ impl Timestamp { pub fn to_utc(self) -> Option> { NaiveDateTime::from_timestamp_opt(self.0, 0) - .map(|naive| DateTime::::from_utc(naive, Utc)) + .map(|naive| DateTime::from_naive_utc_and_offset(naive, Utc)) } pub fn to_local(self) -> Option> { self.to_utc().map(DateTime::::from) } diff --git a/stl/Cargo.toml b/stl/Cargo.toml index 280918d1..d6697c07 100644 --- a/stl/Cargo.toml +++ b/stl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rgb-stl" -version = "0.10.10" +version = { workspace = true } description = "RGB strict type libraries" keywords = ["bitcoin", "lightning", "rgb", "smart-contracts", "lnp-bp"] categories = ["cryptography::cryptocurrencies"] @@ -18,4 +18,4 @@ path = "src/main.rs" [dependencies] strict_types = { workspace = true } -rgb-std = { version = "0.10.10", path = ".." } +rgb-std = { version = "0.11.0-beta.1", path = ".." }