Skip to content

Commit 8e6ff73

Browse files
committed
fix: don't generate borsh::to_vec if no borsh traits
1 parent b6ed330 commit 8e6ff73

29 files changed

+458
-88
lines changed

e2e/anchor/src/generated/instructions/create_guard.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ impl CreateGuard {
6969
false,
7070
));
7171
accounts.extend_from_slice(remaining_accounts);
72-
let mut data = borsh::to_vec(&CreateGuardInstructionData::new()).unwrap();
73-
let mut args = borsh::to_vec(&args).unwrap();
72+
let mut data = CreateGuardInstructionData::new().try_to_vec().unwrap();
73+
let mut args = args.try_to_vec().unwrap();
7474
data.append(&mut args);
7575

7676
solana_instruction::Instruction {
@@ -93,6 +93,10 @@ impl CreateGuardInstructionData {
9393
discriminator: [251, 254, 17, 198, 219, 218, 154, 99],
9494
}
9595
}
96+
97+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
98+
borsh::to_vec(self)
99+
}
96100
}
97101

98102
impl Default for CreateGuardInstructionData {
@@ -112,6 +116,12 @@ pub struct CreateGuardInstructionArgs {
112116
pub additional_fields_rule: Vec<MetadataAdditionalFieldRule>,
113117
}
114118

119+
impl CreateGuardInstructionArgs {
120+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
121+
borsh::to_vec(self)
122+
}
123+
}
124+
115125
/// Instruction builder for `CreateGuard`.
116126
///
117127
/// ### Accounts:
@@ -395,8 +405,8 @@ impl<'a, 'b> CreateGuardCpi<'a, 'b> {
395405
is_writable: remaining_account.2,
396406
})
397407
});
398-
let mut data = borsh::to_vec(&CreateGuardInstructionData::new()).unwrap();
399-
let mut args = borsh::to_vec(&self.__args).unwrap();
408+
let mut data = CreateGuardInstructionData::new().try_to_vec().unwrap();
409+
let mut args = self.__args.try_to_vec().unwrap();
400410
data.append(&mut args);
401411

402412
let instruction = solana_instruction::Instruction {

e2e/anchor/src/generated/instructions/execute.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ impl Execute {
6767
false,
6868
));
6969
accounts.extend_from_slice(remaining_accounts);
70-
let mut data = borsh::to_vec(&ExecuteInstructionData::new()).unwrap();
71-
let mut args = borsh::to_vec(&args).unwrap();
70+
let mut data = ExecuteInstructionData::new().try_to_vec().unwrap();
71+
let mut args = args.try_to_vec().unwrap();
7272
data.append(&mut args);
7373

7474
solana_instruction::Instruction {
@@ -91,6 +91,10 @@ impl ExecuteInstructionData {
9191
discriminator: [105, 37, 101, 197, 75, 251, 102, 26],
9292
}
9393
}
94+
95+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
96+
borsh::to_vec(self)
97+
}
9498
}
9599

96100
impl Default for ExecuteInstructionData {
@@ -105,6 +109,12 @@ pub struct ExecuteInstructionArgs {
105109
pub amount: u64,
106110
}
107111

112+
impl ExecuteInstructionArgs {
113+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
114+
borsh::to_vec(self)
115+
}
116+
}
117+
108118
/// Instruction builder for `Execute`.
109119
///
110120
/// ### Accounts:
@@ -333,8 +343,8 @@ impl<'a, 'b> ExecuteCpi<'a, 'b> {
333343
is_writable: remaining_account.2,
334344
})
335345
});
336-
let mut data = borsh::to_vec(&ExecuteInstructionData::new()).unwrap();
337-
let mut args = borsh::to_vec(&self.__args).unwrap();
346+
let mut data = ExecuteInstructionData::new().try_to_vec().unwrap();
347+
let mut args = self.__args.try_to_vec().unwrap();
338348
data.append(&mut args);
339349

