Struct SinglePrivateImmutable
pub struct SinglePrivateImmutable<Note, Context>
{ /* private fields */ }
Implementations
impl<Note> SinglePrivateImmutable<Note, UtilityContext>
pub unconstrained fn is_initialized(self) -> bool
Returns whether this SinglePrivateImmutable has been initialized.
pub unconstrained fn view_note(self) -> Note
Returns the permanent note in this SinglePrivateImmutable state variable instance.
impl<Note> SinglePrivateImmutable<Note, &mut PrivateContext>
pub fn initialize(self, note: Note) -> NoteMessage<Note>
Initializes a SinglePrivateImmutable state variable instance with a permanent note and returns a
NoteMessage that allows you to decide what method of note message delivery to use.
This function inserts the single, permanent note for this state variable. It can only be called once per SinglePrivateImmutable. Subsequent calls will fail because the initialization nullifier will already exist.
pub fn get_note(self) -> Note
Reads the permanent note of a SinglePrivateImmutable state variable instance.
If this SinglePrivateImmutable state variable has not yet been initialized, no note will exist: the call will fail and the transaction will not be provable.
Since the note is immutable, there's no risk of reading stale data or race conditions - the note never changes after initialization.
A state variable that holds a single private value that is set once and remains unchanged forever (unlike crate::state_vars::private_immutable::PrivateImmutable, which holds one private value per account - hence the name 'single').
Because this private value has no semantic owner, it is up to the application to determine which accounts will learn of its existence via crate::note::note_message::NoteMessage::deliver_to.
Usage
Unlike crate::state_vars::private_immutable::PrivateImmutable which is "owned" (requiring wrapping in an crate::state_vars::owned::Owned state variable), SinglePrivateImmutable is used directly in storage:
Example
A contract's configuration parameters can be represented as a SinglePrivateImmutable. Once set during contract deployment or initial setup, these parameters remain constant for the lifetime of the contract. For example, an account contract's signing public key is typically stored using SinglePrivateImmutable. Note that the configuration would be visible only to the parties to which the NoteMessage returned from the
initialize(...)function is delivered.Requirements
The contract that holds this state variable must have keys associated with it. This is because the initialization nullifier includes the contract's nullifying secret key (nsk) in its preimage and because the contract is set as the owner of the underlying note. This is expected to not ever be a problem because the contracts that use SinglePrivateImmutable generally have keys associated with them (account contracts or escrow contracts).