Skip to content
Open
3 changes: 1 addition & 2 deletions src/human_encoding/named_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use crate::node::{
self, Commit, CommitData, CommitNode, Construct, ConstructData, Constructible as _, Converter,
CoreConstructible as _, Inner, NoDisconnect, NoWitness, Node,
};
use crate::types;
use crate::types::arrow::{Arrow, FinalArrow};
use crate::types::{self, Arrow, FinalArrow};
use crate::{encode, ConstructNode, Value};
use crate::{BitWriter, Cmr, Ihr};

Expand Down
2 changes: 1 addition & 1 deletion src/merkle/amr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::jet::Jet;
use crate::merkle::compact_value;
use crate::types::arrow::FinalArrow;
use crate::types::FinalArrow;
use crate::value::Word;
use crate::{Cmr, Tmr, Value};
use hashes::sha256::Midstate;
Expand Down
7 changes: 7 additions & 0 deletions src/merkle/cmr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: CC0-1.0

use crate::jet::Jet;
#[cfg(feature = "elements")]
use crate::node::{CoreConstructible, DisconnectConstructible, WitnessConstructible};
#[cfg(feature = "elements")]
use crate::types::{self, Error};
use crate::value::Word;
use crate::{FailEntropy, Tmr};
Expand Down Expand Up @@ -254,11 +256,13 @@ impl Cmr {
/// Wrapper around a CMR which allows it to be constructed with the
/// `*Constructible*` traits, allowing CMRs to be computed using the
/// same generic construction code that nodes are.
#[cfg(feature = "elements")] // only used by policy module
pub struct ConstructibleCmr<'brand> {
pub cmr: Cmr,
pub inference_context: types::Context<'brand>,
}

#[cfg(feature = "elements")] // only used by policy module
impl<'brand> CoreConstructible<'brand> for ConstructibleCmr<'brand> {
fn iden(inference_context: &types::Context<'brand>) -> Self {
ConstructibleCmr {
Expand Down Expand Up @@ -366,6 +370,7 @@ impl<'brand> CoreConstructible<'brand> for ConstructibleCmr<'brand> {
}
}

#[cfg(feature = "elements")] // only used by policy module
impl<'brand, X> DisconnectConstructible<'brand, X> for ConstructibleCmr<'brand> {
// Specifically with disconnect we don't check for consistency between the
// type inference context of the disconnected node, if any, and that of
Expand All @@ -379,6 +384,7 @@ impl<'brand, X> DisconnectConstructible<'brand, X> for ConstructibleCmr<'brand>
}
}