340350
let instruction = solana_instruction::Instruction {

e2e/anchor/src/generated/instructions/initialize.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Initialize {
5757
));
5858
accounts.push(solana_instruction::AccountMeta::new(self.payer, true));
5959
accounts.extend_from_slice(remaining_accounts);
60-
let data = borsh::to_vec(&InitializeInstructionData::new()).unwrap();
60+
let data = InitializeInstructionData::new().try_to_vec().unwrap();
6161

6262
solana_instruction::Instruction {
6363
program_id: crate::WEN_TRANSFER_GUARD_ID,
@@ -79,6 +79,10 @@ impl InitializeInstructionData {
7979
discriminator: [43, 34, 13, 49, 167, 88, 235, 235],
8080
}
8181
}
82+
83+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
84+
borsh::to_vec(self)
85+
}
8286
}
8387

8488
impl Default for InitializeInstructionData {
@@ -282,7 +286,7 @@ impl<'a, 'b> InitializeCpi<'a, 'b> {
282286
is_writable: remaining_account.2,
283287
})
284288
});
285-
let data = borsh::to_vec(&InitializeInstructionData::new()).unwrap();
289+
let data = InitializeInstructionData::new().try_to_vec().unwrap();
286290

287291
let instruction = solana_instruction::Instruction {
288292
program_id: crate::WEN_TRANSFER_GUARD_ID,

e2e/anchor/src/generated/instructions/update_guard.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ impl UpdateGuard {
6262
false,
6363
));
6464
accounts.extend_from_slice(remaining_accounts);
65-
let mut data = borsh::to_vec(&UpdateGuardInstructionData::new()).unwrap();
66-
let mut args = borsh::to_vec(&args).unwrap();
65+
let mut data = UpdateGuardInstructionData::new().try_to_vec().unwrap();
66+
let mut args = args.try_to_vec().unwrap();
6767
data.append(&mut args);
6868

6969
solana_instruction::Instruction {
@@ -86,6 +86,10 @@ impl UpdateGuardInstructionData {
8686
discriminator: [51, 38, 175, 180, 25, 249, 39, 24],
8787
}
8888
}
89+
90+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
91+
borsh::to_vec(self)
92+
}
8993
}
9094

9195
impl Default for UpdateGuardInstructionData {
@@ -102,6 +106,12 @@ pub struct UpdateGuardInstructionArgs {
102106
pub additional_fields_rule: Vec<MetadataAdditionalFieldRule>,
103107
}
104108

109+
impl UpdateGuardInstructionArgs {
110+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
111+
borsh::to_vec(self)
112+
}
113+
}
114+
105115
/// Instruction builder for `UpdateGuard`.
106116
///
107117
/// ### Accounts:
@@ -328,8 +338,8 @@ impl<'a, 'b> UpdateGuardCpi<'a, 'b> {
328338
is_writable: remaining_account.2,
329339
})
330340
});
331-
let mut data = borsh::to_vec(&UpdateGuardInstructionData::new()).unwrap();
332-
let mut args = borsh::to_vec(&self.__args).unwrap();
341+
let mut data = UpdateGuardInstructionData::new().try_to_vec().unwrap();
342+
let mut args = self.__args.try_to_vec().unwrap();
333343
data.append(&mut args);
334344

335345
let instruction = solana_instruction::Instruction {

e2e/dummy/src/generated/instructions/instruction1.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl Instruction1 {
2424
) -> solana_instruction::Instruction {
2525
let mut accounts = Vec::with_capacity(remaining_accounts.len());
2626
accounts.extend_from_slice(remaining_accounts);
27-
let data = borsh::to_vec(&Instruction1InstructionData::new()).unwrap();
27+
let data = Instruction1InstructionData::new().try_to_vec().unwrap();
2828

2929
solana_instruction::Instruction {
3030
program_id: crate::DUMMY_ID,
@@ -42,6 +42,10 @@ impl Instruction1InstructionData {
4242
pub fn new() -> Self {
4343
Self {}
4444
}
45+
46+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
47+
borsh::to_vec(self)
48+
}
4549
}
4650

4751
impl Default for Instruction1InstructionData {
@@ -127,7 +131,7 @@ impl<'a, 'b> Instruction1Cpi<'a, 'b> {
127131
is_writable: remaining_account.2,
128132
})
129133
});
130-
let data = borsh::to_vec(&Instruction1InstructionData::new()).unwrap();
134+
let data = Instruction1InstructionData::new().try_to_vec().unwrap();
131135

