Skip to content

Commit

Permalink
mpc: update to new copy_from_slice API from amplify
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 8, 2023
1 parent ebbec89 commit 05a9512
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions commit_verify/src/mpc/atoms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::io::Write;

use amplify::confinement::MediumOrdMap;
use amplify::num::u5;
use amplify::{Bytes32, Wrapper};
use amplify::{Bytes32, FromSliceError, Wrapper};

use crate::id::CommitmentId;
use crate::merkle::MerkleNode;
Expand Down Expand Up @@ -56,7 +56,13 @@ impl CommitStrategy for ProtocolId {
}

impl ProtocolId {
pub fn from_slice(slice: &[u8]) -> Option<Self> { Bytes32::from_slice(slice).map(Self) }
#[deprecated(since = "0.10.6", note = "use copy_from_slice")]
pub fn from_slice(slice: &[u8]) -> Option<Self> {
Bytes32::copy_from_slice(slice).ok().map(Self)
}
pub fn copy_from_slice(slice: &[u8]) -> Result<Self, FromSliceError> {
Bytes32::copy_from_slice(slice).map(Self)
}
}

/// Original message participating in multi-message commitment.
Expand All @@ -80,7 +86,13 @@ pub struct Message(
);

impl Message {
pub fn from_slice(slice: &[u8]) -> Option<Self> { Bytes32::from_slice(slice).map(Self) }
#[deprecated(since = "0.10.6", note = "use copy_from_slice")]
pub fn from_slice(slice: &[u8]) -> Option<Self> {
Bytes32::copy_from_slice(slice).ok().map(Self)
}
pub fn copy_from_slice(slice: &[u8]) -> Result<Self, FromSliceError> {
Bytes32::copy_from_slice(slice).map(Self)
}
}

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, From)]
Expand Down Expand Up @@ -149,7 +161,13 @@ impl CommitStrategy for Commitment {
}

impl Commitment {
pub fn from_slice(slice: &[u8]) -> Option<Self> { Bytes32::from_slice(slice).map(Self) }
#[deprecated(since = "0.10.6", note = "use copy_from_slice")]
pub fn from_slice(slice: &[u8]) -> Option<Self> {
Bytes32::copy_from_slice(slice).ok().map(Self)
}
pub fn copy_from_slice(slice: &[u8]) -> Result<Self, FromSliceError> {
Bytes32::copy_from_slice(slice).map(Self)
}
}

// TODO: Either this type or [`MerkleTree`] should remain
Expand Down

0 comments on commit 05a9512

Please sign in to comment.