Skip to main content

blueprint_client_tangle/
lib.rs

1//! Tangle Client for Blueprint SDK
2//!
3//! This crate provides connectivity to Tangle EVM contracts for blueprint operators.
4//!
5//! ## Overview
6//!
7//! The Tangle client allows blueprints to:
8//! - Query blueprints, services, and operators from the Tangle contract
9//! - Monitor events (job submissions, service lifecycle)
10//! - Submit job results
11//! - Interact with the restaking system
12//!
13//! ## Usage
14//!
15//! ```rust,ignore
16//! use blueprint_client_tangle::{TangleClient, TangleEvent};
17//! use blueprint_runner::config::BlueprintEnvironment;
18//!
19//! async fn example(config: BlueprintEnvironment) -> Result<(), Box<dyn std::error::Error>> {
20//!     // Create client
21//!     let client = TangleClient::new(config).await?;
22//!
23//!     // Query blueprint
24//!     let blueprint = client.get_blueprint(1).await?;
25//!     println!("Blueprint owner: {:?}", blueprint.owner);
26//!
27//!     // Monitor events
28//!     while let Some(event) = client.next_event().await {
29//!         println!("Block {}: {} logs", event.block_number, event.logs.len());
30//!     }
31//!
32//!     Ok(())
33//! }
34//! ```
35//!
36//! ## Contract Interfaces
37//!
38//! The crate provides bindings for:
39//! - `ITangle` - Core Tangle protocol (blueprints, services, jobs, slashing)
40//! - `IMultiAssetDelegation` - Restaking and delegation
41//! - `IOperatorStatusRegistry` - Operator heartbeats and status
42//!
43//! ## Features
44//!
45//! - `std` (default) - Standard library support
46//! - `web` - WebAssembly support
47
48#![cfg_attr(not(feature = "std"), no_std)]
49#![deny(
50    missing_docs,
51    missing_debug_implementations,
52    trivial_casts,
53    trivial_numeric_casts,
54    unsafe_code,
55    unstable_features,
56    unused_import_braces,
57    unused_qualifications
58)]
59
60#[allow(unused_extern_crates)]
61extern crate alloc;
62
63use core::future::Future;
64
65pub mod blueprint_metadata;
66pub mod client;
67pub mod config;
68#[allow(missing_docs)]
69pub mod contracts;
70pub mod error;
71#[allow(missing_docs)]
72pub mod services;
73
74// Re-exports
75pub use blueprint_metadata::{
76    ConfidentialityPolicy, ExecutionProfile, ExecutionProfileError, GpuPolicy, GpuRequirements,
77    extract_job_profiles_blob, inject_execution_profile, resolve_confidentiality_policy,
78    resolve_execution_profile, resolve_execution_profile_from_profiling_data,
79    resolve_gpu_requirements,
80};
81pub use client::{
82    AggregationConfig, AssetInfo, AssetKind, BlueprintSelectionMode, DelegationInfo,
83    DelegationMode, DelegationRecord, DepositInfo, EcdsaPublicKey, JobSubmissionResult, LockInfo,
84    LockMultiplier, OperatorMetadata, OperatorStatusSnapshot, PendingUnstake, PendingWithdrawal,
85    RestakingMetadata, RestakingStatus, TangleClient, TangleEvent, ThresholdType,
86    TransactionResult,
87};
88pub use config::{TangleClientConfig, TangleSettings};
89pub use contracts::{
90    IBlueprintServiceManager, IMultiAssetDelegation, IOperatorStatusRegistry, ITangle,
91};
92pub use error::{Error, Result};
93pub use services::{
94    BlueprintConfig, BlueprintInfo, MembershipModel, OperatorSecurityCommitment, PricingModel,
95    ServiceInfo, ServiceRequestInfo, ServiceRequestParams, ServiceStatus,
96};
97
98/// Trait for clients that provide events
99pub trait EventsClient<E> {
100    /// Get the next event
101    fn next_event(&self) -> impl Future<Output = Option<E>> + Send;
102
103    /// Get the latest event
104    fn latest_event(&self) -> impl Future<Output = Option<E>> + Send;
105}
106
107impl EventsClient<TangleEvent> for TangleClient {
108    async fn next_event(&self) -> Option<TangleEvent> {
109        self.next_event().await
110    }
111
112    async fn latest_event(&self) -> Option<TangleEvent> {
113        self.latest_event().await
114    }
115}