132136
let instruction = solana_instruction::Instruction {
133137
program_id: crate::DUMMY_ID,

e2e/dummy/src/generated/instructions/instruction2.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl Instruction2 {
2424
) -> solana_instruction::Instruction {
2525
let mut accounts = Vec::with_capacity(remaining_accounts.len());
2626
accounts.extend_from_slice(remaining_accounts);
27-
let data = borsh::to_vec(&Instruction2InstructionData::new()).unwrap();
27+
let data = Instruction2InstructionData::new().try_to_vec().unwrap();
2828

2929
solana_instruction::Instruction {
3030
program_id: crate::DUMMY_ID,
@@ -42,6 +42,10 @@ impl Instruction2InstructionData {
4242
pub fn new() -> Self {
4343
Self {}
4444
}
45+
46+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
47+
borsh::to_vec(self)
48+
}
4549
}
4650

4751
impl Default for Instruction2InstructionData {
@@ -127,7 +131,7 @@ impl<'a, 'b> Instruction2Cpi<'a, 'b> {
127131
is_writable: remaining_account.2,
128132
})
129133
});
130-
let data = borsh::to_vec(&Instruction2InstructionData::new()).unwrap();
134+
let data = Instruction2InstructionData::new().try_to_vec().unwrap();
131135

132136
let instruction = solana_instruction::Instruction {
133137
program_id: crate::DUMMY_ID,

e2e/dummy/src/generated/instructions/instruction3.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Instruction3 {
2626
) -> solana_instruction::Instruction {
2727
let mut accounts = Vec::with_capacity(remaining_accounts.len());
2828
accounts.extend_from_slice(remaining_accounts);
29-
let data = borsh::to_vec(&Instruction3InstructionData::new()).unwrap();
29+
let data = Instruction3InstructionData::new().try_to_vec().unwrap();
3030

3131
solana_instruction::Instruction {
3232
program_id: crate::DUMMY_ID,
@@ -46,6 +46,10 @@ impl Instruction3InstructionData {
4646
pub fn new() -> Self {
4747
Self { discriminator: 42 }
4848
}
49+
50+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
51+
borsh::to_vec(self)
52+
}
4953
}
5054

5155
impl Default for Instruction3InstructionData {
@@ -131,7 +135,7 @@ impl<'a, 'b> Instruction3Cpi<'a, 'b> {
131135
is_writable: remaining_account.2,
132136
})
133137
});
134-
let data = borsh::to_vec(&Instruction3InstructionData::new()).unwrap();
138+
let data = Instruction3InstructionData::new().try_to_vec().unwrap();
135139

136140
let instruction = solana_instruction::Instruction {
137141
program_id: crate::DUMMY_ID,

e2e/dummy/src/generated/instructions/instruction4.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ impl Instruction4 {
2828
) -> solana_instruction::Instruction {
2929
let mut accounts = Vec::with_capacity(remaining_accounts.len());
3030
accounts.extend_from_slice(remaining_accounts);
31-
let mut data = borsh::to_vec(&Instruction4InstructionData::new()).unwrap();
32-
let mut args = borsh::to_vec(&args).unwrap();
31+
let mut data = Instruction4InstructionData::new().try_to_vec().unwrap();
32+
let mut args = args.try_to_vec().unwrap();
3333
data.append(&mut args);
3434

3535
solana_instruction::Instruction {
@@ -48,6 +48,10 @@ impl Instruction4InstructionData {
4848
pub fn new() -> Self {
4949
Self {}
5050
}
51+
52+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
53+
borsh::to_vec(self)
54+
}
5155
}
5256

5357
impl Default for Instruction4InstructionData {
@@ -62,6 +66,12 @@ pub struct Instruction4InstructionArgs {
6266
pub my_argument: u64,
6367
}
6468

69+
impl Instruction4InstructionArgs {
70+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
71+
borsh::to_vec(self)
72+
}
73+
}
74+
6575
/// Instruction builder for `Instruction4`.
6676
///
6777
/// ### Accounts:
@@ -156,8 +166,8 @@ impl<'a, 'b> Instruction4Cpi<'a, 'b> {
156166
is_writable: remaining_account.2,
157167
})
158168
});
159-
let mut data = borsh::to_vec(&Instruction4InstructionData::new()).unwrap();
160-
let mut args = borsh::to_vec(&self.__args).unwrap();
169+
let mut data = Instruction4InstructionData::new().try_to_vec().unwrap();
170+
let mut args = self.__args.try_to_vec().unwrap();
161171
data.append(&mut args);
162172

