Skip to content

Commit 77eb01f

Browse files
authored
chore: rename instruction data traits (#1699)
1 parent afc0029 commit 77eb01f

File tree

15 files changed

+81
-108
lines changed

15 files changed

+81
-108
lines changed

program-libs/compressed-account/src/instruction_data/traits.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use super::{
99
};
1010
use crate::{compressed_account::CompressedAccountData, pubkey::Pubkey, CompressedAccountError};
1111

12-
pub trait InstructionDataTrait<'a> {
12+
pub trait InstructionData<'a> {
1313
fn owner(&self) -> Pubkey;
14-
fn new_addresses(&self) -> &[impl NewAddressParamsTrait<'a>];
15-
fn input_accounts(&self) -> &[impl InputAccountTrait<'a>];
16-
fn output_accounts(&self) -> &[impl OutputAccountTrait<'a>];
14+
fn new_addresses(&self) -> &[impl NewAddress<'a>];
15+
fn input_accounts(&self) -> &[impl InputAccount<'a>];
16+
fn output_accounts(&self) -> &[impl OutputAccount<'a>];
1717
fn read_only_accounts(&self) -> Option<&[ZPackedReadOnlyCompressedAccount]>;
1818
fn read_only_addresses(&self) -> Option<&[ZPackedReadOnlyAddress]>;
1919
fn is_compress(&self) -> bool;
@@ -25,7 +25,7 @@ pub trait InstructionDataTrait<'a> {
2525
fn with_transaction_hash(&self) -> bool;
2626
}
2727

28-
pub trait NewAddressParamsTrait<'a>
28+
pub trait NewAddress<'a>
2929
where
3030
Self: Debug,
3131
{
@@ -36,7 +36,7 @@ where
3636
fn assigned_compressed_account_index(&self) -> Option<usize>;
3737
}
3838

39-
pub trait InputAccountTrait<'a>
39+
pub trait InputAccount<'a>
4040
where
4141
Self: Debug,
4242
{
@@ -57,7 +57,7 @@ where
5757
fn root_index(&self) -> u16;
5858
}
5959

60-
pub trait OutputAccountTrait<'a>
60+
pub trait OutputAccount<'a>
6161
where
6262
Self: Debug,
6363
{

program-libs/compressed-account/src/instruction_data/with_account_info.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ use super::{
1010
compressed_proof::CompressedProof,
1111
cpi_context::CompressedCpiContext,
1212
data::{NewAddressParamsAssignedPacked, PackedReadOnlyAddress},
13-
traits::{
14-
AccountOptions, InputAccountTrait, InstructionDataTrait, NewAddressParamsTrait,
15-
OutputAccountTrait,
16-
},
13+
traits::{AccountOptions, InputAccount, InstructionData, NewAddress, OutputAccount},
1714
with_readonly::ZInstructionDataInvokeCpiWithReadOnlyMeta,
1815
zero_copy::{
1916
ZNewAddressParamsAssignedPacked, ZPackedMerkleContext, ZPackedReadOnlyAddress,
@@ -70,7 +67,7 @@ pub struct OutAccountInfo {
7067
pub data: Vec<u8>,
7168
}
7269

73-
impl<'a> InputAccountTrait<'a> for ZCAccountInfo<'a> {
70+
impl<'a> InputAccount<'a> for ZCAccountInfo<'a> {
7471
fn owner(&self) -> &Pubkey {
7572
&self.owner
7673
}
@@ -123,7 +120,7 @@ impl<'a> InputAccountTrait<'a> for ZCAccountInfo<'a> {
123120
}
124121
}
125122

126-
impl<'a> OutputAccountTrait<'a> for ZCAccountInfo<'a> {
123+
impl<'a> OutputAccount<'a> for ZCAccountInfo<'a> {
127124
fn lamports(&self) -> u64 {
128125
self.output.as_ref().unwrap().lamports.into()
129126
}
@@ -298,7 +295,7 @@ pub struct InstructionDataInvokeCpiWithAccountInfo {
298295
pub read_only_accounts: Vec<PackedReadOnlyCompressedAccount>,
299296
}
300297

301-
impl<'a> InstructionDataTrait<'a> for ZInstructionDataInvokeCpiWithAccountInfo<'a> {
298+
impl<'a> InstructionData<'a> for ZInstructionDataInvokeCpiWithAccountInfo<'a> {
302299
fn bump(&self) -> Option<u8> {
303300
Some(self.bump)
304301
}
@@ -328,7 +325,7 @@ impl<'a> InstructionDataTrait<'a> for ZInstructionDataInvokeCpiWithAccountInfo<'
328325
self.meta.invoking_program_id
329326
}
330327

331-
fn new_addresses(&self) -> &[impl NewAddressParamsTrait<'a>] {
328+
fn new_addresses(&self) -> &[impl NewAddress<'a>] {
332329
self.new_address_params.as_slice()
333330
}
334331

@@ -352,11 +349,11 @@ impl<'a> InstructionDataTrait<'a> for ZInstructionDataInvokeCpiWithAccountInfo<'
352349
!self.meta.is_decompress()
353350
}
354351

355-
fn input_accounts(&self) -> &[impl InputAccountTrait<'a>] {
352+
fn input_accounts(&self) -> &[impl InputAccount<'a>] {
356353
self.account_infos.as_slice()
357354
}
358355

359-
fn output_accounts(&self) -> &[impl super::traits::OutputAccountTrait<'a>] {
356+
fn output_accounts(&self) -> &[impl super::traits::OutputAccount<'a>] {
360357
self.account_infos.as_slice()
361358
}
362359

program-libs/compressed-account/src/instruction_data/with_readonly.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use super::{
1313
NewAddressParamsAssignedPacked, OutputCompressedAccountWithPackedContext,
1414
PackedReadOnlyAddress,
1515
},
16-
traits::{AccountOptions, InputAccountTrait, InstructionDataTrait, NewAddressParamsTrait},
16+
traits::{AccountOptions, InputAccount, InstructionData, NewAddress},
1717
zero_copy::{
1818
ZCompressedCpiContext, ZNewAddressParamsAssignedPacked,
1919
ZOutputCompressedAccountWithPackedContext, ZPackedMerkleContext, ZPackedReadOnlyAddress,
@@ -67,7 +67,7 @@ impl From<PackedCompressedAccountWithMerkleContext> for InAccount {
6767
}
6868
}
6969

70-
impl<'a> InputAccountTrait<'a> for ZInAccount<'a> {
70+
impl<'a> InputAccount<'a> for ZInAccount<'a> {
7171
fn owner(&self) -> &Pubkey {
7272
&self.owner
7373
}
@@ -253,7 +253,7 @@ pub struct ZInstructionDataInvokeCpiWithReadOnly<'a> {
253253
pub read_only_accounts: ZeroCopySliceBorsh<'a, ZPackedReadOnlyCompressedAccount>,
254254
}
255255

256-
impl<'a> InstructionDataTrait<'a> for ZInstructionDataInvokeCpiWithReadOnly<'a> {
256+
impl<'a> InstructionData<'a> for ZInstructionDataInvokeCpiWithReadOnly<'a> {
257257
fn account_option_config(&self) -> AccountOptions {
258258
AccountOptions {
259259
sol_pool_pda: self.is_compress(),
@@ -282,7 +282,7 @@ impl<'a> InstructionDataTrait<'a> for ZInstructionDataInvokeCpiWithReadOnly<'a>
282282
self.meta.invoking_program_id
283283
}
284284

285-
fn new_addresses(&self) -> &[impl NewAddressParamsTrait<'a>] {
285+
fn new_addresses(&self) -> &[impl NewAddress<'a>] {
286286
self.new_address_params.as_slice()
287287
}
288288

@@ -306,11 +306,11 @@ impl<'a> InstructionDataTrait<'a> for ZInstructionDataInvokeCpiWithReadOnly<'a>
306306
!self.meta.is_decompress() && self.compress_or_decompress_lamports().is_some()
307307
}
308308

309-
fn input_accounts(&self) -> &[impl InputAccountTrait<'a>] {
309+
fn input_accounts(&self) -> &[impl InputAccount<'a>] {
310310
self.input_compressed_accounts.as_slice()
311311
}
312312

313-
fn output_accounts(&self) -> &[impl super::traits::OutputAccountTrait<'a>] {
313+
fn output_accounts(&self) -> &[impl super::traits::OutputAccount<'a>] {
314314
self.output_compressed_accounts.as_slice()
315315
}
316316

program-libs/compressed-account/src/instruction_data/zero_copy.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ use zerocopy::{
88

99
use super::{
1010
invoke_cpi::InstructionDataInvokeCpi,
11-
traits::{
12-
AccountOptions, InputAccountTrait, InstructionDataTrait, NewAddressParamsTrait,
13-
OutputAccountTrait,
14-
},
11+
traits::{AccountOptions, InputAccount, InstructionData, NewAddress, OutputAccount},
1512
};
1613
use crate::{
1714
compressed_account::{
@@ -64,7 +61,7 @@ pub struct ZNewAddressParamsPacked {
6461
pub address_merkle_tree_root_index: U16,
6562
}
6663

67-
impl NewAddressParamsTrait<'_> for ZNewAddressParamsPacked {
64+
impl NewAddress<'_> for ZNewAddressParamsPacked {
6865
fn seed(&self) -> [u8; 32] {
6966
self.seed
7067
}
@@ -117,7 +114,7 @@ pub struct ZOutputCompressedAccountWithPackedContext<'a> {
117114
pub merkle_tree_index: u8,
118115
}
119116

120-
impl<'a> OutputAccountTrait<'a> for ZOutputCompressedAccountWithPackedContext<'a> {
117+
impl<'a> OutputAccount<'a> for ZOutputCompressedAccountWithPackedContext<'a> {
121118
fn lamports(&self) -> u64 {
122119
self.compressed_account.lamports.into()
123120
}
@@ -332,7 +329,7 @@ pub struct ZPackedCompressedAccountWithMerkleContext<'a> {
332329
meta: Ref<&'a [u8], ZPackedCompressedAccountWithMerkleContextMeta>,
333330
}
334331

335-
impl<'a> InputAccountTrait<'a> for ZPackedCompressedAccountWithMerkleContext<'a> {
332+
impl<'a> InputAccount<'a> for ZPackedCompressedAccountWithMerkleContext<'a> {
336333
fn owner(&self) -> &crate::pubkey::Pubkey {
337334
&self.compressed_account.owner
338335
}
@@ -428,7 +425,7 @@ pub struct ZInstructionDataInvoke<'a> {
428425
pub is_compress: bool,
429426
}
430427

431-
impl<'a> InstructionDataTrait<'a> for ZInstructionDataInvoke<'a> {
428+
impl<'a> InstructionData<'a> for ZInstructionDataInvoke<'a> {
432429
fn bump(&self) -> Option<u8> {
433430
None
434431
}
@@ -467,16 +464,16 @@ impl<'a> InstructionDataTrait<'a> for ZInstructionDataInvoke<'a> {
467464
}
468465
}
469466

470-
fn new_addresses(&self) -> &[impl NewAddressParamsTrait<'a>] {
467+
fn new_addresses(&self) -> &[impl NewAddress<'a>] {
471468
self.new_address_params.as_slice()
472469
}
473470

474-
fn input_accounts(&self) -> &[impl InputAccountTrait<'a>] {
471+
fn input_accounts(&self) -> &[impl InputAccount<'a>] {
475472
self.input_compressed_accounts_with_merkle_context
476473
.as_slice()
477474
}
478475

479-
fn output_accounts(&self) -> &[impl OutputAccountTrait<'a>] {
476+
fn output_accounts(&self) -> &[impl OutputAccount<'a>] {
480477
self.output_compressed_accounts.as_slice()
481478
}
482479

@@ -544,7 +541,7 @@ impl ZInstructionDataInvokeCpi<'_> {
544541
}
545542
}
546543

547-
impl<'a> InstructionDataTrait<'a> for ZInstructionDataInvokeCpi<'a> {
544+
impl<'a> InstructionData<'a> for ZInstructionDataInvokeCpi<'a> {
548545
fn bump(&self) -> Option<u8> {
549546
None
550547
}
@@ -591,15 +588,15 @@ impl<'a> InstructionDataTrait<'a> for ZInstructionDataInvokeCpi<'a> {
591588
self.proof
592589
}
593590

594-
fn new_addresses(&self) -> &[impl NewAddressParamsTrait<'a>] {
591+
fn new_addresses(&self) -> &[impl NewAddress<'a>] {
595592
self.new_address_params.as_slice()
596593
}
597594

598-
fn output_accounts(&self) -> &[impl OutputAccountTrait<'a>] {
595+
fn output_accounts(&self) -> &[impl OutputAccount<'a>] {
599596
self.output_compressed_accounts.as_slice()
600597
}
601598

602-
fn input_accounts(&self) -> &[impl InputAccountTrait<'a>] {
599+
fn input_accounts(&self) -> &[impl InputAccount<'a>] {
603600
self.input_compressed_accounts_with_merkle_context
604601
.as_slice()
605602
}
@@ -776,7 +773,7 @@ pub struct ZNewAddressParamsAssignedPacked {
776773
pub assigned_account_index: u8,
777774
}
778775

779-
impl NewAddressParamsTrait<'_> for ZNewAddressParamsAssignedPacked {
776+
impl NewAddress<'_> for ZNewAddressParamsAssignedPacked {
780777
fn seed(&self) -> [u8; 32] {
781778
self.seed
782779
}

programs/system/src/context.rs

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use light_compressed_account::{
55
cpi_context::CompressedCpiContext,
66
data::{NewAddressParamsPacked, OutputCompressedAccountWithPackedContext},
77
invoke_cpi::InstructionDataInvokeCpi,
8-
traits::{
9-
InputAccountTrait, InstructionDataTrait, NewAddressParamsTrait, OutputAccountTrait,
10-
},
8+
traits::{InputAccount, InstructionData, NewAddress, OutputAccount},
119
zero_copy::{ZPackedReadOnlyAddress, ZPackedReadOnlyCompressedAccount},
1210
},
1311
};
@@ -135,15 +133,15 @@ impl<'info> SystemContext<'info> {
135133
}
136134
}
137135

138-
pub struct WrappedInstructionData<'a, T: InstructionDataTrait<'a>> {
136+
pub struct WrappedInstructionData<'a, T: InstructionData<'a>> {
139137
instruction_data: T,
140138
cpi_context: Option<ZCpiContextAccount<'a>>,
141139
address_len: usize,
142140
input_len: usize,
143141
outputs_len: usize,
144142
}
145143

146-
impl<'a, 'b, T: InstructionDataTrait<'a>> WrappedInstructionData<'a, T> {
144+
impl<'a, 'b, T: InstructionData<'a>> WrappedInstructionData<'a, T> {
147145
pub fn new(instruction_data: T) -> Self {
148146
Self {
149147
input_len: instruction_data.input_accounts().len(),
@@ -205,10 +203,7 @@ impl<'a, 'b, T: InstructionDataTrait<'a>> WrappedInstructionData<'a, T> {
205203
self.instruction_data.with_transaction_hash()
206204
}
207205

208-
pub fn get_output_account(
209-
&'b self,
210-
index: usize,
211-
) -> Option<&'b (impl OutputAccountTrait<'a> + 'b)> {
206+
pub fn get_output_account(&'b self, index: usize) -> Option<&'b (impl OutputAccount<'a> + 'b)> {
212207
if index > self.instruction_data.output_accounts().len() {
213208
None
214209
} else {
@@ -217,7 +212,7 @@ impl<'a, 'b, T: InstructionDataTrait<'a>> WrappedInstructionData<'a, T> {
217212
}
218213
}
219214

220-
impl<'a, T: InstructionDataTrait<'a>> WrappedInstructionData<'a, T> {
215+
impl<'a, T: InstructionData<'a>> WrappedInstructionData<'a, T> {
221216
pub fn owner(&self) -> light_compressed_account::pubkey::Pubkey {
222217
self.instruction_data.owner()
223218
}
@@ -238,9 +233,7 @@ impl<'a, T: InstructionDataTrait<'a>> WrappedInstructionData<'a, T> {
238233
self.instruction_data.compress_or_decompress_lamports()
239234
}
240235

241-
pub fn new_addresses<'b>(
242-
&'b self,
243-
) -> impl Iterator<Item = &'b (dyn NewAddressParamsTrait<'a> + 'b)> {
236+
pub fn new_addresses<'b>(&'b self) -> impl Iterator<Item = &'b (dyn NewAddress<'a> + 'b)> {
244237
if let Some(cpi_context) = &self.cpi_context {
245238
if cpi_context.context.len() > 1 {
246239
panic!("Cpi context len > 1");
@@ -255,9 +248,7 @@ impl<'a, T: InstructionDataTrait<'a>> WrappedInstructionData<'a, T> {
255248
}
256249
}
257250

258-
pub fn output_accounts<'b>(
259-
&'b self,
260-
) -> impl Iterator<Item = &'b (dyn OutputAccountTrait<'a> + 'b)> {
251+
pub fn output_accounts<'b>(&'b self) -> impl Iterator<Item = &'b (dyn OutputAccount<'a> + 'b)> {
261252
if let Some(cpi_context) = &self.cpi_context {
262253
if cpi_context.context.len() > 1 {
263254
panic!("Cpi context len > 1");
@@ -271,9 +262,7 @@ impl<'a, T: InstructionDataTrait<'a>> WrappedInstructionData<'a, T> {
271262
}
272263
}
273264

274-
pub fn input_accounts<'b>(
275-
&'b self,
276-
) -> impl Iterator<Item = &'b (dyn InputAccountTrait<'a> + 'b)> {
265+
pub fn input_accounts<'b>(&'b self) -> impl Iterator<Item = &'b (dyn InputAccount<'a> + 'b)> {
277266
if let Some(cpi_context) = &self.cpi_context {
278267
if cpi_context.context.len() > 1 {
279268
panic!("Cpi context len > 1");
@@ -358,39 +347,31 @@ impl<'a, T: InstructionDataTrait<'a>> WrappedInstructionData<'a, T> {
358347
}
359348

360349
pub fn chain_outputs<'a, 'b: 'a>(
361-
slice1: &'a [impl OutputAccountTrait<'b>],
362-
slice2: &'a [impl OutputAccountTrait<'b>],
363-
) -> impl Iterator<Item = &'a (dyn OutputAccountTrait<'b> + 'a)> {
350+
slice1: &'a [impl OutputAccount<'b>],
351+
slice2: &'a [impl OutputAccount<'b>],
352+
) -> impl Iterator<Item = &'a (dyn OutputAccount<'b> + 'a)> {
364353
slice1
365354
.iter()
366-
.map(|item| item as &dyn OutputAccountTrait<'b>)
367-
.chain(
368-
slice2
369-
.iter()
370-
.map(|item| item as &dyn OutputAccountTrait<'b>),
371-
)
355+
.map(|item| item as &dyn OutputAccount<'b>)
356+
.chain(slice2.iter().map(|item| item as &dyn OutputAccount<'b>))
372357
}
373358

374359
pub fn chain_inputs<'a, 'b: 'a>(
375-
slice1: &'a [impl InputAccountTrait<'b>],
376-
slice2: &'a [impl InputAccountTrait<'b>],
377-
) -> impl Iterator<Item = &'a (dyn InputAccountTrait<'b> + 'a)> {
360+
slice1: &'a [impl InputAccount<'b>],
361+
slice2: &'a [impl InputAccount<'b>],
362+
) -> impl Iterator<Item = &'a (dyn InputAccount<'b> + 'a)> {
378363
slice1
379364
.iter()
380-
.map(|item| item as &dyn InputAccountTrait<'b>)
381-
.chain(slice2.iter().map(|item| item as &dyn InputAccountTrait<'b>))
365+
.map(|item| item as &dyn InputAccount<'b>)
366+
.chain(slice2.iter().map(|item| item as &dyn InputAccount<'b>))
382367
}
383368

384369
pub fn chain_new_addresses<'a, 'b: 'a>(
385-
slice1: &'a [impl NewAddressParamsTrait<'b>],
386-
slice2: &'a [impl NewAddressParamsTrait<'b>],
387-
) -> impl Iterator<Item = &'a (dyn NewAddressParamsTrait<'b> + 'a)> {
370+
slice1: &'a [impl NewAddress<'b>],
371+
slice2: &'a [impl NewAddress<'b>],
372+
) -> impl Iterator<Item = &'a (dyn NewAddress<'b> + 'a)> {
388373
slice1
389374
.iter()
390-
.map(|item| item as &dyn NewAddressParamsTrait<'b>)
391-
.chain(
392-
slice2
393-
.iter()
394-
.map(|item| item as &dyn NewAddressParamsTrait<'b>),
395-
)
375+
.map(|item| item as &dyn NewAddress<'b>)
376+
.chain(slice2.iter().map(|item| item as &dyn NewAddress<'b>))
396377
}

0 commit comments

Comments
 (0)