#[cfg(feature = "elements")] // only used by policy module
impl<'brand, W> WitnessConstructible<'brand, W> for ConstructibleCmr<'brand> {
fn witness(inference_context: &types::Context<'brand>, _witness: W) -> Self {
ConstructibleCmr {
Expand All @@ -393,6 +399,7 @@ mod tests {
use super::*;

use crate::node::{ConstructNode, CoreConstructible};
use crate::types;

use std::str::FromStr;
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion src/merkle/ihr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: CC0-1.0

use crate::jet::Jet;
use crate::types::arrow::FinalArrow;
use crate::types::FinalArrow;
use crate::value::Word;
use crate::{Cmr, Tmr, Value};
use hashes::sha256::Midstate;
Expand Down
38 changes: 27 additions & 11 deletions src/node/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

use crate::dag::{DagLike, MaxSharing, NoSharing, PostOrderIterItem};
use crate::jet::Jet;
use crate::types::arrow::{Arrow, FinalArrow};
use crate::types::{Arrow, FinalArrow};
use crate::{encode, types, Value};
use crate::{Amr, BitIter, BitWriter, Cmr, DecodeError, Ihr, Imr};

use super::{
Construct, ConstructData, ConstructNode, Constructible, Converter, Inner, Marker, NoDisconnect,
NoWitness, Node, Redeem, RedeemNode,
Construct, ConstructData, ConstructNode, Converter, Inner, Marker, NoDisconnect, NoWitness,
Node, Redeem, RedeemNode,
};

use std::io;
Expand Down Expand Up @@ -213,14 +213,30 @@ impl CommitNode {
&Option<Value>,
>,
) -> Result<ConstructData<'brand>, Self::Error> {
let inner = inner
.map(|node| node.arrow())
.map_disconnect(|maybe_node| maybe_node.as_ref().map(|node| node.arrow()));
let inner = inner.disconnect_as_ref(); // lol sigh rust
Ok(ConstructData::new(Arrow::from_inner(
self.inference_context,
inner,
)?))
use crate::node::DisconnectConstructible as _;

let new_arrow = match inner {
Inner::Iden => Arrow::iden(self.inference_context),
Inner::Unit => Arrow::unit(self.inference_context),
Inner::InjL(child) => Arrow::injl(child.arrow()),
Inner::InjR(child) => Arrow::injr(child.arrow()),
Inner::Take(child) => Arrow::take(child.arrow()),
Inner::Drop(child) => Arrow::drop_(child.arrow()),
Inner::Comp(lft, rgt) => Arrow::comp(lft.arrow(), rgt.arrow())?,
Inner::Case(lft, rgt) => Arrow::case(lft.arrow(), rgt.arrow())?,
Inner::Pair(lft, rgt) => Arrow::pair(lft.arrow(), rgt.arrow())?,
Inner::Disconnect(lft, rgt) => {
Arrow::disconnect(lft.arrow(), &rgt.as_ref().map(|node| node.arrow()))?
}
Inner::AssertL(lft, _) => Arrow::assertl(lft.arrow())?,
Inner::AssertR(_, rgt) => Arrow::assertr(rgt.arrow())?,
Inner::Witness(_) => Arrow::witness(self.inference_context),
Inner::Fail(_) => Arrow::fail(self.inference_context),
Inner::Jet(ref jet) => Arrow::jet(self.inference_context, jet.as_ref()),
Inner::Word(ref word) => Arrow::const_word(self.inference_context, word),
};

Ok(ConstructData::new(new_arrow))
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/node/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::dag::{InternalSharing, PostOrderIterItem};
use crate::jet::{Jet, JetEnvironment};
use crate::types::{self, arrow::Arrow};
use crate::types::{self, Arrow};
use crate::{encode, BitIter, BitWriter, Cmr, FailEntropy, FinalizeError, RedeemNode, Value, Word};

use std::io;
Expand Down Expand Up @@ -330,15 +330,15 @@ impl<'brand> CoreConstructible<'brand> for ConstructData<'brand> {
})
}

fn assertl(left: &Self, right: Cmr) -> Result<Self, types::Error> {
fn assertl(left: &Self, _: Cmr) -> Result<Self, types::Error> {
Ok(ConstructData {
arrow: Arrow::assertl(&left.arrow, right)?,
arrow: Arrow::assertl(&left.arrow)?,
})
}

fn assertr(left: Cmr, right: &Self) -> Result<Self, types::Error> {
fn assertr(_: Cmr, right: &Self) -> Result<Self, types::Error> {
Ok(ConstructData {
arrow: Arrow::assertr(left, &right.arrow)?,
arrow: Arrow::assertr(&right.arrow)?,
})
}

Expand All @@ -348,15 +348,15 @@ impl<'brand> CoreConstructible<'brand> for ConstructData<'brand> {
})
}

fn fail(inference_context: &types::Context<'brand>, entropy: FailEntropy) -> Self {
fn fail(inference_context: &types::Context<'brand>, _: FailEntropy) -> Self {
ConstructData {
arrow: Arrow::fail(inference_context, entropy),
arrow: Arrow::fail(inference_context),
}
}

fn const_word(inference_context: &types::Context<'brand>, word: Word) -> Self {
ConstructData {
arrow: Arrow::const_word(inference_context, word),
arrow: Arrow::const_word(inference_context, &word),
}
}

Expand Down Expand Up @@ -388,7 +388,7 @@ impl<'brand> DisconnectConstructible<'brand, Option<Arc<ConstructNode<'brand>>>>
impl<'brand> WitnessConstructible<'brand, Option<Value>> for ConstructData<'brand> {
fn witness(inference_context: &types::Context<'brand>, _witness: Option<Value>) -> Self {
ConstructData {
arrow: Arrow::witness(inference_context, NoWitness),
arrow: Arrow::witness(inference_context),
}
}
}
Expand Down
Loading