apex_sdk_core/
lib.rs

1//! # Apex SDK Core
2//!
3//! Core traits and functionality for the Apex SDK.
4//!
5//! This crate provides the foundational abstractions used across all blockchain adapters
6//! in the Apex SDK. It defines common traits like `ChainAdapter` and `TransactionBuilder`
7//! that enable unified interaction with different blockchain types.
8//!
9//! ## Features
10//!
11//! - **Chain Adapter Trait**: Common interface for all blockchain types
12//! - **Transaction Builder**: Flexible transaction construction
13//! - **Type-safe abstractions**: Generic over chain implementations
14//!
15//! ## Usage
16//!
17//! This crate is typically used as a dependency by adapter implementations
18//! (e.g., `apex-sdk-substrate`, `apex-sdk-evm`) and is re-exported through
19//! the main `apex-sdk` crate.
20//!
21//! ```rust,no_run
22//! use apex_sdk_core::ChainAdapter;
23//! use apex_sdk_types::{Address, TransactionStatus};
24//!
25//! async fn check_transaction<T: ChainAdapter>(
26//!     adapter: &T,
27//!     tx_hash: &str
28//! ) -> Result<TransactionStatus, String> {
29//!     adapter.get_transaction_status(tx_hash).await
30//! }
31//! ```
32
33use apex_sdk_types::{Address, TransactionStatus};
34use async_trait::async_trait;
35
36/// Mock implementations for testing
37#[cfg(any(test, feature = "mocks"))]
38pub mod mocks;
39
40/// Trait for blockchain adapters
41#[async_trait]
42pub trait ChainAdapter: Send + Sync {
43    /// Get the transaction status
44    async fn get_transaction_status(&self, tx_hash: &str) -> Result<TransactionStatus, String>;
45
46    /// Validate an address for this chain
47    fn validate_address(&self, address: &Address) -> bool;
48
49    /// Get the chain name
50    fn chain_name(&self) -> &str;
51}
52
53/// Transaction builder trait
54#[async_trait]
55pub trait TransactionBuilder {
56    /// Set the sender address
57    fn from(&mut self, address: Address) -> &mut Self;
58
59    /// Set the recipient address
60    fn to(&mut self, address: Address) -> &mut Self;
61
62    /// Set the amount
63    fn amount(&mut self, amount: u128) -> &mut Self;
64
65    /// Build the transaction
66    fn build(&self) -> Result<Vec<u8>, String>;
67}