|
1 | 1 | use crate::protocol::{address::AztecAddress, traits::Serialize}; |
2 | 2 |
|
3 | | -/// A request for the `bulk_retrieve_logs` oracle to fetch either: |
4 | | -/// - a public log emitted by `contract_address` with `unsiloed_tag` |
5 | | -/// - a private log with tag equal to `compute_siloed_private_log_first_field(contract_address, unsiloed_tag)`. |
| 3 | +pub(crate) struct LogSourceEnum { |
| 4 | + pub PRIVATE: Field, |
| 5 | + pub PUBLIC: Field, |
| 6 | + pub PUBLIC_AND_PRIVATE: Field, |
| 7 | +} |
| 8 | + |
| 9 | +pub(crate) global LogSource: LogSourceEnum = |
| 10 | + LogSourceEnum { PRIVATE: 0, PUBLIC: 1, PUBLIC_AND_PRIVATE: 2 }; |
| 11 | + |
| 12 | +/// A request for the `bulk_retrieve_logs` oracle to fetch all logs matching a tag. |
6 | 13 | #[derive(Serialize)] |
7 | 14 | pub(crate) struct LogRetrievalRequest { |
8 | 15 | pub contract_address: AztecAddress, |
9 | 16 | pub unsiloed_tag: Field, |
10 | | - // TODO(#15052): choose source: public, private or either (current behavior) |
| 17 | + /// Which log source to query: public, private, or both (the default). See [`LogSource`]. |
| 18 | + pub source: Field, |
| 19 | + /// Inclusive lower bound on block number. When unset, logs from the first block are included. |
| 20 | + pub from_block: Option<Field>, |
| 21 | + /// Exclusive upper bound on block number. When unset, logs up to the anchor block are included. |
| 22 | + pub to_block: Option<Field>, |
| 23 | +} |
| 24 | + |
| 25 | +impl LogRetrievalRequest { |
| 26 | + /// Creates a request that queries both public and private logs with no block range filter. |
| 27 | + pub(crate) fn new(contract_address: AztecAddress, unsiloed_tag: Field) -> Self { |
| 28 | + LogRetrievalRequest { |
| 29 | + contract_address, |
| 30 | + unsiloed_tag, |
| 31 | + source: LogSource.PUBLIC_AND_PRIVATE, |
| 32 | + from_block: Option::none(), |
| 33 | + to_block: Option::none(), |
| 34 | + } |
| 35 | + } |
11 | 36 | } |
12 | 37 |
|
13 | 38 | mod test { |
14 | 39 | use crate::protocol::{address::AztecAddress, traits::{FromField, Serialize}}; |
15 | | - use super::LogRetrievalRequest; |
| 40 | + use super::{LogRetrievalRequest, LogSource}; |
| 41 | + |
| 42 | + #[test] |
| 43 | + fn serialization_of_defaults_matches_typescript() { |
| 44 | + let request = LogRetrievalRequest { |
| 45 | + contract_address: AztecAddress::from_field(1), |
| 46 | + unsiloed_tag: 2, |
| 47 | + source: LogSource.PUBLIC_AND_PRIVATE, |
| 48 | + from_block: Option::none(), |
| 49 | + to_block: Option::none(), |
| 50 | + }; |
| 51 | + |
| 52 | + // We define the serialization in Noir and the deserialization in TS. If the deserialization changes from |
| 53 | + // the snapshot value below, then log_retrieval_request.test.ts must be updated with the same value. |
| 54 | + // Ideally we'd autogenerate this, but for now we only have single-sided snapshot generation, from TS to |
| 55 | + // Noir, which is not what we need here. |
| 56 | + let expected_serialization = [ |
| 57 | + 0x0000000000000000000000000000000000000000000000000000000000000001, |
| 58 | + 0x0000000000000000000000000000000000000000000000000000000000000002, |
| 59 | + 0x0000000000000000000000000000000000000000000000000000000000000002, |
| 60 | + 0x0000000000000000000000000000000000000000000000000000000000000000, |
| 61 | + 0x0000000000000000000000000000000000000000000000000000000000000000, |
| 62 | + 0x0000000000000000000000000000000000000000000000000000000000000000, |
| 63 | + 0x0000000000000000000000000000000000000000000000000000000000000000, |
| 64 | + ]; |
| 65 | + |
| 66 | + assert_eq(request.serialize(), expected_serialization); |
| 67 | + } |
16 | 68 |
|
17 | 69 | #[test] |
18 | | - fn serialization_matches_typescript() { |
19 | | - let request = LogRetrievalRequest { contract_address: AztecAddress::from_field(1), unsiloed_tag: 2 }; |
| 70 | + fn serialization_with_values_matches_typescript() { |
| 71 | + let request = LogRetrievalRequest { |
| 72 | + contract_address: AztecAddress::from_field(1), |
| 73 | + unsiloed_tag: 2, |
| 74 | + source: LogSource.PUBLIC, |
| 75 | + from_block: Option::some(10), |
| 76 | + to_block: Option::some(20), |
| 77 | + }; |
20 | 78 |
|
21 | | - // We define the serialization in Noir and the deserialization in TS. If the deserialization changes from the |
22 | | - // snapshot value below, then log_retrieval_request.test.ts must be updated with the same value. Ideally we'd |
23 | | - // autogenerate this, but for now we only have single-sided snapshot generation, from TS to Noir, which is not |
24 | | - // what we need here. |
25 | 79 | let expected_serialization = [ |
26 | 80 | 0x0000000000000000000000000000000000000000000000000000000000000001, |
27 | 81 | 0x0000000000000000000000000000000000000000000000000000000000000002, |
| 82 | + 0x0000000000000000000000000000000000000000000000000000000000000001, |
| 83 | + 0x0000000000000000000000000000000000000000000000000000000000000001, |
| 84 | + 0x000000000000000000000000000000000000000000000000000000000000000a, |
| 85 | + 0x0000000000000000000000000000000000000000000000000000000000000001, |
| 86 | + 0x0000000000000000000000000000000000000000000000000000000000000014, |
28 | 87 | ]; |
29 | 88 |
|
30 | 89 | assert_eq(request.serialize(), expected_serialization); |
|
0 commit comments