From 6dc4157a9fb1e469556cfe3d2697c77f5ed2cd4d Mon Sep 17 00:00:00 2001 From: Josh Crites Date: Thu, 19 Oct 2023 12:05:08 -0400 Subject: [PATCH 1/2] add view note --- docs/docs/dev_docs/contracts/syntax/storage.md | 6 ++++++ yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr | 2 ++ 2 files changed, 8 insertions(+) diff --git a/docs/docs/dev_docs/contracts/syntax/storage.md b/docs/docs/dev_docs/contracts/syntax/storage.md index 77ae0b61338..e0b123d4819 100644 --- a/docs/docs/dev_docs/contracts/syntax/storage.md +++ b/docs/docs/dev_docs/contracts/syntax/storage.md @@ -317,6 +317,12 @@ However, it's possible that at the time this function is called, the system hasn #include_code state_vars-SingletonGet /yarn-project/noir-contracts/src/contracts/docs_example_contract/src/actions.nr rust +### `view_note` + +Functionally similar to [`get_note`](#get_note), but executed unconstrained and can be used by the wallet to fetch notes for use by front-ends etc. + +#include_code view_note /yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr rust + ## `ImmutableSingleton` ImmutableSingleton represents a unique private state variable that, as the name suggests, is immutable. Once initialized, its value cannot be altered. diff --git a/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr b/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr index d1ce9e44593..9d13156a4c0 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr @@ -104,8 +104,10 @@ impl Singleton { } // docs:end:get_note + // docs:start:view_note unconstrained pub fn view_note(self) -> Note { let options = NoteViewerOptions::new().set_limit(1); view_notes(self.storage_slot, self.note_interface, options)[0].unwrap() } + // docs:end:view_note } From 44fae1cbd782d1e96b256f5305428c57b1b2e448 Mon Sep 17 00:00:00 2001 From: Josh Crites Date: Thu, 19 Oct 2023 20:35:16 -0400 Subject: [PATCH 2/2] immutable singleton view note --- docs/docs/dev_docs/contracts/syntax/storage.md | 6 ++++++ .../aztec-nr/aztec/src/state_vars/immutable_singleton.nr | 2 ++ 2 files changed, 8 insertions(+) diff --git a/docs/docs/dev_docs/contracts/syntax/storage.md b/docs/docs/dev_docs/contracts/syntax/storage.md index e0b123d4819..fa97daf5f73 100644 --- a/docs/docs/dev_docs/contracts/syntax/storage.md +++ b/docs/docs/dev_docs/contracts/syntax/storage.md @@ -369,6 +369,12 @@ Unlike a [`singleton`](#get_note-1), the `get_note` function for an ImmutableSin This function will throw if the ImmutableSingleton hasn't been initialized. +### `view_note` + +Functionally similar to `get_note`, but executed unconstrained and can be used by the wallet to fetch notes for use by front-ends etc. + +#include_code view_note /yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr rust + ## `Set` Set is used for managing a collection of notes. All notes in a set are of the same `NoteType`. But whether these notes all belong to one entity, or are accessible and editable by different entities, is totally up to the developer. Due to our state model, the set is a collection of notes inserted into the data-tree, but notes are never removed from the tree itself, they are only nullified. diff --git a/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr b/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr index 0dad78df1c6..d1ad96565d2 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr @@ -70,8 +70,10 @@ impl ImmutableSingleton { } // docs:end:get_note + // docs:start:view_note unconstrained pub fn view_note(self) -> Note { let options = NoteViewerOptions::new().set_limit(1); view_notes(self.storage_slot, self.note_interface, options)[0].unwrap() } + // docs:end:view_note }