1
1
use {
2
2
async_trait:: async_trait,
3
- solana_banks_interface:: BanksTransactionResultWithSimulation ,
4
- solana_program_test:: { tokio:: sync:: Mutex , BanksClient , ProgramTestContext } ,
3
+ solana_account:: Account ,
4
+ solana_hash:: Hash ,
5
+ solana_pubkey:: Pubkey ,
5
6
solana_rpc_client:: nonblocking:: rpc_client:: RpcClient ,
6
7
solana_rpc_client_api:: response:: RpcSimulateTransactionResult ,
7
- solana_sdk:: {
8
- account:: Account , hash:: Hash , pubkey:: Pubkey , signature:: Signature ,
9
- transaction:: Transaction ,
10
- } ,
8
+ solana_signature:: Signature ,
9
+ solana_transaction:: Transaction ,
11
10
std:: { fmt, future:: Future , pin:: Pin , sync:: Arc } ,
12
11
} ;
13
12
13
+ #[ cfg( feature = "dev-context-only-utils" ) ]
14
+ use {
15
+ solana_banks_client:: BanksClient , solana_banks_interface:: BanksTransactionResultWithSimulation ,
16
+ solana_program_test:: ProgramTestContext , tokio:: sync:: Mutex ,
17
+ } ;
18
+
14
19
type BoxFuture < ' a , T > = Pin < Box < dyn Future < Output = T > + Send + ' a > > ;
15
20
16
21
/// Basic trait for sending transactions to validator.
@@ -30,6 +35,7 @@ pub trait SimulationResult {
30
35
31
36
/// Extends basic `SendTransaction` trait with function `send` where client is
32
37
/// `&mut BanksClient`. Required for `ProgramBanksClient`.
38
+ #[ cfg( feature = "dev-context-only-utils" ) ]
33
39
pub trait SendTransactionBanksClient : SendTransaction {
34
40
fn send < ' a > (
35
41
& self ,
@@ -40,6 +46,7 @@ pub trait SendTransactionBanksClient: SendTransaction {
40
46
41
47
/// Extends basic `SimulateTransaction` trait with function `simulation` where
42
48
/// client is `&mut BanksClient`. Required for `ProgramBanksClient`.
49
+ #[ cfg( feature = "dev-context-only-utils" ) ]
43
50
pub trait SimulateTransactionBanksClient : SimulateTransaction {
44
51
fn simulate < ' a > (
45
52
& self ,
@@ -50,12 +57,15 @@ pub trait SimulateTransactionBanksClient: SimulateTransaction {
50
57
51
58
/// Send transaction to validator using `BanksClient::process_transaction`.
52
59
#[ derive( Debug , Clone , Copy , Default ) ]
60
+ #[ cfg( feature = "dev-context-only-utils" ) ]
53
61
pub struct ProgramBanksClientProcessTransaction ;
54
62
63
+ #[ cfg( feature = "dev-context-only-utils" ) ]
55
64
impl SendTransaction for ProgramBanksClientProcessTransaction {
56
65
type Output = ( ) ;
57
66
}
58
67
68
+ #[ cfg( feature = "dev-context-only-utils" ) ]
59
69
impl SendTransactionBanksClient for ProgramBanksClientProcessTransaction {
60
70
fn send < ' a > (
61
71
& self ,
@@ -71,6 +81,7 @@ impl SendTransactionBanksClient for ProgramBanksClientProcessTransaction {
71
81
}
72
82
}
73
83
84
+ #[ cfg( feature = "dev-context-only-utils" ) ]
74
85
impl SimulationResult for BanksTransactionResultWithSimulation {
75
86
fn get_compute_units_consumed ( & self ) -> ProgramClientResult < u64 > {
76
87
self . simulation_details
@@ -80,10 +91,12 @@ impl SimulationResult for BanksTransactionResultWithSimulation {
80
91
}
81
92
}
82
93
94
+ #[ cfg( feature = "dev-context-only-utils" ) ]
83
95
impl SimulateTransaction for ProgramBanksClientProcessTransaction {
84
96
type SimulationOutput = BanksTransactionResultWithSimulation ;
85
97
}
86
98
99
+ #[ cfg( feature = "dev-context-only-utils" ) ]
87
100
impl SimulateTransactionBanksClient for ProgramBanksClientProcessTransaction {
88
101
fn simulate < ' a > (
89
102
& self ,
@@ -213,23 +226,27 @@ where
213
226
) -> ProgramClientResult < ST :: SimulationOutput > ;
214
227
}
215
228
229
+ #[ cfg( feature = "dev-context-only-utils" ) ]
216
230
enum ProgramBanksClientContext {
217
231
Client ( Arc < Mutex < BanksClient > > ) ,
218
232
Context ( Arc < Mutex < ProgramTestContext > > ) ,
219
233
}
220
234
221
235
/// Program client for `BanksClient` from crate `solana-program-test`.
236
+ #[ cfg( feature = "dev-context-only-utils" ) ]
222
237
pub struct ProgramBanksClient < ST > {
223
238
context : ProgramBanksClientContext ,
224
239
send : ST ,
225
240
}
226
241
242
+ #[ cfg( feature = "dev-context-only-utils" ) ]
227
243
impl < ST > fmt:: Debug for ProgramBanksClient < ST > {
228
244
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
229
245
f. debug_struct ( "ProgramBanksClient" ) . finish ( )
230
246
}
231
247
}
232
248
249
+ #[ cfg( feature = "dev-context-only-utils" ) ]
233
250
impl < ST > ProgramBanksClient < ST > {
234
251
fn new ( context : ProgramBanksClientContext , send : ST ) -> Self {
235
252
Self { context, send }
@@ -260,6 +277,7 @@ impl<ST> ProgramBanksClient<ST> {
260
277
}
261
278
}
262
279
280
+ #[ cfg( feature = "dev-context-only-utils" ) ]
263
281
#[ async_trait]
264
282
impl < ST > ProgramClient < ST > for ProgramBanksClient < ST >
265
283
where
0 commit comments