pub enum NoteTag {
NetworkAccount(u32),
NetworkUseCase(u16, u16),
LocalPublicAny(u32),
LocalAny(u32),
}
Expand description
NoteTag`s are best effort filters for notes registered with the network.
Tags are light-weight values used to speed up queries. The 2 most significant bits of the tags have the following interpretation:
Prefix | Name | NoteExecutionMode | Target | Allowed NoteType |
---|---|---|---|---|
0b00 | NetworkAccount | Network | Network Account | NoteType::Public |
0b01 | NetworkUseCase | Network | Use case | NoteType::Public |
0b10 | LocalPublicAny | Local | Any | NoteType::Public |
0b11 | LocalAny | Local | Any | Any |
Where:
NoteExecutionMode
is set toNoteExecutionMode::Network
to hint aNote
should be consumed by the network. These notes will be further validated and if possible consumed by it.- Target describes how to further interpret the bits in the tag.
- For tags with a specific target, the rest of the tag is interpreted as a partial
AccountId
. For network accounts these are the first 30 bits of the ID while for local account targets, the first 14 bits are used - a trade-off between privacy and uniqueness. - For use case values, the meaning of the rest of the tag is not specified by the protocol and can be used by applications built on top of the rollup.
- For tags with a specific target, the rest of the tag is interpreted as a partial
The note type is the only value enforced by the protocol. The rationale is that any note intended to be consumed by the network must be public to have all the details available. The public note for local execution is intended to allow users to search for notes that can be consumed right away, without requiring an off-band communication channel.
Note on Type Safety
Each enum variant contains the raw encoding of the note tag, where the first two bits
should correspond to the variant’s prefix (as defined in the table above). However, because
enum variants are always public, it is possible to instantiate this enum where this invariant
does not hold, e.g. NoteTag::NetworkAccount(0b11...)
. For that reason, the enum variants
should take precedence in case of such a mismatch and the inner value should not be accessed
directly. Instead, only rely on NoteTag::as_u32
to access the encoded value, which will
always return the correct value.
Variants§
NetworkAccount(u32)
Represents a tag for a note intended for network execution, targeted at a network account. The note must be public.
NetworkUseCase(u16, u16)
Represents a tag for a note intended for network execution for a public use case. The note must be public.
LocalPublicAny(u32)
Represents a tag for a note intended for local execution.
This is used for two purposes:
- A public use case.
- A note targeted at any type of account.
In all cases, the note must be public.
LocalAny(u32)
Represents a tag for a note intended for local execution.
This is used for two purposes:
- A private use case.
- A note targeted at any type of account.
In all cases, the note can be of any type.
Implementations§
Source§impl NoteTag
impl NoteTag
Sourcepub fn from_account_id(account_id: AccountId) -> Self
pub fn from_account_id(account_id: AccountId) -> Self
Returns a new NoteTag::NetworkAccount or NoteTag::LocalAny instantiated from the specified account ID.
The tag is constructed as follows:
- For local execution (
AccountStorageMode::Private
orAccountStorageMode::Public
), the two most significant bits are set to0b11
, which allows for any note type to be used. The following 14 bits are set to the most significant bits of the account ID, and the remaining 16 bits are set to 0. - For network execution (
AccountStorageMode::Network
), the most significant bits are set to0b00
and the remaining bits are set to the 30 most significant bits of the account ID.
Sourcepub fn for_public_use_case(
use_case_id: u16,
payload: u16,
execution: NoteExecutionMode,
) -> Result<Self, NoteError>
pub fn for_public_use_case( use_case_id: u16, payload: u16, execution: NoteExecutionMode, ) -> Result<Self, NoteError>
Returns a new NoteTag::NetworkUseCase
or NoteTag::LocalPublicAny
instantiated for a custom use case which requires a public note.
The public use_case tag requires a NoteType::Public note.
The two high bits are set to the b10
or b01
depending on the execution hint, the next 14
bits are set to the use_case_id
, and the low 16 bits are set to payload
.
§Errors
- If
use_case_id
is larger than or equal to $2^{14}$.
Sourcepub fn for_local_use_case(
use_case_id: u16,
payload: u16,
) -> Result<Self, NoteError>
pub fn for_local_use_case( use_case_id: u16, payload: u16, ) -> Result<Self, NoteError>
Returns a new NoteTag::LocalAny
instantiated for a custom local use case.
The local use_case tag is the only tag type that allows for NoteType::Private notes.
The two high bits are set to the b11
, the next 14 bits are set to the use_case_id
, and
the low 16 bits are set to payload
.
§Errors
- If
use_case_id
is larger than or equal to 2^14.
Sourcepub fn is_single_target(&self) -> bool
pub fn is_single_target(&self) -> bool
Returns true if the note is intended for execution by a specific account, i.e.
NoteTag::NetworkAccount
Sourcepub fn execution_mode(&self) -> NoteExecutionMode
pub fn execution_mode(&self) -> NoteExecutionMode
Returns note execution mode defined by this tag.
If the most significant bit of the tag is 0 the note is intended for local execution; otherwise, the note is intended for network execution.
Trait Implementations§
Source§impl Deserializable for NoteTag
impl Deserializable for NoteTag
Source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
source
, attempts to deserialize these bytes
into Self
, and returns the result. Read moreSource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
Source§impl Ord for NoteTag
impl Ord for NoteTag
Source§impl PartialOrd for NoteTag
impl PartialOrd for NoteTag
Source§impl Serializable for NoteTag
impl Serializable for NoteTag
Source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
self
into bytes and writes these bytes into the target
.Source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
impl Copy for NoteTag
impl Eq for NoteTag
impl StructuralPartialEq for NoteTag
Auto Trait Implementations§
impl Freeze for NoteTag
impl RefUnwindSafe for NoteTag
impl Send for NoteTag
impl Sync for NoteTag
impl Unpin for NoteTag
impl UnwindSafe for NoteTag
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more