diff --git a/ergotree-interpreter/src/eval/deserialize_context.rs b/ergotree-interpreter/src/eval/deserialize_context.rs index cbb88fcd2..49485e389 100644 --- a/ergotree-interpreter/src/eval/deserialize_context.rs +++ b/ergotree-interpreter/src/eval/deserialize_context.rs @@ -14,8 +14,12 @@ impl Evaluable for DeserializeContext { fn eval(&self, env: &mut Env, ctx: &mut EvalContext) -> Result { match ctx.ctx.extension.values.get(&self.id) { Some(c) => { - if c.tpe != SType::SColl(SType::SByte.into()) { - Err(EvalError::UnexpectedExpr(format!("DeserializeContext: expected extension value to have type SColl(SByte), got {:?}", c.tpe))) + let expected_tpe = SType::SColl(SType::SByte.into()); + if c.tpe != expected_tpe { + Err(EvalError::UnexpectedExpr(format!( + "DeserializeContext: expected extension value to have type {:?} got {:?}", + expected_tpe, c.tpe + ))) } else { let bytes = c.v.clone().try_extract_into::>()?; let expr = Expr::sigma_parse_bytes(bytes.as_slice())?; @@ -26,8 +30,8 @@ impl Evaluable for DeserializeContext { } } None => Err(EvalError::NotFound(format!( - "DeserializeContext: no value with id {} in context extension", - self.id + "DeserializeContext: no value with id {} in context extension map {}", + self.id, ctx.ctx.extension ))), } } diff --git a/ergotree-interpreter/src/eval/expr.rs b/ergotree-interpreter/src/eval/expr.rs index 2c04f17a4..651999dd5 100644 --- a/ergotree-interpreter/src/eval/expr.rs +++ b/ergotree-interpreter/src/eval/expr.rs @@ -40,7 +40,7 @@ impl Evaluable for Expr { )), Expr::Collection(op) => op.eval(env, ctx), Expr::ValDef(_) => Err(EvalError::UnexpectedExpr( - ("ValDef is evaluated in BlockValue").to_string(), + ("ValDef should be evaluated in BlockValue").to_string(), )), Expr::And(op) => op.eval(env, ctx), Expr::Or(op) => op.eval(env, ctx), diff --git a/ergotree-interpreter/src/eval/get_var.rs b/ergotree-interpreter/src/eval/get_var.rs index 07bbbfb7c..1ac5e34e6 100644 --- a/ergotree-interpreter/src/eval/get_var.rs +++ b/ergotree-interpreter/src/eval/get_var.rs @@ -1,4 +1,3 @@ -// use ergotree_ir::mir::constant::TryExtractInto; use ergotree_ir::mir::constant::TryExtractFromError; use ergotree_ir::mir::get_var::GetVar; use ergotree_ir::mir::value::Value; @@ -14,8 +13,8 @@ impl Evaluable for GetVar { None => Ok(Value::Opt(None.into())), Some(v) if v.tpe == self.var_tpe => Ok((Some(v.v.clone())).into()), Some(v) => Err(TryExtractFromError(format!( - "GetVar: expected {:?}, found {:?}", - self.var_tpe, v.tpe + "GetVar: expected extension value id {} to have type {:?}, found {:?} in context extension map {}", + self.var_id, self.var_tpe, v, ctx.ctx.extension )) .into()), } diff --git a/ergotree-interpreter/src/sigma_protocol/prover/context_extension.rs b/ergotree-interpreter/src/sigma_protocol/prover/context_extension.rs index 09aed3e41..ed245147f 100644 --- a/ergotree-interpreter/src/sigma_protocol/prover/context_extension.rs +++ b/ergotree-interpreter/src/sigma_protocol/prover/context_extension.rs @@ -7,6 +7,7 @@ use ergotree_ir::serialization::SigmaSerializable; use ergotree_ir::serialization::SigmaSerializeResult; use indexmap::IndexMap; use std::convert::TryFrom; +use std::fmt; use thiserror::Error; /// User-defined variables to be put into context @@ -25,6 +26,12 @@ impl ContextExtension { } } +impl fmt::Display for ContextExtension { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_map().entries(self.values.iter()).finish() + } +} + impl SigmaSerializable for ContextExtension { fn sigma_serialize(&self, w: &mut W) -> SigmaSerializeResult { w.put_u8(self.values.len() as u8)?; diff --git a/ergotree-ir/src/mir/constant.rs b/ergotree-ir/src/mir/constant.rs index e3ff14b09..be58514c0 100644 --- a/ergotree-ir/src/mir/constant.rs +++ b/ergotree-ir/src/mir/constant.rs @@ -88,6 +88,12 @@ impl std::fmt::Debug for Constant { } } +impl std::fmt::Display for Constant { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + self.v.fmt(f) + } +} + impl std::fmt::Debug for Literal { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { @@ -112,6 +118,63 @@ impl std::fmt::Debug for Literal { } } +impl std::fmt::Display for Literal { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + Literal::Coll(CollKind::NativeColl(NativeColl::CollByte(i8_bytes))) => { + write!(f, "Coll[Byte]("); + for (i, b) in i8_bytes.iter().enumerate() { + if i > 0 { + write!(f, ", ")?; + } + write!(f, "{}", b)?; + } + write!(f, ")") + } + Literal::Coll(CollKind::WrappedColl { elem_tpe, items }) => { + write!(f, "Coll[{}](", elem_tpe)?; + for (i, item) in items.iter().enumerate() { + if i > 0 { + write!(f, ", ")?; + } + item.fmt(f)?; + } + write!(f, ")") + } + Literal::Opt(boxed_opt) => { + if let Some(v) = &**boxed_opt { + write!(f, "Some(")?; + v.fmt(f)?; + write!(f, ")") + } else { + write!(f, "None") + } + } + Literal::Tup(items) => { + write!(f, "(")?; + for (i, item) in items.iter().enumerate() { + if i > 0 { + write!(f, ", ")?; + } + item.fmt(f)?; + } + write!(f, ")") + } + Literal::Unit => write!(f, "()"), + Literal::Boolean(v) => v.fmt(f), + Literal::Byte(v) => v.fmt(f), + Literal::Short(v) => v.fmt(f), + Literal::Int(v) => v.fmt(f), + Literal::Long(v) => write!(f, "{}L", v), + Literal::BigInt(v) => v.fmt(f), + Literal::SigmaProp(v) => v.fmt(f), + Literal::GroupElement(v) => v.fmt(f), + Literal::AvlTree(v) => v.fmt(f), + Literal::CBox(v) => v.fmt(f), + } + } +} + impl From<()> for Literal { fn from(_: ()) -> Literal { Literal::Unit