allow SELF in st_tmpl (#240)
* allow SELF in st_tmpl * add some tests * Update src/backends/plonky2/circuits/mainpod.rs Co-authored-by: Ahmad Afuni <root@ahmadafuni.com> --------- Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
This commit is contained in:
parent
b4a4c72328
commit
82481e88d7
9 changed files with 178 additions and 87 deletions
|
|
@ -7,7 +7,8 @@ use crate::{
|
|||
frontend::{AnchoredKey, Error, Result, Statement, StatementArg},
|
||||
middleware::{
|
||||
self, hash_str, CustomPredicate, CustomPredicateBatch, Key, KeyOrWildcard, NativePredicate,
|
||||
Params, PodId, Predicate, StatementTmpl, StatementTmplArg, ToFields, Value, Wildcard,
|
||||
Params, PodId, Predicate, SelfOrWildcard, StatementTmpl, StatementTmplArg, ToFields, Value,
|
||||
Wildcard,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -18,6 +19,12 @@ pub enum KeyOrWildcardStr {
|
|||
Wildcard(String),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum SelfOrWildcardStr {
|
||||
SELF,
|
||||
Wildcard(String),
|
||||
}
|
||||
|
||||
/// helper to build a literal KeyOrWildcardStr::Key from the given str
|
||||
pub fn key(s: &str) -> KeyOrWildcardStr {
|
||||
KeyOrWildcardStr::Key(s.to_string())
|
||||
|
|
@ -27,11 +34,21 @@ pub fn key(s: &str) -> KeyOrWildcardStr {
|
|||
#[derive(Clone)]
|
||||
pub enum BuilderArg {
|
||||
Literal(Value),
|
||||
/// Key: (origin, key), where origin is a Wildcard and key can be both Key or Wildcard
|
||||
Key(String, KeyOrWildcardStr),
|
||||
/// Key: (origin, key), where origin is SELF or Wildcard and key is Key or Wildcard
|
||||
Key(SelfOrWildcardStr, KeyOrWildcardStr),
|
||||
WildcardLiteral(String),
|
||||
}
|
||||
|
||||
impl From<&str> for SelfOrWildcardStr {
|
||||
fn from(origin: &str) -> Self {
|
||||
if origin == "SELF" {
|
||||
SelfOrWildcardStr::SELF
|
||||
} else {
|
||||
SelfOrWildcardStr::Wildcard(origin.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// When defining a `BuilderArg`, it can be done from 3 different inputs:
|
||||
/// i. (&str, literal): this is to set a POD and a field, ie. (POD, literal("field"))
|
||||
/// ii. (&str, &str): this is to define a origin-key wildcard pair, ie. (src_origin, src_dest)
|
||||
|
|
@ -40,11 +57,6 @@ pub enum BuilderArg {
|
|||
/// case i.
|
||||
impl From<(&str, KeyOrWildcardStr)> for BuilderArg {
|
||||
fn from((origin, lit): (&str, KeyOrWildcardStr)) -> Self {
|
||||
// ensure that `lit` is of HashOrWildcardStr::Hash type
|
||||
match lit {
|
||||
KeyOrWildcardStr::Key(_) => (),
|
||||
_ => panic!("not supported"),
|
||||
};
|
||||
Self::Key(origin.into(), lit)
|
||||
}
|
||||
}
|
||||
|
|
@ -197,7 +209,7 @@ impl CustomPredicateBatchBuilder {
|
|||
.map(|a| match a {
|
||||
BuilderArg::Literal(v) => StatementTmplArg::Literal(v.clone()),
|
||||
BuilderArg::Key(pod_id, key) => StatementTmplArg::AnchoredKey(
|
||||
resolve_wildcard(args, priv_args, pod_id),
|
||||
resolve_self_or_wildcard(args, priv_args, pod_id),
|
||||
resolve_key_or_wildcard(args, priv_args, key),
|
||||
),
|
||||
BuilderArg::WildcardLiteral(v) => {
|
||||
|
|
@ -227,6 +239,19 @@ impl CustomPredicateBatchBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
fn resolve_self_or_wildcard(
|
||||
args: &[&str],
|
||||
priv_args: &[&str],
|
||||
v: &SelfOrWildcardStr,
|
||||
) -> SelfOrWildcard {
|
||||
match v {
|
||||
SelfOrWildcardStr::SELF => SelfOrWildcard::SELF,
|
||||
SelfOrWildcardStr::Wildcard(s) => {
|
||||
SelfOrWildcard::Wildcard(resolve_wildcard(args, priv_args, s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_key_or_wildcard(
|
||||
args: &[&str],
|
||||
priv_args: &[&str],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue