Skip to content

Commit

Permalink
contract: fix unnamed commitment type by newtype for bundle input map
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Feb 15, 2024
1 parent 30f6329 commit 1759eab
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
43 changes: 38 additions & 5 deletions src/contract/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::BTreeMap;
use std::collections::{btree_map, BTreeMap};

use amplify::confinement::{Confined, U16};
use amplify::{Bytes32, Wrapper};
use bp::Vout;
use commit_verify::{mpc, CommitEncode, CommitEngine, CommitId, CommitmentId, DigestExt, Sha256};
use strict_encoding::{StrictDumb, StrictEncode};

use super::OpId;
use crate::{Transition, LIB_NAME_RGB};
use crate::{OpId, Transition, LIB_NAME_RGB};

pub type Vin = Vout;

Expand Down Expand Up @@ -66,6 +65,40 @@ impl From<mpc::Message> for BundleId {
fn from(id: mpc::Message) -> Self { BundleId(id.into_inner()) }
}

#[derive(Wrapper, WrapperMut, Clone, PartialEq, Eq, Hash, Debug, From)]

Check warning on line 68 in src/contract/bundle.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/bundle.rs#L68

Added line #L68 was not covered by tests
#[wrapper(Deref)]
#[wrapper_mut(DerefMut)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),

Check warning on line 75 in src/contract/bundle.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/bundle.rs#L75

Added line #L75 was not covered by tests
serde(crate = "serde_crate", transparent)
)]
pub struct InputMap(Confined<BTreeMap<Vin, OpId>, 1, U16>);

impl StrictDumb for InputMap {
fn strict_dumb() -> Self { Self(confined_bmap!(strict_dumb!() => strict_dumb!())) }
}

impl InputMap {
pub fn with(input: Vin, id: OpId) -> Self { InputMap(Confined::with((input, id))) }

Check warning on line 85 in src/contract/bundle.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/bundle.rs#L85

Added line #L85 was not covered by tests
}

impl IntoIterator for InputMap {
type Item = (Vin, OpId);
type IntoIter = btree_map::IntoIter<Vin, OpId>;

fn into_iter(self) -> Self::IntoIter { self.0.into_iter() }

Check warning on line 92 in src/contract/bundle.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/bundle.rs#L92

Added line #L92 was not covered by tests
}

impl<'a> IntoIterator for &'a InputMap {
type Item = (&'a Vin, &'a OpId);
type IntoIter = btree_map::Iter<'a, Vin, OpId>;

fn into_iter(self) -> Self::IntoIter { self.0.iter() }

Check warning on line 99 in src/contract/bundle.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/bundle.rs#L99

Added line #L99 was not covered by tests
}

#[derive(Clone, PartialEq, Eq, Debug, From)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
Expand All @@ -75,7 +108,7 @@ impl From<mpc::Message> for BundleId {
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct TransitionBundle {
pub input_map: Confined<BTreeMap<Vin, OpId>, 1, U16>,
pub input_map: InputMap,
pub known_transitions: Confined<BTreeMap<OpId, Transition>, 1, U16>,
}

Expand All @@ -88,7 +121,7 @@ impl CommitEncode for TransitionBundle {
impl StrictDumb for TransitionBundle {
fn strict_dumb() -> Self {
Self {
input_map: confined_bmap! { strict_dumb!() => strict_dumb!() },
input_map: strict_dumb!(),
known_transitions: confined_bmap! { strict_dumb!() => strict_dumb!() },
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub use assignments::{
TypedAssigns,
};
pub use attachment::{AttachId, ConcealedAttach, RevealedAttach};
pub use bundle::{BundleId, TransitionBundle, Vin};
pub use bundle::{BundleId, InputMap, TransitionBundle, Vin};
pub use contract::{
AssignmentWitness, ContractHistory, ContractState, GlobalOrd, KnownState, Opout,
OpoutParseError, OutputAssignment,
Expand Down
2 changes: 1 addition & 1 deletion src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::{

/// Strict types id for the library providing data types for RGB consensus.
pub const LIB_ID_RGB: &str =
"urn:ubideco:stl:35cF57bXFVGRrGsPBW7D9wh49BeAZpBgSwBGQxSXDFDH#station-product-conduct";
"urn:ubideco:stl:GBpCZWjW6YyuTB8tGMi856t1iATppxNGTr7GPzZxgSpU#helium-cinema-contact";

fn _rgb_core_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_RGB), tiny_bset! {
Expand Down

0 comments on commit 1759eab

Please sign in to comment.