11#![ allow( unused) ]
2+ use anyhow:: Result ;
23use std:: sync:: Arc ;
34
45use crate :: middleware:: {
5- hash_str, CustomPredicate , CustomPredicateBatch , Hash , HashOrWildcard , NativePredicate ,
6+ hash_str, CustomPredicate , CustomPredicateBatch , Hash , HashOrWildcard , NativePredicate , Params ,
67 Predicate , StatementTmpl , StatementTmplArg , ToFields , Value , F ,
78} ;
89
@@ -96,31 +97,34 @@ impl CustomPredicateBatchBuilder {
9697
9798 fn predicate_and (
9899 & mut self ,
100+ params : & Params ,
99101 args : & [ & str ] ,
100102 priv_args : & [ & str ] ,
101103 sts : & [ StatementTmplBuilder ] ,
102- ) -> Predicate {
103- self . predicate ( true , args, priv_args, sts)
104+ ) -> Result < Predicate > {
105+ self . predicate ( params , true , args, priv_args, sts)
104106 }
105107
106108 fn predicate_or (
107109 & mut self ,
110+ params : & Params ,
108111 args : & [ & str ] ,
109112 priv_args : & [ & str ] ,
110113 sts : & [ StatementTmplBuilder ] ,
111- ) -> Predicate {
112- self . predicate ( false , args, priv_args, sts)
114+ ) -> Result < Predicate > {
115+ self . predicate ( params , false , args, priv_args, sts)
113116 }
114117
115118 /// creates the custom predicate from the given input, adds it to the
116119 /// self.predicates, and returns the index of the created predicate
117120 fn predicate (
118121 & mut self ,
122+ params : & Params ,
119123 conjunction : bool ,
120124 args : & [ & str ] ,
121125 priv_args : & [ & str ] ,
122126 sts : & [ StatementTmplBuilder ] ,
123- ) -> Predicate {
127+ ) -> Result < Predicate > {
124128 let statements = sts
125129 . iter ( )
126130 . map ( |sb| {
@@ -138,13 +142,9 @@ impl CustomPredicateBatchBuilder {
138142 StatementTmpl ( sb. predicate . clone ( ) , args)
139143 } )
140144 . collect ( ) ;
141- let custom_predicate = CustomPredicate {
142- conjunction,
143- statements,
144- args_len : args. len ( ) ,
145- } ;
145+ let custom_predicate = CustomPredicate :: new ( params, conjunction, statements, args. len ( ) ) ?;
146146 self . predicates . push ( custom_predicate) ;
147- Predicate :: BatchSelf ( self . predicates . len ( ) - 1 )
147+ Ok ( Predicate :: BatchSelf ( self . predicates . len ( ) - 1 ) )
148148 }
149149
150150 fn finish ( self ) -> Arc < CustomPredicateBatch > {
@@ -174,7 +174,7 @@ mod tests {
174174 use crate :: middleware:: { CustomPredicateRef , Params , PodType } ;
175175
176176 #[ test]
177- fn test_custom_pred ( ) {
177+ fn test_custom_pred ( ) -> Result < ( ) > {
178178 use NativePredicate as NP ;
179179 use StatementTmplBuilder as STB ;
180180
@@ -183,6 +183,7 @@ mod tests {
183183
184184 let mut builder = CustomPredicateBatchBuilder :: new ( "eth_friend" . into ( ) ) ;
185185 let _eth_friend = builder. predicate_and (
186+ & params,
186187 // arguments:
187188 & [ "src_ori" , "src_key" , "dst_ori" , "dst_key" ] ,
188189 // private arguments:
@@ -202,7 +203,7 @@ mod tests {
202203 . arg ( ( "attestation_pod" , literal ( "attestation" ) ) )
203204 . arg ( ( "dst_ori" , "dst_key" ) ) ,
204205 ] ,
205- ) ;
206+ ) ? ;
206207
207208 println ! ( "a.0. eth_friend = {}" , builder. predicates. last( ) . unwrap( ) ) ;
208209 let eth_friend = builder. finish ( ) ;
@@ -216,6 +217,7 @@ mod tests {
216217 // >
217218 let mut builder = CustomPredicateBatchBuilder :: new ( "eth_dos_distance_base" . into ( ) ) ;
218219 let eth_dos_distance_base = builder. predicate_and (
220+ & params,
219221 & [
220222 // arguments:
221223 "src_ori" ,
@@ -236,7 +238,7 @@ mod tests {
236238 . arg ( ( "distance_ori" , "distance_key" ) )
237239 . arg ( 0 ) ,
238240 ] ,
239- ) ;
241+ ) ? ;
240242 println ! (
241243 "b.0. eth_dos_distance_base = {}" ,
242244 builder. predicates. last( ) . unwrap( )
@@ -246,6 +248,7 @@ mod tests {
246248
247249 // next chunk builds:
248250 let eth_dos_distance_ind = builder. predicate_and (
251+ & params,
249252 & [
250253 // arguments:
251254 "src_ori" ,
@@ -281,14 +284,15 @@ mod tests {
281284 . arg ( ( "intermed_ori" , "intermed_key" ) )
282285 . arg ( ( "dst_ori" , "dst_key" ) ) ,
283286 ] ,
284- ) ;
287+ ) ? ;
285288
286289 println ! (
287290 "b.1. eth_dos_distance_ind = {}" ,
288291 builder. predicates. last( ) . unwrap( )
289292 ) ;
290293
291294 let _eth_dos_distance = builder. predicate_or (
295+ & params,
292296 & [
293297 "src_ori" ,
294298 "src_key" ,
@@ -308,7 +312,7 @@ mod tests {
308312 . arg ( ( "dst_ori" , "dst_key" ) )
309313 . arg ( ( "distance_ori" , "distance_key" ) ) ,
310314 ] ,
311- ) ;
315+ ) ? ;
312316
313317 println ! (
314318 "b.2. eth_dos_distance = {}" ,
@@ -318,5 +322,7 @@ mod tests {
318322 let eth_dos_batch_b = builder. finish ( ) ;
319323 let fields = eth_dos_batch_b. to_fields ( & params) ;
320324 println ! ( "Batch b, serialized: {:?}" , fields) ;
325+
326+ Ok ( ( ) )
321327 }
322328}
0 commit comments