Module note

Source
Expand description

Contains the Client APIs related to notes. Notes can contain assets and scripts that are executed as part of transactions.

This module enables the tracking, retrieval, and processing of notes. It offers methods to query input and output notes from the store, check their consumability, compile note scripts, and retrieve notes based on partial ID matching.

§Overview

The module exposes APIs to:

  • Retrieve input notes and output notes.
  • Determine the consumability of notes using the NoteScreener.
  • Compile note scripts from source code with compile_note_script.
  • Retrieve an input note by a prefix of its ID using the helper function get_input_note_with_id_prefix.

§Example

use miden_client::{
    Client,
    note::{get_input_note_with_id_prefix, NoteScreener},
    store::NoteFilter,
    crypto::FeltRng,
};
use miden_objects::account::AccountId;

// Retrieve all committed input notes
let input_notes = client.get_input_notes(NoteFilter::Committed).await?;
println!("Found {} committed input notes.", input_notes.len());

// Check consumability for a specific note
if let Some(note) = input_notes.first() {
    let consumability = client.get_note_consumability(note.clone()).await?;
    println!("Note consumability: {:?}", consumability);
}

// Retrieve an input note by a partial ID match
let note_prefix = "0x70b7ec";
match get_input_note_with_id_prefix(client, note_prefix).await {
    Ok(note) => println!("Found note with matching prefix: {}", note.id().to_hex()),
    Err(err) => println!("Error retrieving note: {:?}", err),
}

// Compile the note script
let script_src = "begin push.9 push.12 add end";
let note_script = client.compile_note_script(script_src)?;
println!("Compiled note script successfully.");

For more details on the API and error handling, see the documentation for the specific functions and types in this module.

Modules§

script_roots
Well-known note script roots. This file was generated by build.rs.
scripts
Contains functions to simplify standard note scripts creation.

Structs§

BlockNumber
A convenience wrapper around a u32 representing the number of a block.
Note
A note with all the data required for it to be consumed by executing it against the transaction kernel.
NoteAssets
An asset container for a note.
NoteId
Returns a unique identifier of a note, which is simultaneously a commitment to the note.
NoteInclusionProof
Contains the data required to prove inclusion of a note in the canonical chain.
NoteInputs
A container for note inputs.
NoteMetadata
Metadata associated with a note.
NoteRecipient
Value that describes under which condition a note can be consumed.
NoteScreener
Provides functionality for testing whether a note is relevant to the client or not.
NoteScript
An executable program of a note.
NoteTag
NoteTag`s are best effort filters for notes registered with the network.
NoteUpdates
Contains note changes to apply to the store.
Nullifier
A note’s nullifier.

Enums§

NoteError
NoteExecutionHint
Specifies the conditions under which a note is ready to be consumed. These conditions are meant to be encoded in the note script as well.
NoteExecutionMode
super::Note’s execution mode hints.
NoteFile
A serialized representation of a note.
NoteRelevance
Describes the relevance of a note based on the screening.
NoteScreenerError
Error when screening notes to check relevance to a client.
NoteType

Functions§

build_p2id_recipient
Creates a NoteRecipient for the P2ID note.
build_swap_tag
Returns a note tag for a swap note with the specified parameters.
create_p2id_note
Generates a P2ID note - pay to id note.
create_p2idr_note
Generates a P2IDR note - pay to id with recall after a certain block height.
create_swap_note
Generates a SWAP note - swap of assets between two accounts - and returns the note as well as NoteDetails for the payback note.
get_input_note_with_id_prefix
Returns the client input note whose ID starts with note_id_prefix.

Type Aliases§

NoteConsumability
Represents the consumability of a note by a specific account.