Selaa lähdekoodia

Small refactor of collect_cind_points

Ian Goldberg 3 kuukautta sitten
vanhempi
commit
c2c275dfb1

+ 3 - 18
sigma_compiler_core/src/notequals.rs

@@ -16,9 +16,9 @@ use super::pedersen::{
 };
 use super::sigma::combiners::*;
 use super::sigma::types::{expr_type_tokens, VarDict};
-use super::syntax::taggedvardict_to_vardict;
+use super::syntax::{collect_cind_points, taggedvardict_to_vardict};
 use super::transform::paren_if_needed;
-use super::{TaggedIdent, TaggedPoint, TaggedVarDict};
+use super::TaggedVarDict;
 use quote::{format_ident, quote};
 use std::collections::HashMap;
 use syn::{parse_quote, Error, Expr, Ident, Result};
@@ -93,22 +93,7 @@ pub fn transform(
     // the macro input.  There must be at least two of them in order to
     // handle not-equals statements, so that we can make Pedersen
     // commitments.
-    let cind_points: Vec<Ident> = vars
-        .values()
-        .filter_map(|ti| {
-            if let TaggedIdent::Point(TaggedPoint {
-                is_cind: true,
-                is_vec: false,
-                id,
-                ..
-            }) = ti
-            {
-                Some(id.clone())
-            } else {
-                None
-            }
-        })
-        .collect();
+    let cind_points = collect_cind_points(vars);
 
     // Find any statements that look like Pedersen commitments in the
     // StatementTree, and make a HashMap mapping the committed private

+ 3 - 18
sigma_compiler_core/src/rangeproof.rs

@@ -26,9 +26,9 @@ use super::pedersen::{
 };
 use super::sigma::combiners::*;
 use super::sigma::types::{expr_type_tokens, VarDict};
-use super::syntax::taggedvardict_to_vardict;
+use super::syntax::{collect_cind_points, taggedvardict_to_vardict};
 use super::transform::paren_if_needed;
-use super::{TaggedIdent, TaggedPoint, TaggedVarDict};
+use super::TaggedVarDict;
 use quote::{format_ident, quote};
 use std::collections::HashMap;
 use syn::{parse_quote, Error, Expr, Ident, Result};
@@ -210,22 +210,7 @@ pub fn transform(
     // the macro input.  There must be at least two of them in order to
     // handle range statements, so that we can make Pedersen
     // commitments.
-    let cind_points: Vec<Ident> = vars
-        .values()
-        .filter_map(|ti| {
-            if let TaggedIdent::Point(TaggedPoint {
-                is_cind: true,
-                is_vec: false,
-                id,
-                ..
-            }) = ti
-            {
-                Some(id.clone())
-            } else {
-                None
-            }
-        })
-        .collect();
+    let cind_points = collect_cind_points(vars);
 
     // Find any statements that look like Pedersen commitments in the
     // StatementTree, and make a HashMap mapping the committed private

+ 20 - 0
sigma_compiler_core/src/syntax.rs

@@ -157,6 +157,26 @@ pub fn taggedvardict_to_vardict(vd: &TaggedVarDict) -> VarDict {
         .collect()
 }
 
+/// Collect the list of [`Point`](TaggedIdent::Point)s tagged `cind`
+/// from the given [`TaggedVarDict`]
+pub fn collect_cind_points(vars: &TaggedVarDict) -> Vec<Ident> {
+    vars.values()
+        .filter_map(|ti| {
+            if let TaggedIdent::Point(TaggedPoint {
+                is_cind: true,
+                is_vec: false,
+                id,
+                ..
+            }) = ti
+            {
+                Some(id.clone())
+            } else {
+                None
+            }
+        })
+        .collect()
+}
+
 #[cfg(test)]
 /// Convert a list of strings describing `Scalar`s and a list of strings
 /// describing `Point`s into a [`TaggedVarDict`]