Expand description
§Schema Module
The schema
module provides macros for constructing and organizing transaction schemas
in a hierarchical manner. These macros are designed to simplify the creation of complex
transaction structures by allowing inline specification of schema elements, which represent instructions
within transactions.
§Overview
This module includes two primary macros:
schema!
: The main macro for constructing aTransactionSchema
, which is a hierarchical schema representation.schema_inner!
: A helper macro, used internally byschema!
for recursive schema node construction.
Together, these macros enable you to define schema nodes in a flexible and intuitive manner,
allowing for combinations of Any
and Instruction
nodes with optional nested instructions.
§Key Macros
§schema!
The schema!
macro is the primary entry point for constructing a TransactionSchema
.
It parses provided tokens into a TransactionSchema
object, allowing inline definition
of various schema elements in a tree-like structure. This macro supports keywords like
any
to create branches that can match multiple instruction types.
§Example
use your_crate::schema;
let transaction_schema = schema![
any,
[
AllInstructionTypes::JupSwap(JupiterInstructionType::SwapEvent),
"jup_swap_event",
[]
],
any,
];
This example defines a schema with an any
branch, an Instruction
node with nested
instructions, and another any
branch, creating a flexible transaction structure.
In practical terms, this means that the schema represents a transaction that has a Jupiter Swap Event
instruction anywhere within the transaction.
§schema_inner!
This macro is used internally by schema!
to build out individual SchemaNode
elements.
It supports three main syntax patterns: any
, single Instruction
nodes, and nested Instruction
nodes. Users typically don’t need to interact with this macro directly, as it’s invoked by schema!
to handle recursive node construction.
§Supported Syntax Patterns
any
: Adds anAny
node, which can match any instruction type, multiple times.[$ix_type:expr, $name:expr]
: Adds anInstruction
node without nested instructions.[$ix_type:expr, $name:expr, [$($inner:tt)*]]
: Adds anInstruction
node with nested inner instructions.
§Notes
- The
schema!
macro relies onschema_inner!
for recursive parsing and node creation. - When using the
schema!
macro, ensure that all instruction types and identifiers correspond to valid values expected by theTransactionSchema
to avoid compilation errors.
§Crate Dependencies
This module relies on components like SchemaNode
and InstructionSchemaNode
to build the schema tree.
Make sure these types are defined and accessible within the scope of the module’s usage.