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/// Trait for blockchain adapters
37#[async_trait]
38pub trait ChainAdapter: Send + Sync {
39 /// Get the transaction status
40 async fn get_transaction_status(&self, tx_hash: &str) -> Result<TransactionStatus, String>;
41
42 /// Validate an address for this chain
43 fn validate_address(&self, address: &Address) -> bool;
44
45 /// Get the chain name
46 fn chain_name(&self) -> &str;
47}
48
49/// Transaction builder trait
50#[async_trait]
51pub trait TransactionBuilder {
52 /// Set the sender address
53 fn from(&mut self, address: Address) -> &mut Self;
54
55 /// Set the recipient address
56 fn to(&mut self, address: Address) -> &mut Self;
57
58 /// Set the amount
59 fn amount(&mut self, amount: u128) -> &mut Self;
60
61 /// Build the transaction
62 fn build(&self) -> Result<Vec<u8>, String>;
63}