Skip to content

Commit

Permalink
Merge pull request #74 from ergoplatform/add-ge-contstant-ser
Browse files Browse the repository at this point in the history
Add Constant::GroupElement implementation along with serialization;
  • Loading branch information
greenhat committed Jul 29, 2020
2 parents 4cfc894 + e34279d commit b95dcfa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 19 additions & 1 deletion sigma-tree/src/ast/constant.rs
@@ -1,6 +1,7 @@
use crate::chain::{Base16DecodedBytes, Base16EncodedBytes};
use crate::{
chain::ErgoBox,
ecpoint::EcPoint,
sigma_protocol::SigmaProp,
types::{LiftIntoSType, SType},
};
Expand Down Expand Up @@ -66,7 +67,7 @@ pub enum ConstantVal {
/// Big integer
BigInt,
/// GroupElement
GroupElement,
GroupElement(Box<EcPoint>),
/// Sigma property
SigmaProp(Box<SigmaProp>),
/// Box
Expand Down Expand Up @@ -211,6 +212,21 @@ impl Into<Constant> for SigmaProp {
}
}

impl Into<ConstantVal> for EcPoint {
fn into(self) -> ConstantVal {
ConstantVal::GroupElement(Box::new(self))
}
}

impl Into<Constant> for EcPoint {
fn into(self) -> Constant {
Constant {
tpe: SType::SGroupElement,
v: self.into(),
}
}
}

/// Marker trait to select types for which CollElems::NonPrimitive is used to store elements as Vec<ConstantVal>
pub trait StoredNonPrimitive {}

Expand Down Expand Up @@ -263,6 +279,8 @@ mod tests {
any::<i16>().prop_map_into(),
any::<i32>().prop_map_into(),
any::<i64>().prop_map_into(),
any::<EcPoint>().prop_map_into(),
any::<SigmaProp>().prop_map_into(),
(vec(any::<i8>(), 0..100)).prop_map_into(),
(vec(any::<i16>(), 0..100)).prop_map_into(),
(vec(any::<i32>(), 0..100)).prop_map_into(),
Expand Down
4 changes: 3 additions & 1 deletion sigma-tree/src/serialization/data.rs
Expand Up @@ -2,6 +2,7 @@ use crate::{
ast::ConstantVal,
ast::ConstantVal::*,
ast::{CollPrim, ConstantColl},
ecpoint::EcPoint,
sigma_protocol,
types::SType,
types::SType::*,
Expand All @@ -28,7 +29,7 @@ impl DataSerializer {
Int(v) => w.put_i32(*v),
Long(v) => w.put_i64(*v),
BigInt => todo!(),
GroupElement => todo!(),
GroupElement(ecp) => ecp.sigma_serialize(w),
SigmaProp(s) => s.value().sigma_serialize(w),
CBox(_) => todo!(),
AvlTree => todo!(),
Expand Down Expand Up @@ -59,6 +60,7 @@ impl DataSerializer {
SShort => Short(r.get_i16()?),
SInt => Int(r.get_i32()?),
SLong => Long(r.get_i64()?),
SGroupElement => GroupElement(Box::new(EcPoint::sigma_parse(r)?)),
SSigmaProp => ConstantVal::sigma_prop(SigmaProp::new(SigmaBoolean::sigma_parse(r)?)),
SColl(elem_type) if **elem_type == SByte => {
let len = r.get_u16()? as usize;
Expand Down

0 comments on commit b95dcfa

Please sign in to comment.