Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 801bb9c

Browse files
committed
replace deprecated try_to_vec with borsh::to_vec
1 parent 59c3718 commit 801bb9c

File tree

44 files changed

+222
-326
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+222
-326
lines changed

associated-token-account/program/src/instruction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn build_associated_token_account_instruction(
8484
AccountMeta::new_readonly(solana_program::system_program::id(), false),
8585
AccountMeta::new_readonly(*token_program_id, false),
8686
],
87-
data: instruction.try_to_vec().unwrap(),
87+
data: borsh::to_vec(&instruction).unwrap(),
8888
}
8989
}
9090

@@ -156,6 +156,6 @@ pub fn recover_nested(
156156
AccountMeta::new(*wallet_address, true),
157157
AccountMeta::new_readonly(*token_program_id, false),
158158
],
159-
data: instruction_data.try_to_vec().unwrap(),
159+
data: borsh::to_vec(&instruction_data).unwrap(),
160160
}
161161
}

binary-option/program/src/instruction.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ pub fn initialize_binary_option(
6060
AccountMeta::new_readonly(solana_program::system_program::id(), false),
6161
AccountMeta::new_readonly(sysvar::rent::id(), false),
6262
],
63-
data: BinaryOptionInstruction::InitializeBinaryOption(InitializeBinaryOptionArgs {
64-
decimals,
65-
})
66-
.try_to_vec()
63+
data: borsh::to_vec(&BinaryOptionInstruction::InitializeBinaryOption(
64+
InitializeBinaryOptionArgs { decimals },
65+
))
6766
.unwrap(),
6867
}
6968
}
@@ -107,12 +106,11 @@ pub fn trade(
107106
AccountMeta::new_readonly(escrow_authority, false),
108107
AccountMeta::new_readonly(spl_token::id(), false),
109108
],
110-
data: BinaryOptionInstruction::Trade(TradeArgs {
109+
data: borsh::to_vec(&BinaryOptionInstruction::Trade(TradeArgs {
111110
size,
112111
buy_price,
113112
sell_price,
114-
})
115-
.try_to_vec()
113+
}))
116114
.unwrap(),
117115
}
118116
}
@@ -131,7 +129,7 @@ pub fn settle(
131129
AccountMeta::new_readonly(winning_mint, false),
132130
AccountMeta::new_readonly(pool_authority, true),
133131
],
134-
data: BinaryOptionInstruction::Settle.try_to_vec().unwrap(),
132+
data: borsh::to_vec(&BinaryOptionInstruction::Settle).unwrap(),
135133
}
136134
}
137135

@@ -167,6 +165,6 @@ pub fn collect(
167165
AccountMeta::new_readonly(solana_program::system_program::id(), false),
168166
AccountMeta::new_readonly(sysvar::rent::id(), false),
169167
],
170-
data: BinaryOptionInstruction::Collect.try_to_vec().unwrap(),
168+
data: borsh::to_vec(&BinaryOptionInstruction::Collect).unwrap(),
171169
}
172170
}

