1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Extension traits for ApplicationContext to provide ergonomic access to chain-specific clients
//!
//! These traits should be implemented in the respective chain-specific crates
//! (riglr-solana-tools, riglr-evm-tools, etc.) to provide type-safe, convenient
//! access methods for their clients.
use crateToolError;
use Arc;
/// Example trait that should be implemented in riglr-solana-tools
///
/// # Example Implementation (in riglr-solana-tools/src/lib.rs):
/// ```rust,ignore
/// use riglr_core::provider::ApplicationContext;
/// use riglr_core::provider_extensions::SolanaAppContextProvider;
/// use riglr_core::ToolError;
/// use solana_client::rpc_client::RpcClient as SolanaRpcClient;
/// use std::sync::Arc;
///
/// impl SolanaAppContextProvider for ApplicationContext {
/// fn solana_client(&self) -> Result<Arc<SolanaRpcClient>, ToolError> {
/// self.get_extension::<Arc<SolanaRpcClient>>()
/// .ok_or_else(|| ToolError::permanent_string(
/// "Solana RPC client not configured in ApplicationContext"
/// ))
/// }
/// }
/// ```
/// Example trait that should be implemented in riglr-evm-tools
///
/// # Example Implementation (in riglr-evm-tools/src/lib.rs):
/// ```rust,ignore
/// use riglr_core::provider::ApplicationContext;
/// use riglr_core::provider_extensions::EvmAppContextProvider;
/// use riglr_core::ToolError;
/// use ethers::providers::Provider;
/// use std::sync::Arc;
///
/// impl EvmAppContextProvider for ApplicationContext {
/// fn evm_client(&self) -> Result<Arc<dyn Provider>, ToolError> {
/// self.get_extension::<Arc<dyn Provider>>()
/// .ok_or_else(|| ToolError::permanent_string(
/// "EVM provider not configured in ApplicationContext"
/// ))
/// }
/// }
/// ```
/// Generic extension trait for custom providers
///
/// This can be used for any custom client type that needs to be accessed
/// from the ApplicationContext.
///
/// # Example:
/// ```rust,ignore
/// use riglr_core::provider::ApplicationContext;
/// use riglr_core::provider_extensions::AppContextExtension;
/// use riglr_core::ToolError;
/// use std::sync::Arc;
///
/// struct MyCustomClient;
///
/// impl AppContextExtension<MyCustomClient> for ApplicationContext {
/// fn get_client(&self) -> Result<Arc<MyCustomClient>, ToolError> {
/// self.get_extension::<Arc<MyCustomClient>>()
/// .ok_or_else(|| ToolError::permanent_string(
/// "MyCustomClient not configured in ApplicationContext"
/// ))
/// }
/// }
/// ```