@@ -106,107 +106,97 @@ pub mod solana_rpc_client_nonce_utils {
106
106
}
107
107
}
108
108
109
- /// Re-exports and mocks of solana-program modules that mirror those from
110
- /// solana-program.
111
- ///
112
- /// This lets examples in solana-program appear to be written as client
113
- /// programs.
114
- pub mod solana_sdk {
115
- pub use crate :: {
116
- hash, instruction, keccak, message, nonce,
117
- pubkey:: { self , Pubkey } ,
118
- system_instruction, system_program,
119
- sysvar:: {
120
- self ,
121
- clock:: { self , Clock } ,
122
- } ,
123
- } ;
124
-
125
- pub mod account {
126
- use { crate :: pubkey:: Pubkey , solana_clock:: Epoch } ;
127
- #[ derive( Clone ) ]
128
- pub struct Account {
129
- pub lamports : u64 ,
130
- pub data : Vec < u8 > ,
131
- pub owner : Pubkey ,
132
- pub executable : bool ,
133
- pub rent_epoch : Epoch ,
134
- }
109
+ pub mod solana_account {
110
+ use { crate :: pubkey:: Pubkey , solana_clock:: Epoch } ;
111
+ #[ derive( Clone ) ]
112
+ pub struct Account {
113
+ pub lamports : u64 ,
114
+ pub data : Vec < u8 > ,
115
+ pub owner : Pubkey ,
116
+ pub executable : bool ,
117
+ pub rent_epoch : Epoch ,
118
+ }
135
119
136
- pub trait ReadableAccount : Sized {
137
- fn data ( & self ) -> & [ u8 ] ;
138
- }
120
+ pub trait ReadableAccount : Sized {
121
+ fn data ( & self ) -> & [ u8 ] ;
122
+ }
139
123
140
- impl ReadableAccount for Account {
141
- fn data ( & self ) -> & [ u8 ] {
142
- & self . data
143
- }
124
+ impl ReadableAccount for Account {
125
+ fn data ( & self ) -> & [ u8 ] {
126
+ & self . data
144
127
}
145
128
}
146
129
147
- pub mod account_utils {
148
- use super :: account :: Account ;
130
+ pub mod state_traits {
131
+ use super :: Account ;
149
132
150
133
pub trait StateMut < T > { }
151
134
152
135
impl < T > StateMut < T > for Account { }
153
136
}
137
+ }
154
138
155
- pub mod signature {
156
- use crate :: pubkey:: Pubkey ;
157
-
158
- #[ derive( Default , Debug ) ]
159
- pub struct Signature ;
160
-
161
- pub struct Keypair ;
162
-
163
- impl Keypair {
164
- pub fn new ( ) -> Keypair {
165
- Keypair
166
- }
167
- }
139
+ pub mod solana_signature {
140
+ #[ derive( Default , Debug ) ]
141
+ pub struct Signature ;
142
+ }
168
143
169
- impl Signer for Keypair {
170
- fn pubkey ( & self ) -> Pubkey {
171
- Pubkey :: default ( )
172
- }
173
- }
144
+ pub mod solana_signer {
145
+ use { solana_pubkey:: Pubkey , thiserror:: Error } ;
174
146
175
- pub trait Signer {
176
- fn pubkey ( & self ) -> Pubkey ;
177
- }
147
+ #[ derive( Error , Debug ) ]
148
+ #[ error( "mock-error" ) ]
149
+ pub struct SignerError ;
150
+ pub trait Signer {
151
+ fn pubkey ( & self ) -> Pubkey ;
178
152
}
179
153
180
154
pub mod signers {
181
- use super :: signature :: Signer ;
155
+ use super :: Signer ;
182
156
183
157
pub trait Signers { }
184
158
185
159
impl < T : Signer > Signers for [ & T ] { }
186
160
impl < T : Signer > Signers for [ & T ; 1 ] { }
187
161
impl < T : Signer > Signers for [ & T ; 2 ] { }
188
162
}
163
+ }
189
164
190
- pub mod signer {
191
- use thiserror:: Error ;
165
+ pub mod solana_keypair {
166
+ use { crate :: example_mocks:: solana_signer:: Signer , solana_pubkey:: Pubkey } ;
167
+ pub struct Keypair ;
192
168
193
- #[ derive( Error , Debug ) ]
194
- #[ error( "mock-error" ) ]
195
- pub struct SignerError ;
169
+ impl Keypair {
170
+ pub fn new ( ) -> Keypair {
171
+ Keypair
172
+ }
196
173
}
197
174
198
- pub mod transaction {
175
+ impl Signer for Keypair {
176
+ fn pubkey ( & self ) -> Pubkey {
177
+ Pubkey :: default ( )
178
+ }
179
+ }
180
+ }
181
+
182
+ pub mod solana_transaction {
183
+ use {
184
+ crate :: example_mocks:: solana_signer:: { signers:: Signers , SignerError } ,
185
+ serde_derive:: Serialize ,
186
+ solana_hash:: Hash ,
187
+ solana_instruction:: Instruction ,
188
+ solana_message:: Message ,
189
+ solana_pubkey:: Pubkey ,
190
+ } ;
191
+
192
+ pub mod versioned {
199
193
use {
200
- super :: { signature:: Signature , signer:: SignerError , signers:: Signers } ,
201
- crate :: {
202
- hash:: Hash ,
203
- instruction:: Instruction ,
204
- message:: { Message , VersionedMessage } ,
205
- pubkey:: Pubkey ,
194
+ crate :: example_mocks:: {
195
+ solana_signature:: Signature ,
196
+ solana_signer:: { signers:: Signers , SignerError } ,
206
197
} ,
207
- serde_derive :: Serialize ,
198
+ solana_message :: VersionedMessage ,
208
199
} ;
209
-
210
200
pub struct VersionedTransaction {
211
201
pub signatures : Vec < Signature > ,
212
202
pub message : VersionedMessage ,
@@ -223,56 +213,89 @@ pub mod solana_sdk {
223
213
} )
224
214
}
225
215
}
216
+ }
226
217
227
- #[ derive( Serialize ) ]
228
- pub struct Transaction {
229
- pub message : Message ,
230
- }
218
+ #[ derive( Serialize ) ]
219
+ pub struct Transaction {
220
+ pub message : Message ,
221
+ }
231
222
232
- impl Transaction {
233
- pub fn new < T : Signers + ?Sized > (
234
- _from_keypairs : & T ,
235
- _message : Message ,
236
- _recent_blockhash : Hash ,
237
- ) -> Transaction {
238
- Transaction {
239
- message : Message :: new ( & [ ] , None ) ,
240
- }
223
+ impl Transaction {
224
+ pub fn new < T : Signers + ?Sized > (
225
+ _from_keypairs : & T ,
226
+ _message : Message ,
227
+ _recent_blockhash : Hash ,
228
+ ) -> Transaction {
229
+ Transaction {
230
+ message : Message :: new ( & [ ] , None ) ,
241
231
}
232
+ }
242
233
243
- pub fn new_unsigned ( _message : Message ) -> Self {
244
- Transaction {
245
- message : Message :: new ( & [ ] , None ) ,
246
- }
234
+ pub fn new_unsigned ( _message : Message ) -> Self {
235
+ Transaction {
236
+ message : Message :: new ( & [ ] , None ) ,
247
237
}
238
+ }
248
239
249
- pub fn new_with_payer ( _instructions : & [ Instruction ] , _payer : Option < & Pubkey > ) -> Self {
250
- Transaction {
251
- message : Message :: new ( & [ ] , None ) ,
252
- }
240
+ pub fn new_with_payer ( _instructions : & [ Instruction ] , _payer : Option < & Pubkey > ) -> Self {
241
+ Transaction {
242
+ message : Message :: new ( & [ ] , None ) ,
253
243
}
244
+ }
254
245
255
- pub fn new_signed_with_payer < T : Signers + ?Sized > (
256
- instructions : & [ Instruction ] ,
257
- payer : Option < & Pubkey > ,
258
- signing_keypairs : & T ,
259
- recent_blockhash : Hash ,
260
- ) -> Self {
261
- let message = Message :: new ( instructions, payer) ;
262
- Self :: new ( signing_keypairs, message, recent_blockhash)
263
- }
246
+ pub fn new_signed_with_payer < T : Signers + ?Sized > (
247
+ instructions : & [ Instruction ] ,
248
+ payer : Option < & Pubkey > ,
249
+ signing_keypairs : & T ,
250
+ recent_blockhash : Hash ,
251
+ ) -> Self {
252
+ let message = Message :: new ( instructions, payer) ;
253
+ Self :: new ( signing_keypairs, message, recent_blockhash)
254
+ }
264
255
265
- pub fn sign < T : Signers + ?Sized > ( & mut self , _keypairs : & T , _recent_blockhash : Hash ) { }
256
+ pub fn sign < T : Signers + ?Sized > ( & mut self , _keypairs : & T , _recent_blockhash : Hash ) { }
266
257
267
- pub fn try_sign < T : Signers + ?Sized > (
268
- & mut self ,
269
- _keypairs : & T ,
270
- _recent_blockhash : Hash ,
271
- ) -> Result < ( ) , SignerError > {
272
- Ok ( ( ) )
273
- }
258
+ pub fn try_sign < T : Signers + ?Sized > (
259
+ & mut self ,
260
+ _keypairs : & T ,
261
+ _recent_blockhash : Hash ,
262
+ ) -> Result < ( ) , SignerError > {
263
+ Ok ( ( ) )
274
264
}
275
265
}
266
+ }
267
+
268
+ /// Re-exports and mocks of solana-program modules that mirror those from
269
+ /// solana-program.
270
+ ///
271
+ /// This lets examples in solana-program appear to be written as client
272
+ /// programs.
273
+ pub mod solana_sdk {
274
+ pub use crate :: {
275
+ example_mocks:: {
276
+ solana_account:: { self as account, state_traits as account_utils} ,
277
+ solana_signer:: { self as signer, signers} ,
278
+ } ,
279
+ hash, instruction, keccak, message, nonce,
280
+ pubkey:: { self , Pubkey } ,
281
+ system_instruction, system_program,
282
+ sysvar:: {
283
+ self ,
284
+ clock:: { self , Clock } ,
285
+ } ,
286
+ } ;
287
+
288
+ pub mod signature {
289
+ pub use crate :: example_mocks:: {
290
+ solana_keypair:: Keypair , solana_signature:: Signature , solana_signer:: Signer ,
291
+ } ;
292
+ }
293
+
294
+ pub mod transaction {
295
+ pub use crate :: example_mocks:: solana_transaction:: {
296
+ versioned:: VersionedTransaction , Transaction ,
297
+ } ;
298
+ }
276
299
277
300
pub use crate :: address_lookup_table;
278
301
}
0 commit comments