macro_rules! schema { ($($tt:tt)*) => { ... }; }
Expand description
Constructs a TransactionSchema
from provided tokens.
The schema!
macro facilitates the creation of a TransactionSchema
by parsing
the provided tokens and assembling the structure. This macro simplifies schema
construction by allowing inline specification of schema elements, including
instruction types and associated names.
§Syntax
The schema!
macro uses a flexible token-based syntax, enabling you to define
schema nodes inline. Nodes are defined in a hierarchical manner, with keywords
like any
indicating schema branches, followed by instruction types, string
identifiers, and additional attributes or sub-nodes as needed.
§Example
let transaction_schema = schema![
any
[
AllInstructionTypes::JupSwap(JupiterInstructionType::SwapEvent),
"jup_swap_event",
[]
]
any
];
§Parameters
$tt
: The token stream passed to the macro, which may include multiple schema nodes and attributes. These tokens are parsed to construct the schema tree, forming aTransactionSchema
object with a root node containing the specified elements.
§Returns
This macro returns a TransactionSchema
instance with the constructed schema
tree based on the tokens provided. The schema is organized with nodes added
to the root, allowing for complex, multi-layered transaction structures, which represent
real transaction instructions, in order.
§Notes
- This macro requires that the inner macro
schema_inner!
is also defined, as it handles the recursive parsing and node addition to the schema. - Ensure that types and keywords used within the schema correspond to valid
identifiers and instructions expected by
TransactionSchema
. Inconsistent tokens may lead to compilation errors or incorrect schema construction.