Skip to main content

circles_types/
lib.rs

1//! # Circles Types
2//!
3//! Complete type definitions for the Circles protocol ecosystem in Rust.
4//!
5//! This crate provides comprehensive data structures for all aspects of the Circles
6//! protocol, including avatar management, trust relations, token operations, pathfinding,
7//! event handling, RPC communication, and contract interactions. All types support
8//! full `serde` serialization and are compatible with the TypeScript Circles SDK.
9//!
10//! ## Features
11//!
12//! - **Complete Protocol Coverage**: Types for avatars, trust, tokens, groups, events
13//! - **Alloy Integration**: Built on `alloy-primitives` for Ethereum compatibility
14//! - **API Compatible**: Matches TypeScript SDK structure exactly
15//! - **Type Safety**: Leverages Rust's type system while maintaining flexibility
16//! - **Async Ready**: Traits for contract runners and batch operations
17//! - **Query DSL**: Complete query builder for `circles_query` RPC method
18//!
19//! ## Usage Examples
20//!
21//! ```rust,ignore
22//! use circles_types::{
23//!     // Core types
24//!     Address, U256, TxHash,
25//!     // Avatar and profile types
26//!     AvatarInfo, Profile, AvatarType,
27//!     // Pathfinding
28//!     FindPathParams, PathfindingResult,
29//!     // Trust relations
30//!     TrustRelation, TrustRelationType,
31//!     // Configuration
32//!     CirclesConfig,
33//! };
34//!
35//! // Create avatar information
36//! let avatar = AvatarInfo {
37//!     block_number: 12345,
38//!     timestamp: Some(1234567890),
39//!     transaction_index: 1,
40//!     log_index: 0,
41//!     transaction_hash: "0xabc123...".parse()?,
42//!     version: 2,
43//!     avatar_type: AvatarType::CrcV2RegisterHuman,
44//!     avatar: "0x123...".parse()?,
45//!     token_id: Some(U256::from(1)),
46//!     has_v1: false,
47//!     v1_token: None,
48//!     cid_v0_digest: None,
49//!     cid_v0: None,
50//!     v1_stopped: None,
51//!     is_human: true,
52//!     name: None,
53//!     symbol: None,
54//! };
55//!
56//! // Create pathfinding parameters
57//! let params = FindPathParams {
58//!     from: "0xabc...".parse()?,
59//!     to: "0xdef...".parse()?,
60//!     target_flow: U256::from(1000u64),
61//!     use_wrapped_balances: Some(true),
62//!     from_tokens: None,
63//!     to_tokens: None,
64//!     exclude_from_tokens: None,
65//!     exclude_to_tokens: None,
66//!     simulated_balances: None,
67//!     simulated_trusts: None,
68//!     max_transfers: Some(10),
69//! };
70//!
71//! // Serialize to JSON
72//! let json = serde_json::to_string(&avatar)?;
73//! # Ok::<(), Box<dyn std::error::Error>>(())
74//! ```
75//!
76//! ## Type Categories
77//!
78//! ### Core Blockchain Types
79//! - [`Address`] - Ethereum address (re-exported from alloy-primitives)
80//! - [`TxHash`], [`BlockHash`] - Transaction and block hashes
81//! - [`U256`], [`U192`] - Large unsigned integers
82//! - [`TransactionRequest`] - Transaction request data
83//!
84//! ### Avatar & Profile Management
85//! - [`AvatarInfo`] - Complete avatar information and metadata
86//! - [`Profile`] - User profile with name, description, images
87//! - [`GroupProfile`] - Group profile extending Profile with symbol
88//! - [`AvatarType`] - Registration event types (Human, Group, Organization)
89//!
90//! ### Trust & Social Graph
91//! - [`TrustRelation`] - Individual trust relationship
92//! - [`AggregatedTrustRelation`] - Processed trust relationships
93//! - [`TrustRelationType`] - Trust relationship types
94//!
95//! ### Token Operations
96//! - [`TokenBalance`] - Token balance with metadata
97//! - [`TokenInfo`] - Token creation and type information
98//! - [`TokenHolder`] - Account token holdings
99//! - [`Balance`] - Flexible balance type (raw or formatted)
100//!
101//! ### Group Management
102//! - [`GroupRow`] - Group registration and metadata
103//! - [`GroupMembershipRow`] - Group membership records
104//! - [`GroupQueryParams`] - Parameters for group queries
105//!
106//! ### Pathfinding & Transfers
107//! - [`FindPathParams`] - Parameters for path computation
108//! - [`PathfindingResult`] - Computed transfer path
109//! - [`TransferStep`] - Individual transfer in a path
110//! - [`FlowMatrix`] - Complete flow representation for contracts
111//! - [`SimulatedBalance`] - Balance simulation for pathfinding
112//! - [`SimulatedTrust`] - Trust-edge simulation for pathfinding
113//!
114//! ### Event System
115//! - [`CirclesEvent`] - Universal event structure
116//! - [`CirclesEventType`] - All supported event types (25+ variants)
117//! - [`CirclesBaseEvent`] - Common event metadata
118//!
119//! ### RPC & Communication
120//! - [`JsonRpcRequest`], [`JsonRpcResponse`] - Standard JSON-RPC types
121//! - [`CirclesQueryResponse`] - Response format for queries
122//! - [`TokenBalanceResponse`] - Token balance from RPC calls
123//!
124//! ### Query System
125//! - [`QueryParams`] - Parameters for `circles_query` RPC method
126//! - [`FilterPredicate`], [`Conjunction`] - Query filtering DSL
127//! - [`PagedResult`] - Paginated query results
128//! - [`SortOrder`], [`OrderBy`] - Result sorting
129//!
130//! ### Contract Execution
131//! - [`ContractRunner`] - Async trait for contract interactions
132//! - [`BatchRun`] - Trait for batched transaction execution
133//! - [`RunnerConfig`] - Configuration for contract runners
134//!
135//! ### Protocol Configuration
136//! - [`CirclesConfig`] - Complete protocol configuration
137//! - [`EscrowedAmountAndDays`] - Contract-specific response types
138//! - [`DecodedContractError`] - Contract error information
139//!
140//! ### Network State
141//! - [`NetworkSnapshot`] - Complete network state at a block
142//! - [`EventRow`] - Base structure for event pagination
143//! - [`Cursor`] - Pagination cursor for efficient queries
144
145// =============================================================================
146// External re-exports
147// =============================================================================
148
149// Alloy primitive types
150pub use alloy_primitives::aliases::{BlockHash, TxHash};
151pub use alloy_primitives::Address;
152pub use alloy_primitives::Bytes;
153pub use alloy_primitives::{aliases::U192, U256};
154
155// Alloy RPC types
156pub use alloy_provider::transport::TransportResult;
157pub use alloy_rpc_types::TransactionRequest;
158
159// =============================================================================
160// Internal modules with explicit re-exports
161// =============================================================================
162
163mod avatar;
164pub use avatar::{AvatarInfo, AvatarType, GeoLocation, GroupProfile, Profile};
165
166mod config;
167pub use config::CirclesConfig;
168
169mod contracts;
170pub use contracts::EscrowedAmountAndDays;
171
172mod errors;
173pub use errors::DecodedContractError;
174
175mod events;
176pub use events::{CirclesBaseEvent, CirclesEvent, CirclesEventType, RpcSubscriptionEvent};
177
178mod group;
179pub use group::{GroupMembershipRow, GroupQueryParams, GroupRow, GroupTokenHolderRow};
180
181mod network;
182pub use network::{EventType, NetworkSnapshot};
183
184mod trust;
185pub use trust::{AggregatedTrustRelation, TrustRelation, TrustRelationType};
186
187mod wrapper;
188pub use wrapper::{CirclesType, WrappedTokenInfo, WrappedTokensRecord};
189
190mod token;
191pub use token::{TokenBalance, TokenHolder, TokenInfo};
192
193mod client;
194pub use client::{AvatarRow, CirclesQuery, GroupType, TokenBalanceRow, TrustRelationRow};
195
196mod runner;
197pub use runner::{BatchRun, ContractRunner, RunnerConfig};
198
199mod rpc;
200pub use rpc::{
201    AllInvitationsResponse, AtScaleInvitation, Balance, CirclesQueryResponse, EscrowInvitation,
202    InvitationOriginResponse, InvitationsFromResponse, InvitedAccountInfo, JsonRpcError,
203    JsonRpcRequest, JsonRpcResponse, QueryResponse, SafeQueryResponse, TokenBalanceResponse,
204    TransactionHistoryRow, TrustInvitation,
205};
206
207mod query;
208pub use query::{
209    ColumnInfo, Conjunction, ConjunctionType, Cursor, CursorColumn, EventRow, Filter,
210    FilterPredicate, FilterType, OrderBy, PagedQueryParams, PagedResult, QueryParams, SortOrder,
211    TableInfo,
212};
213
214mod pathfinding;
215pub use pathfinding::{
216    AdvancedTransferOptions,
217    FindPathParams,
218    // Original flow types
219    FlowEdge,
220    FlowEdgeStruct,
221    FlowMatrix,
222    PathfindingFlowMatrix,
223    PathfindingResult,
224    PathfindingTransferStep,
225    SimulatedBalance,
226    SimulatedTrust,
227    Stream,
228    StreamStruct,
229    TransferStep,
230};