carbon_core/
lib.rs

1//! # Carbon Core
2//!
3//! `carbon-core` is a framework designed for building customizable and
4//! extensible indexers tailored to Solana blockchain data. It facilitates
5//! efficient data ingestion, transformation, and processing, supporting a wide
6//! range of use cases from transaction parsing to complex instruction analysis.
7//! This crate includes modular components that enable users to process
8//! blockchain data flexibly and with ease.
9//!
10//! The true power of this framework lies when utilizing all it's components in
11//! combination with one another.
12//!
13//! ## Modules Overview
14//!
15//! - **[`account`]**: Manages account data processing, including decoding and
16//!   updates. Account data is processed through pipes that support custom
17//!   decoders and processors.
18//!
19//! - **[`account_deletion`]**: Handles the deletion of accounts and processes
20//!   these events in the pipeline.
21//!
22//! - **[`collection`]**: Defines collections for instruction decoding, allowing
23//!   for customized instruction parsers that handle specific instruction sets.
24//!
25//! - **[`datasource`]**: Provides data ingestion capabilities, enabling the
26//!   integration of external data sources into the pipeline. Supports
27//!   Solana-specific data structures.
28//!
29//! - **[`deserialize`]**: Contains utilities for data deserialization,
30//!   including helper functions for parsing Solana transactions and other
31//!   binary data formats.
32//!
33//! - **[`error`]**: Defines error types used throughout the crate, providing
34//!   consistent error handling for the framework.
35//!
36//! - **[`filter`]**: Provides a flexible filtering system that allows selective
37//!   processing of updates based on various criteria such as datasource ID,
38//!   update content, or custom logic. Filters can be applied to different
39//!   types of updates (accounts, instructions, transactions, account deletions,
40//!   and block details) to control which updates are processed by specific pipes.
41//!
42//! - **[`instruction`]**: Supports instruction parsing and processing within
43//!   transactions. This module includes structures and traits for decoding and
44//!   handling transaction instructions.
45//!
46//! - **[`metrics`]**: Facilitates performance monitoring and metric recording
47//!   within the pipeline. Metrics can be customized and are recorded at each
48//!   processing stage for monitoring and debugging purposes.
49//!
50//! - **[`pipeline`]**: Represents the core of the framework, defining the main
51//!   pipeline structure that manages data flow and processing. The pipeline
52//!   integrates data sources, processing pipes, and metrics to provide a
53//!   complete data processing solution.
54//!
55//! - **[`postgres`]**: Provides support for PostgreSQL database operations,
56//!   including table definitions, insert, upsert, and delete operations.
57//!   This module is designed to be used in conjunction with the `sqlx` crate
58//!   for database interactions.
59//!
60//! - **[`processor`]**: Contains traits and implementations for processing data
61//!   in the pipeline. This module allows for the creation of custom data
62//!   processors that can be integrated into various stages of the pipeline.
63//!
64//! - **[`schema`]**: Defines transaction schemas, allowing for structured
65//!   parsing and validation of transaction data based on specified rules.
66//!   Supports complex nested instruction matching for comprehensive transaction
67//!   analysis.
68//!
69//! - **[`transaction`]**: Manages transaction data, including metadata
70//!   extraction and parsing. This module supports transaction validation and
71//!   processing, enabling detailed transaction insights.
72//!
73//! - **[`transformers`]**: Provides utility functions for transforming and
74//!   restructuring data. This module includes functions for converting Solana
75//!   transaction data into formats suitable for processing within the
76//!   framework.
77//!
78//! ## Quick Start
79//!
80//! To create a new `carbon-core` pipeline, start by configuring data sources,
81//! processing pipes, and metrics in the [`pipeline::PipelineBuilder`]. Below is
82//! a basic example demonstrating how to set up a pipeline:
83//!
84//! ```ignore
85//! use std::sync::Arc;
86//!
87//! carbon_core::pipeline::Pipeline::builder()
88//! .datasource(transaction_crawler)
89//! .metrics(Arc::new(LogMetrics::new()))
90//! .metrics(Arc::new(PrometheusMetrics::new()))
91//! .instruction(
92//!    TestProgramDecoder,
93//!    TestProgramProcessor
94//! )
95//! .account(
96//!     TestProgramDecoder,
97//!     TestProgramAccountProcessor
98//! )
99//! .transaction(TEST_SCHEMA.clone(), TestProgramTransactionProcessor)
100//! .account_deletions(TestProgramAccountDeletionProcessor)
101//! .build()?
102//! .run()
103//! .await?;
104//! ```
105//!
106//! ## Crate Features
107//!
108//! - **Modular Design**: Components can be easily added or replaced, allowing
109//!   for a high degree of customization.
110//! - **Concurrency Support**: Built with asynchronous Rust, enabling efficient
111//!   data processing in parallel.
112//! - **Solana-Specific**: Tailored to handle Solana blockchain data structures,
113//!   making it ideal for blockchain data analysis and transaction processing.
114//!
115//! ## Notes
116//!
117//! - `carbon-core` integrates with Solana's SDK, leveraging types and data
118//!   structures specific to the Solana blockchain.
119//! - This framework is designed for advanced use cases, such as blockchain
120//!   indexing, transaction monitoring, and custom data analysis.
121//!
122//! Explore each module in detail to understand their individual functions and
123//! to learn how to customize and extend `carbon-core` to suit your specific
124//! data processing requirements.
125
126pub mod account;
127pub mod account_deletion;
128pub mod account_utils;
129mod block_details;
130pub mod collection;
131pub mod datasource;
132pub mod deserialize;
133pub mod error;
134pub mod filter;
135#[cfg(feature = "graphql")]
136pub mod graphql;
137pub mod instruction;
138pub mod metrics;
139pub mod pipeline;
140#[cfg(feature = "postgres")]
141pub mod postgres;
142pub mod processor;
143pub mod schema;
144pub mod transaction;
145pub mod transformers;
146
147pub use borsh;
148#[cfg(feature = "macros")]
149pub use carbon_macros::*;
150#[cfg(feature = "macros")]
151pub use carbon_proc_macros::*;
152#[cfg(feature = "macros")]
153#[doc(hidden)]
154pub use log;