Expand description
Defines the structures and functions for constructing and matching
transaction schemas in carbon-core
.
This module provides the TransactionSchema
, SchemaNode
, and
InstructionSchemaNode
types, enabling users to define and validate
transactions against a specific schema. Transaction schemas can be nested,
allowing for complex, multi-layered transaction structures that represent
various instructions and sub-instructions.
§Key Components
- TransactionSchema: Represents the overall schema for a transaction, consisting of a collection of schema nodes at its root.
- SchemaNode: A node in the schema that can either be an instruction
node or an
Any
node, allowing flexibility in matching instructions at that level. - InstructionSchemaNode: Represents an instruction with its type, name, and any nested inner instructions.
§Usage
The TransactionSchema
type provides methods to match a given transaction’s
instructions against the schema and return a mapped representation of the
data if it conforms to the schema. The match_schema
and match_nodes
methods allow for hierarchical matching and data extraction from
transactions.
§Notes
- Schema Matching: Schema matching is sequential, with
Any
nodes providing flexibility in handling unknown instructions within transactions. EachInstructionSchemaNode
defines specific instructions to be matched, allowing for strict validation where needed. - Nested Instructions: Instruction schemas can contain nested instructions, enabling validation of complex transactions with inner instructions.
- Data Conversion: The
match_schema
method returns data as a deserialized type usingserde_json
. Ensure that your expected output type implementsDeserializeOwned
.
Structs§
- Instruction
Schema Node - Represents an instruction node within a schema, containing the instruction type, name, and optional nested instructions for further validation.
- Parsed
Instruction - Represents a parsed instruction, containing its program ID, decoded instruction data, and any nested instructions within the transaction.
- Transaction
Schema - Represents the schema for a transaction, defining the structure and expected instructions.
Enums§
- Schema
Node - Represents a node within a transaction schema, which can be either an
Instruction
node or anAny
node to allow for flexible matching.
Functions§
- merge_
hashmaps - Merges two hash maps containing instruction data and account information.