@@ -30,6 +30,82 @@ macro_rules! process_inputs {
3030 } } ;
3131}
3232
33+ #[ macro_export]
34+ macro_rules! authorize {
35+ (
36+ $process: expr,
37+ $inputs: expr,
38+ $program_string: expr,
39+ $function_id_string: expr,
40+ $private_key: expr,
41+ $rng: expr
42+ ) => { {
43+ log( "Loading program" ) ;
44+ let program =
45+ ProgramNative :: from_str( $program_string) . map_err( |_| "The program ID provided was invalid" . to_string( ) ) ?;
46+ log( "Loading function" ) ;
47+ let function_name = IdentifierNative :: from_str( $function_id_string)
48+ . map_err( |_| "The function name provided was invalid" . to_string( ) ) ?;
49+
50+ let program_id = program. id( ) . to_string( ) ;
51+
52+ if program_id != "credits.aleo" {
53+ if !$process. contains_program( program. id( ) ) {
54+ log( "Adding program to the process" ) ;
55+ $process. add_program( & program) . map_err( |e| e. to_string( ) ) ?;
56+ }
57+ }
58+
59+ log( & format!( "Creating authorization for {program_id}:{function_name}" ) ) ;
60+ $process
61+ . authorize:: <CurrentAleo , _>( $private_key, program. id( ) , function_name, $inputs. iter( ) , $rng)
62+ . map_err( |err| err. to_string( ) ) ?
63+ } } ;
64+ }
65+
66+ #[ macro_export]
67+ macro_rules! authorize_fee {
68+ (
69+ $process: expr,
70+ $private_key: expr,
71+ $deployment_or_execution_id: expr,
72+ $base_fee: expr,
73+ $priority_fee: expr,
74+ $fee_record: expr,
75+ $rng: expr
76+ ) => { {
77+ match $fee_record {
78+ Some ( fee_record) => {
79+ log( "Authorizing credits.aleo/fee_private" ) ;
80+ let fee_record_native = RecordPlaintextNative :: from_str( & fee_record. to_string( ) )
81+ . map_err( |e| format!( "Invalid fee record: {}" , e) ) ?;
82+ $process
83+ . authorize_fee_private:: <CurrentAleo , _>(
84+ $private_key,
85+ fee_record_native,
86+ $base_fee,
87+ $priority_fee,
88+ $deployment_or_execution_id,
89+ $rng,
90+ )
91+ . map_err( |e| e. to_string( ) ) ?
92+ }
93+ None => {
94+ log( "Authorizing credits.aleo/fee_public" ) ;
95+ $process
96+ . authorize_fee_public:: <CurrentAleo , _>(
97+ $private_key,
98+ $base_fee,
99+ $priority_fee,
100+ $deployment_or_execution_id,
101+ $rng,
102+ )
103+ . map_err( |e| e. to_string( ) ) ?
104+ }
105+ }
106+ } } ;
107+ }
108+
33109#[ macro_export]
34110macro_rules! execute_program {
35111 ( $process: expr, $inputs: expr, $program_string: expr, $function_id_string: expr, $private_key: expr, $proving_key: expr, $verifying_key: expr, $rng: expr) => { {
@@ -52,12 +128,8 @@ macro_rules! execute_program {
52128 let program_id = program. id( ) . to_string( ) ;
53129
54130 if program_id != "credits.aleo" {
55- log( "Adding program to the process" ) ;
56- if let Ok ( stored_program) = $process. get_program( program. id( ) ) {
57- if stored_program != & program {
58- return Err ( "The program provided does not match the program stored in the cache, please clear the cache before proceeding" . to_string( ) ) ;
59- }
60- } else {
131+ if !$process. contains_program( program. id( ) ) {
132+ log( "Adding program to the process" ) ;
61133 $process. add_program( & program) . map_err( |e| e. to_string( ) ) ?;
62134 }
63135 }
@@ -98,7 +170,7 @@ macro_rules! execute_program {
98170
99171#[ macro_export]
100172macro_rules! execute_fee {
101- ( $process: expr, $private_key: expr, $fee_record: expr, $priority_fee_microcredits: expr, $submission_url: expr, $fee_proving_key: expr, $fee_verifying_key: expr, $execution_id : expr, $rng: expr, $offline_query: expr, $minimum_execution_cost: expr) => { {
173+ ( $process: expr, $private_key: expr, $fee_record: expr, $priority_fee_microcredits: expr, $submission_url: expr, $fee_proving_key: expr, $fee_verifying_key: expr, $deployment_or_execution_id : expr, $rng: expr, $offline_query: expr, $minimum_execution_cost: expr) => { {
102174 if ( ( $fee_proving_key. is_some( ) && $fee_verifying_key. is_none( ) )
103175 || ( $fee_proving_key. is_none( ) && $fee_verifying_key. is_some( ) ) )
104176 {
@@ -138,7 +210,7 @@ macro_rules! execute_fee {
138210 fee_record_native,
139211 $minimum_execution_cost,
140212 $priority_fee_microcredits,
141- $execution_id ,
213+ $deployment_or_execution_id ,
142214 $rng,
143215 ) . map_err( |e| e. to_string( ) ) ?
144216 }
@@ -147,7 +219,7 @@ macro_rules! execute_fee {
147219 $private_key,
148220 $minimum_execution_cost,
149221 $priority_fee_microcredits,
150- $execution_id ,
222+ $deployment_or_execution_id ,
151223 $rng,
152224 ) . map_err( |e| e. to_string( ) ) ?
153225 }
@@ -168,7 +240,7 @@ macro_rules! execute_fee {
168240 let fee = trace. prove_fee:: <CurrentAleo , _>( VarunaVersion :: V2 , & mut StdRng :: from_entropy( ) ) . map_err( |e|e. to_string( ) ) ?;
169241
170242 log( "Verifying fee execution" ) ;
171- $process. verify_fee( VarunaVersion :: V2 , & fee, $execution_id ) . map_err( |e| e. to_string( ) ) ?;
243+ $process. verify_fee( VarunaVersion :: V2 , & fee, $deployment_or_execution_id ) . map_err( |e| e. to_string( ) ) ?;
172244
173245 fee
174246 } }
@@ -194,4 +266,4 @@ macro_rules! calculate_minimum_fee {
194266
195267 minimum_execution_cost
196268 } } ;
197- }
269+ }
0 commit comments