binary-oracle-pair/program/src/instruction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub fn init_pool(
102102
init_args: InitArgs,
103103
) -> Result<Instruction, ProgramError> {
104104
let init_data = PoolInstruction::InitPool(init_args);
105-
let data = init_data.try_to_vec()?;
105+
let data = borsh::to_vec(&init_data)?;
106106
let accounts = vec![
107107
AccountMeta::new(*pool, false),
108108
AccountMeta::new_readonly(*authority, false),
@@ -138,7 +138,7 @@ pub fn deposit(
138138
amount: u64,
139139
) -> Result<Instruction, ProgramError> {
140140
let init_data = PoolInstruction::Deposit(amount);
141-
let data = init_data.try_to_vec()?;
141+
let data = borsh::to_vec(&init_data)?;
142142

143143
let accounts = vec![
144144
AccountMeta::new_readonly(*pool, false),
@@ -180,7 +180,7 @@ pub fn withdraw(
180180
amount: u64,
181181
) -> Result<Instruction, ProgramError> {
182182
let init_data = PoolInstruction::Withdraw(amount);
183-
let data = init_data.try_to_vec()?;
183+
let data = borsh::to_vec(&init_data)?;
184184
let accounts = vec![
185185
AccountMeta::new_readonly(*pool, false),
186186
AccountMeta::new_readonly(*authority, false),
@@ -212,7 +212,7 @@ pub fn decide(
212212
decision: bool,
213213
) -> Result<Instruction, ProgramError> {
214214
let init_data = PoolInstruction::Decide(decision);
215-
let data = init_data.try_to_vec()?;
215+
let data = borsh::to_vec(&init_data)?;
216216
let accounts = vec![
217217
AccountMeta::new(*pool, false),
218218
AccountMeta::new_readonly(*decider, true),

binary-oracle-pair/program/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ mod test {
8585
decision: Decision::Fail,
8686
};
8787

88-
let packed = p.try_to_vec().unwrap();
88+
let packed = borsh::to_vec(&p).unwrap();
8989

9090
let unpacked = Pool::try_from_slice(packed.as_slice()).unwrap();
9191

feature-proposal/program/src/instruction.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Pack for FeatureProposalInstruction {
107107

108108
impl FeatureProposalInstruction {
109109
fn pack_into_vec(&self) -> Vec<u8> {
110-
self.try_to_vec().expect("try_to_vec")
110+
borsh::to_vec(self).expect("try_to_vec")
111111
}
112112
}
113113

@@ -177,19 +177,18 @@ mod tests {
177177
#[test]
178178
fn test_serialize_bytes() {
179179
assert_eq!(
180-
FeatureProposalInstruction::Tally.try_to_vec().unwrap(),
180+
borsh::to_vec(&FeatureProposalInstruction::Tally).unwrap(),
181181
vec![1]
182182
);
183183

184184
assert_eq!(
185-
FeatureProposalInstruction::Propose {
185+
borsh::to_vec(&FeatureProposalInstruction::Propose {
186186
tokens_to_mint: 42,
187187
acceptance_criteria: AcceptanceCriteria {
188188
tokens_required: 0xdeadbeefdeadbeef,
189189
deadline: -1,
190190
}
191-
}
192-
.try_to_vec()
191+
})
193192
.unwrap(),
194193
vec![
195194
0, 42, 0, 0, 0, 0, 0, 0, 0, 239, 190, 173, 222, 239, 190, 173, 222, 255, 255, 255,

feature-proposal/program/src/state.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Pack for FeatureProposal {
4545
const LEN: usize = 17; // see `test_get_packed_len()` for justification of "18"
4646

4747
fn pack_into_slice(&self, dst: &mut [u8]) {
48-
let data = self.try_to_vec().unwrap();
48+
let data = borsh::to_vec(self).unwrap();
4949
dst[..data.len()].copy_from_slice(&data);
5050
}
5151

@@ -75,14 +75,13 @@ mod tests {
7575

7676
#[test]
7777
fn test_serialize_bytes() {
78-
assert_eq!(FeatureProposal::Expired.try_to_vec().unwrap(), vec![3]);
78+
assert_eq!(borsh::to_vec(&FeatureProposal::Expired).unwrap(), vec![3]);
7979

8080
assert_eq!(
81-
FeatureProposal::Pending(AcceptanceCriteria {
81+
borsh::to_vec(&FeatureProposal::Pending(AcceptanceCriteria {
8282
tokens_required: 0xdeadbeefdeadbeef,
8383
deadline: -1,
84-
})
85-
.try_to_vec()
84+
}))
8685
.unwrap(),
8786
vec![1, 239, 190, 173, 222, 239, 190, 173, 222, 255, 255, 255, 255, 255, 255, 255, 255],
8887
);

governance/addin-mock/program/src/instruction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn setup_voter_weight_record(
9696
Instruction {
9797
program_id: *program_id,
9898
accounts,
99-
data: instruction.try_to_vec().unwrap(),
99+
data: borsh::to_vec(&instruction).unwrap(),
100100
}
101101
}
102102

@@ -129,6 +129,6 @@ pub fn setup_max_voter_weight_record(
129129
Instruction {
130130
program_id: *program_id,
131131
accounts,
132-
data: instruction.try_to_vec().unwrap(),
132+
data: borsh::to_vec(&instruction).unwrap(),
133133
}
134134
}

governance/chat/program/src/instruction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ pub fn post_message(
9090
Instruction {
9191
program_id: *program_id,
9292
accounts,
93-
data: instruction.try_to_vec().unwrap(),
93+
data: borsh::to_vec(&instruction).unwrap(),
9494
}
9595
}

governance/chat/program/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ mod test {
9292
reply_to: Some(Pubkey::new_unique()),
9393
body: MessageBody::Text("message".to_string()),
9494
};
95-
let size = message.try_to_vec().unwrap().len();
95+
let size = borsh::to_vec(&message).unwrap().len();
9696

9797
assert_eq!(message.get_max_size(), Some(size));
9898
}

0 commit comments

Comments
 (0)