163173
let instruction = solana_instruction::Instruction {

e2e/dummy/src/generated/instructions/instruction5.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ impl Instruction5 {
2828
) -> solana_instruction::Instruction {
2929
let mut accounts = Vec::with_capacity(remaining_accounts.len());
3030
accounts.extend_from_slice(remaining_accounts);
31-
let mut data = borsh::to_vec(&Instruction5InstructionData::new()).unwrap();
32-
let mut args = borsh::to_vec(&args).unwrap();
31+
let mut data = Instruction5InstructionData::new().try_to_vec().unwrap();
32+
let mut args = args.try_to_vec().unwrap();
3333
data.append(&mut args);
3434

3535
solana_instruction::Instruction {
@@ -48,6 +48,10 @@ impl Instruction5InstructionData {
4848
pub fn new() -> Self {
4949
Self {}
5050
}
51+
52+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
53+
borsh::to_vec(self)
54+
}
5155
}
5256

5357
impl Default for Instruction5InstructionData {
@@ -62,6 +66,12 @@ pub struct Instruction5InstructionArgs {
6266
pub my_argument: u64,
6367
}
6468

69+
impl Instruction5InstructionArgs {
70+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
71+
borsh::to_vec(self)
72+
}
73+
}
74+
6575
/// Instruction builder for `Instruction5`.
6676
///
6777
/// ### Accounts:
@@ -157,8 +167,8 @@ impl<'a, 'b> Instruction5Cpi<'a, 'b> {
157167
is_writable: remaining_account.2,
158168
})
159169
});
160-
let mut data = borsh::to_vec(&Instruction5InstructionData::new()).unwrap();
161-
let mut args = borsh::to_vec(&self.__args).unwrap();
170+
let mut data = Instruction5InstructionData::new().try_to_vec().unwrap();
171+
let mut args = self.__args.try_to_vec().unwrap();
162172
data.append(&mut args);
163173

164174
let instruction = solana_instruction::Instruction {

e2e/dummy/src/generated/instructions/instruction6.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Instruction6 {
2727
let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
2828
accounts.push(solana_instruction::AccountMeta::new(self.my_account, false));
2929
accounts.extend_from_slice(remaining_accounts);
30-
let data = borsh::to_vec(&Instruction6InstructionData::new()).unwrap();
30+
let data = Instruction6InstructionData::new().try_to_vec().unwrap();
3131

3232
solana_instruction::Instruction {
3333
program_id: crate::DUMMY_ID,
@@ -45,6 +45,10 @@ impl Instruction6InstructionData {
4545
pub fn new() -> Self {
4646
Self {}
4747
}
48+
49+
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
50+
borsh::to_vec(self)
51+
}
4852
}
4953

5054
impl Default for Instruction6InstructionData {
@@ -156,7 +160,7 @@ impl<'a, 'b> Instruction6Cpi<'a, 'b> {
156160
is_writable: remaining_account.2,
157161
})
158162
});
159-
let data = borsh::to_vec(&Instruction6InstructionData::new()).unwrap();
163+
let data = Instruction6InstructionData::new().try_to_vec().unwrap();
160164

161165
let instruction = solana_instruction::Instruction {
162166
program_id: crate::DUMMY_ID,

0 commit comments

Comments
 (0)