diff --git a/associated-token-account/program/src/instruction.rs b/associated-token-account/program/src/instruction.rs index efacd97dd97..728d2abcf3a 100644 --- a/associated-token-account/program/src/instruction.rs +++ b/associated-token-account/program/src/instruction.rs @@ -84,7 +84,7 @@ fn build_associated_token_account_instruction( AccountMeta::new_readonly(solana_program::system_program::id(), false), AccountMeta::new_readonly(*token_program_id, false), ], - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -156,6 +156,6 @@ pub fn recover_nested( AccountMeta::new(*wallet_address, true), AccountMeta::new_readonly(*token_program_id, false), ], - data: instruction_data.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction_data).unwrap(), } } diff --git a/binary-option/program/src/instruction.rs b/binary-option/program/src/instruction.rs index 8596c264e78..485386d6d31 100644 --- a/binary-option/program/src/instruction.rs +++ b/binary-option/program/src/instruction.rs @@ -60,10 +60,9 @@ pub fn initialize_binary_option( AccountMeta::new_readonly(solana_program::system_program::id(), false), AccountMeta::new_readonly(sysvar::rent::id(), false), ], - data: BinaryOptionInstruction::InitializeBinaryOption(InitializeBinaryOptionArgs { - decimals, - }) - .try_to_vec() + data: borsh::to_vec(&BinaryOptionInstruction::InitializeBinaryOption( + InitializeBinaryOptionArgs { decimals }, + )) .unwrap(), } } @@ -107,12 +106,11 @@ pub fn trade( AccountMeta::new_readonly(escrow_authority, false), AccountMeta::new_readonly(spl_token::id(), false), ], - data: BinaryOptionInstruction::Trade(TradeArgs { + data: borsh::to_vec(&BinaryOptionInstruction::Trade(TradeArgs { size, buy_price, sell_price, - }) - .try_to_vec() + })) .unwrap(), } } @@ -131,7 +129,7 @@ pub fn settle( AccountMeta::new_readonly(winning_mint, false), AccountMeta::new_readonly(pool_authority, true), ], - data: BinaryOptionInstruction::Settle.try_to_vec().unwrap(), + data: borsh::to_vec(&BinaryOptionInstruction::Settle).unwrap(), } } @@ -167,6 +165,6 @@ pub fn collect( AccountMeta::new_readonly(solana_program::system_program::id(), false), AccountMeta::new_readonly(sysvar::rent::id(), false), ], - data: BinaryOptionInstruction::Collect.try_to_vec().unwrap(), + data: borsh::to_vec(&BinaryOptionInstruction::Collect).unwrap(), } } diff --git a/binary-oracle-pair/program/src/instruction.rs b/binary-oracle-pair/program/src/instruction.rs index 969dd34ec8d..b524010cb03 100644 --- a/binary-oracle-pair/program/src/instruction.rs +++ b/binary-oracle-pair/program/src/instruction.rs @@ -102,7 +102,7 @@ pub fn init_pool( init_args: InitArgs, ) -> Result { let init_data = PoolInstruction::InitPool(init_args); - let data = init_data.try_to_vec()?; + let data = borsh::to_vec(&init_data)?; let accounts = vec![ AccountMeta::new(*pool, false), AccountMeta::new_readonly(*authority, false), @@ -138,7 +138,7 @@ pub fn deposit( amount: u64, ) -> Result { let init_data = PoolInstruction::Deposit(amount); - let data = init_data.try_to_vec()?; + let data = borsh::to_vec(&init_data)?; let accounts = vec![ AccountMeta::new_readonly(*pool, false), @@ -180,7 +180,7 @@ pub fn withdraw( amount: u64, ) -> Result { let init_data = PoolInstruction::Withdraw(amount); - let data = init_data.try_to_vec()?; + let data = borsh::to_vec(&init_data)?; let accounts = vec![ AccountMeta::new_readonly(*pool, false), AccountMeta::new_readonly(*authority, false), @@ -212,7 +212,7 @@ pub fn decide( decision: bool, ) -> Result { let init_data = PoolInstruction::Decide(decision); - let data = init_data.try_to_vec()?; + let data = borsh::to_vec(&init_data)?; let accounts = vec![ AccountMeta::new(*pool, false), AccountMeta::new_readonly(*decider, true), diff --git a/binary-oracle-pair/program/src/state.rs b/binary-oracle-pair/program/src/state.rs index c17910c583f..da3ac37abd7 100644 --- a/binary-oracle-pair/program/src/state.rs +++ b/binary-oracle-pair/program/src/state.rs @@ -85,7 +85,7 @@ mod test { decision: Decision::Fail, }; - let packed = p.try_to_vec().unwrap(); + let packed = borsh::to_vec(&p).unwrap(); let unpacked = Pool::try_from_slice(packed.as_slice()).unwrap(); diff --git a/feature-proposal/program/src/instruction.rs b/feature-proposal/program/src/instruction.rs index fa2da6424d8..ea8238e4149 100644 --- a/feature-proposal/program/src/instruction.rs +++ b/feature-proposal/program/src/instruction.rs @@ -107,7 +107,7 @@ impl Pack for FeatureProposalInstruction { impl FeatureProposalInstruction { fn pack_into_vec(&self) -> Vec { - self.try_to_vec().expect("try_to_vec") + borsh::to_vec(self).expect("try_to_vec") } } @@ -177,19 +177,18 @@ mod tests { #[test] fn test_serialize_bytes() { assert_eq!( - FeatureProposalInstruction::Tally.try_to_vec().unwrap(), + borsh::to_vec(&FeatureProposalInstruction::Tally).unwrap(), vec![1] ); assert_eq!( - FeatureProposalInstruction::Propose { + borsh::to_vec(&FeatureProposalInstruction::Propose { tokens_to_mint: 42, acceptance_criteria: AcceptanceCriteria { tokens_required: 0xdeadbeefdeadbeef, deadline: -1, } - } - .try_to_vec() + }) .unwrap(), vec![ 0, 42, 0, 0, 0, 0, 0, 0, 0, 239, 190, 173, 222, 239, 190, 173, 222, 255, 255, 255, diff --git a/feature-proposal/program/src/state.rs b/feature-proposal/program/src/state.rs index 613ad3427d9..81d86f2da7a 100644 --- a/feature-proposal/program/src/state.rs +++ b/feature-proposal/program/src/state.rs @@ -45,7 +45,7 @@ impl Pack for FeatureProposal { const LEN: usize = 17; // see `test_get_packed_len()` for justification of "18" fn pack_into_slice(&self, dst: &mut [u8]) { - let data = self.try_to_vec().unwrap(); + let data = borsh::to_vec(self).unwrap(); dst[..data.len()].copy_from_slice(&data); } @@ -75,14 +75,13 @@ mod tests { #[test] fn test_serialize_bytes() { - assert_eq!(FeatureProposal::Expired.try_to_vec().unwrap(), vec![3]); + assert_eq!(borsh::to_vec(&FeatureProposal::Expired).unwrap(), vec![3]); assert_eq!( - FeatureProposal::Pending(AcceptanceCriteria { + borsh::to_vec(&FeatureProposal::Pending(AcceptanceCriteria { tokens_required: 0xdeadbeefdeadbeef, deadline: -1, - }) - .try_to_vec() + })) .unwrap(), vec![1, 239, 190, 173, 222, 239, 190, 173, 222, 255, 255, 255, 255, 255, 255, 255, 255], ); diff --git a/governance/addin-mock/program/src/instruction.rs b/governance/addin-mock/program/src/instruction.rs index 676909a138c..65bc2d331fc 100644 --- a/governance/addin-mock/program/src/instruction.rs +++ b/governance/addin-mock/program/src/instruction.rs @@ -96,7 +96,7 @@ pub fn setup_voter_weight_record( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -129,6 +129,6 @@ pub fn setup_max_voter_weight_record( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } diff --git a/governance/chat/program/src/instruction.rs b/governance/chat/program/src/instruction.rs index c95c78c5f06..9dda2c36f20 100644 --- a/governance/chat/program/src/instruction.rs +++ b/governance/chat/program/src/instruction.rs @@ -90,6 +90,6 @@ pub fn post_message( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } diff --git a/governance/chat/program/src/state.rs b/governance/chat/program/src/state.rs index b995e5bf252..10db01c95a8 100644 --- a/governance/chat/program/src/state.rs +++ b/governance/chat/program/src/state.rs @@ -92,7 +92,7 @@ mod test { reply_to: Some(Pubkey::new_unique()), body: MessageBody::Text("message".to_string()), }; - let size = message.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&message).unwrap().len(); assert_eq!(message.get_max_size(), Some(size)); } diff --git a/governance/program/src/instruction.rs b/governance/program/src/instruction.rs index 911111618ad..240627b8f87 100644 --- a/governance/program/src/instruction.rs +++ b/governance/program/src/instruction.rs @@ -731,7 +731,7 @@ pub fn create_realm( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -779,7 +779,7 @@ pub fn deposit_governing_tokens( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -820,7 +820,7 @@ pub fn withdraw_governing_tokens( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -854,7 +854,7 @@ pub fn set_governance_delegate( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -899,7 +899,7 @@ pub fn create_governance( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -946,7 +946,7 @@ pub fn create_program_governance( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -990,7 +990,7 @@ pub fn create_mint_governance( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1034,7 +1034,7 @@ pub fn create_token_governance( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1093,7 +1093,7 @@ pub fn create_proposal( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1141,7 +1141,7 @@ pub fn add_signatory( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1191,7 +1191,7 @@ pub fn sign_off_proposal( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1242,7 +1242,7 @@ pub fn cast_vote( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1278,7 +1278,7 @@ pub fn finalize_vote( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1316,7 +1316,7 @@ pub fn relinquish_vote( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1343,7 +1343,7 @@ pub fn cancel_proposal( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1391,7 +1391,7 @@ pub fn insert_transaction( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1418,7 +1418,7 @@ pub fn remove_transaction( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1446,7 +1446,7 @@ pub fn execute_transaction( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1465,7 +1465,7 @@ pub fn set_governance_config( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1490,7 +1490,7 @@ pub fn flag_transaction_error( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1524,7 +1524,7 @@ pub fn set_realm_authority( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1589,7 +1589,7 @@ pub fn set_realm_config( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1651,7 +1651,7 @@ pub fn create_token_owner_record( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1674,7 +1674,7 @@ pub fn upgrade_program_metadata( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1699,7 +1699,7 @@ pub fn create_native_treasury( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1742,7 +1742,7 @@ pub fn revoke_governing_tokens( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1772,7 +1772,7 @@ pub fn add_required_signatory( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1798,7 +1798,7 @@ pub fn remove_required_signatory( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1856,7 +1856,7 @@ pub fn refund_proposal_deposit( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } @@ -1880,6 +1880,6 @@ pub fn complete_proposal( Instruction { program_id: *program_id, accounts, - data: instruction.try_to_vec().unwrap(), + data: borsh::to_vec(&instruction).unwrap(), } } diff --git a/governance/program/src/state/governance.rs b/governance/program/src/state/governance.rs index 1e343462106..ad2bd6532eb 100644 --- a/governance/program/src/state/governance.rs +++ b/governance/program/src/state/governance.rs @@ -10,7 +10,7 @@ use { }, tools::structs::Reserved119, }, - borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + borsh::{io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, solana_program::{ account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, pubkey::Pubkey, rent::Rent, @@ -722,7 +722,7 @@ mod test { let governance_data = create_test_governance(); // Act - let size = governance_data.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&governance_data).unwrap().len(); // Assert assert_eq!(governance_data.get_max_size(), Some(size)); @@ -734,7 +734,7 @@ mod test { let governance = create_test_v1_governance(); // Act - let size = governance.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&governance).unwrap().len(); // Assert assert_eq!(108, size); diff --git a/governance/program/src/state/program_metadata.rs b/governance/program/src/state/program_metadata.rs index 1034c6544bd..7c0f7f51423 100644 --- a/governance/program/src/state/program_metadata.rs +++ b/governance/program/src/state/program_metadata.rs @@ -72,7 +72,7 @@ mod test { version: "111.122.155".to_string(), }; - let size = program_metadata_data.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&program_metadata_data).unwrap().len(); assert_eq!(program_metadata_data.get_max_size(), Some(size)); } diff --git a/governance/program/src/state/proposal.rs b/governance/program/src/state/proposal.rs index 30ae07ff95a..8b28f88b7a3 100644 --- a/governance/program/src/state/proposal.rs +++ b/governance/program/src/state/proposal.rs @@ -22,7 +22,7 @@ use { tools::spl_token::get_spl_token_mint_supply, PROGRAM_AUTHORITY_SEED, }, - borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + borsh::{io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, solana_program::{ account_info::{next_account_info, AccountInfo}, clock::{Slot, UnixTimestamp}, @@ -1395,7 +1395,7 @@ mod test { max_winning_options: 1, }; - let size = proposal.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&proposal).unwrap().len(); assert_eq!(proposal.get_max_size(), Some(size)); } @@ -1410,7 +1410,7 @@ mod test { max_winning_options: 3, }; - let size = proposal.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&proposal).unwrap().len(); assert_eq!(proposal.get_max_size(), Some(size)); } diff --git a/governance/program/src/state/proposal_deposit.rs b/governance/program/src/state/proposal_deposit.rs index 76126ff639a..e07c54a2003 100644 --- a/governance/program/src/state/proposal_deposit.rs +++ b/governance/program/src/state/proposal_deposit.rs @@ -111,7 +111,7 @@ mod test { }; // Act - let size = proposal_deposit_data.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&proposal_deposit_data).unwrap().len(); // Assert assert_eq!(proposal_deposit_data.get_max_size(), Some(size)); diff --git a/governance/program/src/state/proposal_transaction.rs b/governance/program/src/state/proposal_transaction.rs index f2ae26ecb67..2ab96ce7211 100644 --- a/governance/program/src/state/proposal_transaction.rs +++ b/governance/program/src/state/proposal_transaction.rs @@ -9,7 +9,7 @@ use { }, PROGRAM_AUTHORITY_SEED, }, - borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + borsh::{io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, core::panic, solana_program::{ account_info::AccountInfo, @@ -298,7 +298,7 @@ mod test { #[test] fn test_account_meta_data_size() { let account_meta_data = create_test_account_meta_data(); - let size = account_meta_data.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&account_meta_data).unwrap().len(); assert_eq!(34, size); } @@ -307,7 +307,7 @@ mod test { fn test_proposal_transaction_max_size() { // Arrange let proposal_transaction = create_test_proposal_transaction(); - let size = proposal_transaction.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&proposal_transaction).unwrap().len(); // Act, Assert assert_eq!(proposal_transaction.get_max_size(), Some(size)); @@ -320,7 +320,7 @@ mod test { proposal_transaction.instructions[0].data = vec![]; proposal_transaction.instructions[0].accounts = vec![]; - let size = proposal_transaction.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&proposal_transaction).unwrap().len(); // Act, Assert assert_eq!(proposal_transaction.get_max_size(), Some(size)); diff --git a/governance/program/src/state/realm.rs b/governance/program/src/state/realm.rs index acbc1cb7765..e43609d0531 100644 --- a/governance/program/src/state/realm.rs +++ b/governance/program/src/state/realm.rs @@ -12,7 +12,7 @@ use { }, PROGRAM_AUTHORITY_SEED, }, - borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + borsh::{io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, solana_program::{ account_info::{next_account_info, AccountInfo}, program_error::ProgramError, @@ -505,7 +505,7 @@ mod test { reserved_v2: [0; 128], }; - let size = realm.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&realm).unwrap().len(); assert_eq!(realm.get_max_size(), Some(size)); } diff --git a/governance/program/src/state/realm_config.rs b/governance/program/src/state/realm_config.rs index d334c338166..d252aa05e35 100644 --- a/governance/program/src/state/realm_config.rs +++ b/governance/program/src/state/realm_config.rs @@ -326,7 +326,7 @@ mod test { reserved: Reserved110::default(), }; - let size = realm_config.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&realm_config).unwrap().len(); assert_eq!(realm_config.get_max_size(), Some(size)); } diff --git a/governance/program/src/state/signatory_record.rs b/governance/program/src/state/signatory_record.rs index 5c3a5a1cfea..c20a8abd4a1 100644 --- a/governance/program/src/state/signatory_record.rs +++ b/governance/program/src/state/signatory_record.rs @@ -6,7 +6,7 @@ use { state::{enums::GovernanceAccountType, legacy::SignatoryRecordV1}, PROGRAM_AUTHORITY_SEED, }, - borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + borsh::{io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, solana_program::{ account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, pubkey::Pubkey, diff --git a/governance/program/src/state/token_owner_record.rs b/governance/program/src/state/token_owner_record.rs index e246fbe5c7f..996e38ceec8 100644 --- a/governance/program/src/state/token_owner_record.rs +++ b/governance/program/src/state/token_owner_record.rs @@ -12,7 +12,7 @@ use { }, PROGRAM_AUTHORITY_SEED, }, - borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + borsh::{io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, solana_program::{ account_info::{next_account_info, AccountInfo}, program_error::ProgramError, @@ -504,7 +504,7 @@ mod test { let governance = create_test_program_v1_token_owner_record(); // Act - let size = governance.try_to_vec().unwrap().len(); + let size = borsh::to_vec(&governance).unwrap().len(); // Assert assert_eq!(154, size); diff --git a/governance/program/src/state/vote_record.rs b/governance/program/src/state/vote_record.rs index 050f8fd9c3d..8606ba02075 100644 --- a/governance/program/src/state/vote_record.rs +++ b/governance/program/src/state/vote_record.rs @@ -12,7 +12,7 @@ use { }, PROGRAM_AUTHORITY_SEED, }, - borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + borsh::{io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, solana_program::{ account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, pubkey::Pubkey, diff --git a/governance/program/tests/process_add_signatory.rs b/governance/program/tests/process_add_signatory.rs index 7c9b15507bb..cc80679611f 100644 --- a/governance/program/tests/process_add_signatory.rs +++ b/governance/program/tests/process_add_signatory.rs @@ -3,7 +3,6 @@ mod program_test; use { - borsh::BorshSerialize, program_test::*, solana_program::program_error::ProgramError, solana_program_test::tokio, @@ -453,10 +452,9 @@ pub async fn test_add_non_matching_required_signatory_to_proposal_err() { &signatory.pubkey(), ); - create_signatory_record_ix.data = GovernanceInstruction::AddSignatory { + create_signatory_record_ix.data = borsh::to_vec(&GovernanceInstruction::AddSignatory { signatory: Pubkey::new_unique(), - } - .try_to_vec() + }) .unwrap(); // Act diff --git a/governance/tools/src/account.rs b/governance/tools/src/account.rs index 00351e51347..b3183b00c03 100644 --- a/governance/tools/src/account.rs +++ b/governance/tools/src/account.rs @@ -44,7 +44,7 @@ pub fn create_and_serialize_account<'a, T: BorshSerialize + AccountMaxSize>( let (serialized_data, account_size) = if let Some(max_size) = account_data.get_max_size() { (None, max_size) } else { - let serialized_data = account_data.try_to_vec()?; + let serialized_data = borsh::to_vec(account_data)?; let account_size = serialized_data.len(); (Some(serialized_data), account_size) }; @@ -139,7 +139,7 @@ pub fn create_and_serialize_account_with_owner_signed<'a, T: BorshSerialize + Ac let (serialized_data, account_size) = if let Some(max_size) = account_data.get_max_size() { (None, max_size) } else { - let serialized_data = account_data.try_to_vec()?; + let serialized_data = borsh::to_vec(&account_data)?; let account_size = serialized_data.len(); (Some(serialized_data), account_size) }; diff --git a/libraries/math/src/instruction.rs b/libraries/math/src/instruction.rs index dd45073cb99..5fd4dc6c4e4 100644 --- a/libraries/math/src/instruction.rs +++ b/libraries/math/src/instruction.rs @@ -118,9 +118,7 @@ pub fn precise_sqrt(radicand: u64) -> Instruction { Instruction { program_id: id(), accounts: vec![], - data: MathInstruction::PreciseSquareRoot { radicand } - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&MathInstruction::PreciseSquareRoot { radicand }).unwrap(), } } @@ -129,9 +127,7 @@ pub fn sqrt_u64(radicand: u64) -> Instruction { Instruction { program_id: id(), accounts: vec![], - data: MathInstruction::SquareRootU64 { radicand } - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&MathInstruction::SquareRootU64 { radicand }).unwrap(), } } @@ -140,9 +136,7 @@ pub fn sqrt_u128(radicand: u128) -> Instruction { Instruction { program_id: id(), accounts: vec![], - data: MathInstruction::SquareRootU128 { radicand } - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&MathInstruction::SquareRootU128 { radicand }).unwrap(), } } @@ -151,11 +145,10 @@ pub fn u64_multiply(multiplicand: u64, multiplier: u64) -> Instruction { Instruction { program_id: id(), accounts: vec![], - data: MathInstruction::U64Multiply { + data: borsh::to_vec(&MathInstruction::U64Multiply { multiplicand, multiplier, - } - .try_to_vec() + }) .unwrap(), } } @@ -165,9 +158,7 @@ pub fn u64_divide(dividend: u64, divisor: u64) -> Instruction { Instruction { program_id: id(), accounts: vec![], - data: MathInstruction::U64Divide { dividend, divisor } - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&MathInstruction::U64Divide { dividend, divisor }).unwrap(), } } @@ -176,11 +167,10 @@ pub fn f32_multiply(multiplicand: f32, multiplier: f32) -> Instruction { Instruction { program_id: id(), accounts: vec![], - data: MathInstruction::F32Multiply { + data: borsh::to_vec(&MathInstruction::F32Multiply { multiplicand, multiplier, - } - .try_to_vec() + }) .unwrap(), } } @@ -190,9 +180,7 @@ pub fn f32_divide(dividend: f32, divisor: f32) -> Instruction { Instruction { program_id: id(), accounts: vec![], - data: MathInstruction::F32Divide { dividend, divisor } - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&MathInstruction::F32Divide { dividend, divisor }).unwrap(), } } @@ -201,9 +189,7 @@ pub fn f32_exponentiate(base: f32, exponent: f32) -> Instruction { Instruction { program_id: id(), accounts: vec![], - data: MathInstruction::F32Exponentiate { base, exponent } - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&MathInstruction::F32Exponentiate { base, exponent }).unwrap(), } } @@ -212,9 +198,7 @@ pub fn f32_natural_log(argument: f32) -> Instruction { Instruction { program_id: id(), accounts: vec![], - data: MathInstruction::F32NaturalLog { argument } - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&MathInstruction::F32NaturalLog { argument }).unwrap(), } } @@ -223,9 +207,7 @@ pub fn f32_normal_cdf(argument: f32) -> Instruction { Instruction { program_id: id(), accounts: vec![], - data: MathInstruction::F32NormalCDF { argument } - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&MathInstruction::F32NormalCDF { argument }).unwrap(), } } @@ -234,9 +216,7 @@ pub fn f64_pow(base: f64, exponent: f64) -> Instruction { Instruction { program_id: id(), accounts: vec![], - data: MathInstruction::F64Pow { base, exponent } - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&MathInstruction::F64Pow { base, exponent }).unwrap(), } } @@ -245,7 +225,7 @@ pub fn noop() -> Instruction { Instruction { program_id: id(), accounts: vec![], - data: MathInstruction::Noop.try_to_vec().unwrap(), + data: borsh::to_vec(&MathInstruction::Noop).unwrap(), } } @@ -259,9 +239,7 @@ mod tests { assert_eq!(0, instruction.accounts.len()); assert_eq!( instruction.data, - MathInstruction::PreciseSquareRoot { radicand: u64::MAX } - .try_to_vec() - .unwrap() + borsh::to_vec(&MathInstruction::PreciseSquareRoot { radicand: u64::MAX }).unwrap() ); assert_eq!(instruction.program_id, crate::id()); } @@ -272,9 +250,7 @@ mod tests { assert_eq!(0, instruction.accounts.len()); assert_eq!( instruction.data, - MathInstruction::SquareRootU64 { radicand: u64::MAX } - .try_to_vec() - .unwrap() + borsh::to_vec(&MathInstruction::SquareRootU64 { radicand: u64::MAX }).unwrap() ); assert_eq!(instruction.program_id, crate::id()); } @@ -285,10 +261,9 @@ mod tests { assert_eq!(0, instruction.accounts.len()); assert_eq!( instruction.data, - MathInstruction::SquareRootU128 { + borsh::to_vec(&MathInstruction::SquareRootU128 { radicand: u128::MAX - } - .try_to_vec() + }) .unwrap() ); assert_eq!(instruction.program_id, crate::id()); @@ -300,11 +275,10 @@ mod tests { assert_eq!(0, instruction.accounts.len()); assert_eq!( instruction.data, - MathInstruction::U64Multiply { + borsh::to_vec(&MathInstruction::U64Multiply { multiplicand: u64::MAX, multiplier: u64::MAX - } - .try_to_vec() + }) .unwrap() ); assert_eq!(instruction.program_id, crate::id()); @@ -316,11 +290,10 @@ mod tests { assert_eq!(0, instruction.accounts.len()); assert_eq!( instruction.data, - MathInstruction::U64Divide { + borsh::to_vec(&MathInstruction::U64Divide { dividend: u64::MAX, divisor: u64::MAX - } - .try_to_vec() + }) .unwrap() ); assert_eq!(instruction.program_id, crate::id()); @@ -332,11 +305,10 @@ mod tests { assert_eq!(0, instruction.accounts.len()); assert_eq!( instruction.data, - MathInstruction::F32Multiply { + borsh::to_vec(&MathInstruction::F32Multiply { multiplicand: f32::MAX, multiplier: f32::MAX - } - .try_to_vec() + }) .unwrap() ); assert_eq!(instruction.program_id, crate::id()); @@ -348,11 +320,10 @@ mod tests { assert_eq!(0, instruction.accounts.len()); assert_eq!( instruction.data, - MathInstruction::F32Divide { + borsh::to_vec(&MathInstruction::F32Divide { dividend: f32::MAX, divisor: f32::MAX - } - .try_to_vec() + }) .unwrap() ); assert_eq!(instruction.program_id, crate::id()); @@ -364,11 +335,10 @@ mod tests { assert_eq!(0, instruction.accounts.len()); assert_eq!( instruction.data, - MathInstruction::F32Exponentiate { + borsh::to_vec(&MathInstruction::F32Exponentiate { base: f32::MAX, exponent: f32::MAX - } - .try_to_vec() + }) .unwrap() ); assert_eq!(instruction.program_id, crate::id()) @@ -380,9 +350,7 @@ mod tests { assert_eq!(0, instruction.accounts.len()); assert_eq!( instruction.data, - MathInstruction::F32NaturalLog { argument: f32::MAX } - .try_to_vec() - .unwrap() + borsh::to_vec(&MathInstruction::F32NaturalLog { argument: f32::MAX }).unwrap() ); assert_eq!(instruction.program_id, crate::id()) } @@ -393,9 +361,7 @@ mod tests { assert_eq!(0, instruction.accounts.len()); assert_eq!( instruction.data, - MathInstruction::F32NormalCDF { argument: f32::MAX } - .try_to_vec() - .unwrap() + borsh::to_vec(&MathInstruction::F32NormalCDF { argument: f32::MAX }).unwrap() ); assert_eq!(instruction.program_id, crate::id()) } @@ -406,7 +372,7 @@ mod tests { assert_eq!(0, instruction.accounts.len()); assert_eq!( instruction.data, - MathInstruction::Noop.try_to_vec().unwrap() + borsh::to_vec(&MathInstruction::Noop).unwrap() ); assert_eq!(instruction.program_id, crate::id()); } diff --git a/libraries/math/src/processor.rs b/libraries/math/src/processor.rs index 45c1cbd26d7..fff69dd9703 100644 --- a/libraries/math/src/processor.rs +++ b/libraries/math/src/processor.rs @@ -167,7 +167,7 @@ pub fn process_instruction( #[cfg(test)] mod tests { - use {super::*, crate::instruction::MathInstruction, borsh::BorshSerialize}; + use {super::*, crate::instruction::MathInstruction}; #[test] fn test_u64_multiply() { @@ -245,7 +245,7 @@ mod tests { }, MathInstruction::Noop, ] { - let input = math_instruction.try_to_vec().unwrap(); + let input = borsh::to_vec(math_instruction).unwrap(); process_instruction(&program_id, &[], &input).unwrap(); } } diff --git a/managed-token/program/src/instruction.rs b/managed-token/program/src/instruction.rs index c3801690aa0..d6dd8e46e76 100644 --- a/managed-token/program/src/instruction.rs +++ b/managed-token/program/src/instruction.rs @@ -105,7 +105,7 @@ pub fn create_initialize_mint_instruction( AccountMeta::new_readonly(system_program::id(), false), AccountMeta::new_readonly(spl_token::id(), false), ], - data: ManagedTokenInstruction::InitializeMint { decimals }.try_to_vec()?, + data: borsh::to_vec(&ManagedTokenInstruction::InitializeMint { decimals })?, }) } @@ -130,7 +130,7 @@ pub fn create_initialize_account_instruction( AccountMeta::new_readonly(spl_associated_token_account::id(), false), AccountMeta::new_readonly(spl_token::id(), false), ], - data: ManagedTokenInstruction::InitializeAccount.try_to_vec()?, + data: borsh::to_vec(&ManagedTokenInstruction::InitializeAccount)?, }) } @@ -151,7 +151,7 @@ pub fn create_mint_to_instruction( AccountMeta::new_readonly(authority, false), AccountMeta::new_readonly(spl_token::id(), false), ], - data: ManagedTokenInstruction::MintTo { amount }.try_to_vec()?, + data: borsh::to_vec(&ManagedTokenInstruction::MintTo { amount })?, }) } @@ -176,7 +176,7 @@ pub fn create_transfer_instruction( AccountMeta::new_readonly(freeze_authority, false), AccountMeta::new_readonly(spl_token::id(), false), ], - data: ManagedTokenInstruction::Transfer { amount }.try_to_vec()?, + data: borsh::to_vec(&ManagedTokenInstruction::Transfer { amount })?, }) } @@ -202,7 +202,7 @@ pub fn create_transfer_with_delegate_instruction( AccountMeta::new_readonly(freeze_authority, false), AccountMeta::new_readonly(spl_token::id(), false), ], - data: ManagedTokenInstruction::Transfer { amount }.try_to_vec()?, + data: borsh::to_vec(&ManagedTokenInstruction::Transfer { amount })?, }) } @@ -224,7 +224,7 @@ pub fn create_burn_instruction( AccountMeta::new_readonly(freeze_authority, false), AccountMeta::new_readonly(spl_token::id(), false), ], - data: ManagedTokenInstruction::Burn { amount }.try_to_vec()?, + data: borsh::to_vec(&ManagedTokenInstruction::Burn { amount })?, }) } @@ -246,7 +246,7 @@ pub fn create_close_account_instruction( AccountMeta::new_readonly(freeze_authority, false), AccountMeta::new_readonly(spl_token::id(), false), ], - data: ManagedTokenInstruction::CloseAccount.try_to_vec()?, + data: borsh::to_vec(&ManagedTokenInstruction::CloseAccount)?, }) } @@ -270,7 +270,7 @@ pub fn create_approve_instruction( AccountMeta::new_readonly(freeze_authority, false), AccountMeta::new_readonly(spl_token::id(), false), ], - data: ManagedTokenInstruction::Approve { amount }.try_to_vec()?, + data: borsh::to_vec(&ManagedTokenInstruction::Approve { amount })?, }) } @@ -291,6 +291,6 @@ pub fn create_revoke_instruction( AccountMeta::new_readonly(freeze_authority, false), AccountMeta::new_readonly(spl_token::id(), false), ], - data: ManagedTokenInstruction::Revoke.try_to_vec()?, + data: borsh::to_vec(&ManagedTokenInstruction::Revoke)?, }) } diff --git a/name-service/program/src/instruction.rs b/name-service/program/src/instruction.rs index 4ed949f1271..7f722284b3e 100644 --- a/name-service/program/src/instruction.rs +++ b/name-service/program/src/instruction.rs @@ -125,7 +125,7 @@ pub fn create( name_parent_opt: Option, name_parent_owner_opt: Option, ) -> Result { - let data = instruction_data.try_to_vec().unwrap(); + let data = borsh::to_vec(&instruction_data).unwrap(); let mut accounts = vec![ AccountMeta::new_readonly(system_program::id(), false), AccountMeta::new(payer_key, true), @@ -162,7 +162,7 @@ pub fn update( name_parent: Option, ) -> Result { let instruction_data = NameRegistryInstruction::Update { offset, data }; - let data = instruction_data.try_to_vec().unwrap(); + let data = borsh::to_vec(&instruction_data).unwrap(); let mut accounts = vec![ AccountMeta::new(name_account_key, false), AccountMeta::new_readonly(name_update_signer, true), @@ -187,7 +187,7 @@ pub fn transfer( name_class_opt: Option, ) -> Result { let instruction_data = NameRegistryInstruction::Transfer { new_owner }; - let data = instruction_data.try_to_vec().unwrap(); + let data = borsh::to_vec(&instruction_data).unwrap(); let mut accounts = vec![ AccountMeta::new(name_account_key, false), AccountMeta::new_readonly(name_owner_key, true), @@ -211,7 +211,7 @@ pub fn delete( refund_target: Pubkey, ) -> Result { let instruction_data = NameRegistryInstruction::Delete; - let data = instruction_data.try_to_vec().unwrap(); + let data = borsh::to_vec(&instruction_data).unwrap(); let accounts = vec![ AccountMeta::new(name_account_key, false), AccountMeta::new_readonly(name_owner_key, true), @@ -233,7 +233,7 @@ pub fn realloc( space: u32, ) -> Result { let instruction_data = NameRegistryInstruction::Realloc { space }; - let data = instruction_data.try_to_vec().unwrap(); + let data = borsh::to_vec(&instruction_data).unwrap(); let accounts = vec![ AccountMeta::new_readonly(system_program::id(), false), AccountMeta::new(payer_key, true), diff --git a/single-pool/cli/src/main.rs b/single-pool/cli/src/main.rs index 8af38f1594f..952d057c732 100644 --- a/single-pool/cli/src/main.rs +++ b/single-pool/cli/src/main.rs @@ -1,7 +1,6 @@ #![allow(clippy::arithmetic_side_effects)] use { - borsh::BorshSerialize, clap::{CommandFactory, Parser}, solana_clap_v3_utils::input_parsers::Amount, solana_client::{ @@ -133,9 +132,7 @@ async fn command_initialize(config: &Config, command_config: InitializeCli) -> C if command_config.skip_metadata { assert_eq!( instructions.last().unwrap().data, - SinglePoolInstruction::CreateTokenMetadata - .try_to_vec() - .unwrap() + borsh::to_vec(&SinglePoolInstruction::CreateTokenMetadata).unwrap() ); instructions.pop(); diff --git a/single-pool/program/src/instruction.rs b/single-pool/program/src/instruction.rs index daa034cc02d..fda54691a3c 100644 --- a/single-pool/program/src/instruction.rs +++ b/single-pool/program/src/instruction.rs @@ -164,7 +164,7 @@ pub fn initialize_pool(program_id: &Pubkey, vote_account_address: &Pubkey) -> In let pool_address = find_pool_address(program_id, vote_account_address); let mint_address = find_pool_mint_address(program_id, &pool_address); - let data = SinglePoolInstruction::InitializePool.try_to_vec().unwrap(); + let data = borsh::to_vec(&SinglePoolInstruction::InitializePool).unwrap(); let accounts = vec![ AccountMeta::new_readonly(*vote_account_address, false), AccountMeta::new(pool_address, false), @@ -199,9 +199,7 @@ pub fn initialize_pool(program_id: &Pubkey, vote_account_address: &Pubkey) -> In pub fn reactivate_pool_stake(program_id: &Pubkey, vote_account_address: &Pubkey) -> Instruction { let pool_address = find_pool_address(program_id, vote_account_address); - let data = SinglePoolInstruction::ReactivatePoolStake - .try_to_vec() - .unwrap(); + let data = borsh::to_vec(&SinglePoolInstruction::ReactivatePoolStake).unwrap(); let accounts = vec![ AccountMeta::new_readonly(*vote_account_address, false), AccountMeta::new_readonly(pool_address, false), @@ -268,7 +266,7 @@ pub fn deposit_stake( user_token_account: &Pubkey, user_lamport_account: &Pubkey, ) -> Instruction { - let data = SinglePoolInstruction::DepositStake.try_to_vec().unwrap(); + let data = borsh::to_vec(&SinglePoolInstruction::DepositStake).unwrap(); let accounts = vec![ AccountMeta::new_readonly(*pool_address, false), @@ -342,11 +340,10 @@ pub fn withdraw_stake( user_token_account: &Pubkey, token_amount: u64, ) -> Instruction { - let data = SinglePoolInstruction::WithdrawStake { + let data = borsh::to_vec(&SinglePoolInstruction::WithdrawStake { user_stake_authority: *user_stake_authority, token_amount, - } - .try_to_vec() + }) .unwrap(); let accounts = vec![ @@ -415,9 +412,7 @@ pub fn create_token_metadata( ) -> Instruction { let pool_mint = find_pool_mint_address(program_id, pool_address); let (token_metadata, _) = find_metadata_account(&pool_mint); - let data = SinglePoolInstruction::CreateTokenMetadata - .try_to_vec() - .unwrap(); + let data = borsh::to_vec(&SinglePoolInstruction::CreateTokenMetadata).unwrap(); let accounts = vec![ AccountMeta::new_readonly(*pool_address, false), @@ -455,9 +450,8 @@ pub fn update_token_metadata( let pool_address = find_pool_address(program_id, vote_account_address); let pool_mint = find_pool_mint_address(program_id, &pool_address); let (token_metadata, _) = find_metadata_account(&pool_mint); - let data = SinglePoolInstruction::UpdateTokenMetadata { name, symbol, uri } - .try_to_vec() - .unwrap(); + let data = + borsh::to_vec(&SinglePoolInstruction::UpdateTokenMetadata { name, symbol, uri }).unwrap(); let accounts = vec![ AccountMeta::new_readonly(*vote_account_address, false), diff --git a/stake-pool/program/src/inline_mpl_token_metadata.rs b/stake-pool/program/src/inline_mpl_token_metadata.rs index b7697a29419..a5d0836b3dd 100644 --- a/stake-pool/program/src/inline_mpl_token_metadata.rs +++ b/stake-pool/program/src/inline_mpl_token_metadata.rs @@ -38,7 +38,7 @@ pub(crate) mod instruction { ) -> Instruction { let mut data = vec![33]; // CreateMetadataAccountV3 data.append( - &mut CreateMetadataAccountArgsV3 { + &mut borsh::to_vec(&CreateMetadataAccountArgsV3 { data: DataV2 { name, symbol, @@ -50,8 +50,7 @@ pub(crate) mod instruction { }, is_mutable: true, collection_details: None, - } - .try_to_vec() + }) .unwrap(), ); Instruction { @@ -86,13 +85,12 @@ pub(crate) mod instruction { ) -> Instruction { let mut data = vec![15]; // UpdateMetadataAccountV2 data.append( - &mut UpdateMetadataAccountArgsV2 { + &mut borsh::to_vec(&UpdateMetadataAccountArgsV2 { data: metadata, update_authority: new_update_authority, primary_sale_happened, is_mutable, - } - .try_to_vec() + }) .unwrap(), ); Instruction { diff --git a/stake-pool/program/src/instruction.rs b/stake-pool/program/src/instruction.rs index 4b8afd8e17b..313afd93015 100644 --- a/stake-pool/program/src/instruction.rs +++ b/stake-pool/program/src/instruction.rs @@ -750,7 +750,7 @@ pub fn initialize( referral_fee, max_validators, }; - let data = init_data.try_to_vec().unwrap(); + let data = borsh::to_vec(&init_data).unwrap(); let mut accounts = vec![ AccountMeta::new(*stake_pool, false), AccountMeta::new_readonly(*manager, true), @@ -801,9 +801,10 @@ pub fn add_validator_to_pool( AccountMeta::new_readonly(system_program::id(), false), AccountMeta::new_readonly(stake::program::id(), false), ]; - let data = StakePoolInstruction::AddValidatorToPool(seed.map(|s| s.get()).unwrap_or(0)) - .try_to_vec() - .unwrap(); + let data = borsh::to_vec(&StakePoolInstruction::AddValidatorToPool( + seed.map(|s| s.get()).unwrap_or(0), + )) + .unwrap(); Instruction { program_id: *program_id, accounts, @@ -835,9 +836,7 @@ pub fn remove_validator_from_pool( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::RemoveValidatorFromPool - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&StakePoolInstruction::RemoveValidatorFromPool).unwrap(), } } @@ -873,11 +872,10 @@ pub fn decrease_validator_stake( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::DecreaseValidatorStake { + data: borsh::to_vec(&StakePoolInstruction::DecreaseValidatorStake { lamports, transient_stake_seed, - } - .try_to_vec() + }) .unwrap(), } } @@ -915,12 +913,11 @@ pub fn decrease_additional_validator_stake( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::DecreaseAdditionalValidatorStake { + data: borsh::to_vec(&StakePoolInstruction::DecreaseAdditionalValidatorStake { lamports, transient_stake_seed, ephemeral_stake_seed, - } - .try_to_vec() + }) .unwrap(), } } @@ -955,11 +952,10 @@ pub fn decrease_validator_stake_with_reserve( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::DecreaseValidatorStakeWithReserve { + data: borsh::to_vec(&StakePoolInstruction::DecreaseValidatorStakeWithReserve { lamports, transient_stake_seed, - } - .try_to_vec() + }) .unwrap(), } } @@ -999,11 +995,10 @@ pub fn increase_validator_stake( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::IncreaseValidatorStake { + data: borsh::to_vec(&StakePoolInstruction::IncreaseValidatorStake { lamports, transient_stake_seed, - } - .try_to_vec() + }) .unwrap(), } } @@ -1045,12 +1040,11 @@ pub fn increase_additional_validator_stake( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::IncreaseAdditionalValidatorStake { + data: borsh::to_vec(&StakePoolInstruction::IncreaseAdditionalValidatorStake { lamports, transient_stake_seed, ephemeral_stake_seed, - } - .try_to_vec() + }) .unwrap(), } } @@ -1097,13 +1091,12 @@ pub fn redelegate( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::Redelegate { + data: borsh::to_vec(&StakePoolInstruction::Redelegate { lamports, source_transient_stake_seed, ephemeral_stake_seed, destination_transient_stake_seed, - } - .try_to_vec() + }) .unwrap(), } } @@ -1124,11 +1117,10 @@ pub fn set_preferred_validator( AccountMeta::new_readonly(*staker, true), AccountMeta::new_readonly(*validator_list_address, false), ], - data: StakePoolInstruction::SetPreferredValidator { + data: borsh::to_vec(&StakePoolInstruction::SetPreferredValidator { validator_type, validator_vote_address, - } - .try_to_vec() + }) .unwrap(), } } @@ -1421,11 +1413,10 @@ pub fn update_validator_list_balance( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::UpdateValidatorListBalance { + data: borsh::to_vec(&StakePoolInstruction::UpdateValidatorListBalance { start_index, no_merge, - } - .try_to_vec() + }) .unwrap(), } } @@ -1489,11 +1480,10 @@ pub fn update_validator_list_balance_chunk( Ok(Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::UpdateValidatorListBalance { + data: borsh::to_vec(&StakePoolInstruction::UpdateValidatorListBalance { start_index: start_index.try_into().unwrap(), no_merge, - } - .try_to_vec() + }) .unwrap(), }) } @@ -1563,9 +1553,7 @@ pub fn update_stake_pool_balance( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::UpdateStakePoolBalance - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&StakePoolInstruction::UpdateStakePoolBalance).unwrap(), } } @@ -1583,9 +1571,7 @@ pub fn cleanup_removed_validator_entries( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::CleanupRemovedValidatorEntries - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&StakePoolInstruction::CleanupRemovedValidatorEntries).unwrap(), } } @@ -1788,17 +1774,16 @@ fn deposit_stake_internal( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::DepositStakeWithSlippage { + data: borsh::to_vec(&StakePoolInstruction::DepositStakeWithSlippage { minimum_pool_tokens_out, - } - .try_to_vec() + }) .unwrap(), } } else { Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::DepositStake.try_to_vec().unwrap(), + data: borsh::to_vec(&StakePoolInstruction::DepositStake).unwrap(), } }, ); @@ -1990,20 +1975,17 @@ fn deposit_sol_internal( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::DepositSolWithSlippage { + data: borsh::to_vec(&StakePoolInstruction::DepositSolWithSlippage { lamports_in, minimum_pool_tokens_out, - } - .try_to_vec() + }) .unwrap(), } } else { Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::DepositSol(lamports_in) - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&StakePoolInstruction::DepositSol(lamports_in)).unwrap(), } } } @@ -2175,20 +2157,17 @@ fn withdraw_stake_internal( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::WithdrawStakeWithSlippage { + data: borsh::to_vec(&StakePoolInstruction::WithdrawStakeWithSlippage { pool_tokens_in, minimum_lamports_out, - } - .try_to_vec() + }) .unwrap(), } } else { Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::WithdrawStake(pool_tokens_in) - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&StakePoolInstruction::WithdrawStake(pool_tokens_in)).unwrap(), } } } @@ -2298,20 +2277,17 @@ fn withdraw_sol_internal( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::WithdrawSolWithSlippage { + data: borsh::to_vec(&StakePoolInstruction::WithdrawSolWithSlippage { pool_tokens_in, minimum_lamports_out, - } - .try_to_vec() + }) .unwrap(), } } else { Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::WithdrawSol(pool_tokens_in) - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&StakePoolInstruction::WithdrawSol(pool_tokens_in)).unwrap(), } } } @@ -2467,7 +2443,7 @@ pub fn set_manager( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::SetManager.try_to_vec().unwrap(), + data: borsh::to_vec(&StakePoolInstruction::SetManager).unwrap(), } } @@ -2485,7 +2461,7 @@ pub fn set_fee( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::SetFee { fee }.try_to_vec().unwrap(), + data: borsh::to_vec(&StakePoolInstruction::SetFee { fee }).unwrap(), } } @@ -2504,7 +2480,7 @@ pub fn set_staker( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::SetStaker.try_to_vec().unwrap(), + data: borsh::to_vec(&StakePoolInstruction::SetStaker).unwrap(), } } @@ -2526,9 +2502,7 @@ pub fn set_funding_authority( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::SetFundingAuthority(funding_type) - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&StakePoolInstruction::SetFundingAuthority(funding_type)).unwrap(), } } @@ -2558,8 +2532,7 @@ pub fn update_token_metadata( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::UpdateTokenMetadata { name, symbol, uri } - .try_to_vec() + data: borsh::to_vec(&StakePoolInstruction::UpdateTokenMetadata { name, symbol, uri }) .unwrap(), } } @@ -2594,8 +2567,7 @@ pub fn create_token_metadata( Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::CreateTokenMetadata { name, symbol, uri } - .try_to_vec() + data: borsh::to_vec(&StakePoolInstruction::CreateTokenMetadata { name, symbol, uri }) .unwrap(), } } diff --git a/stake-pool/program/src/state.rs b/stake-pool/program/src/state.rs index 135639b39cd..e2b79d535db 100644 --- a/stake-pool/program/src/state.rs +++ b/stake-pool/program/src/state.rs @@ -1162,7 +1162,7 @@ mod test { fn validator_list_deserialize_mut_slice() { let max_validators = 10; let stake_list = test_validator_list(max_validators); - let mut serialized = stake_list.try_to_vec().unwrap(); + let mut serialized = borsh::to_vec(&stake_list).unwrap(); let (header, mut big_vec) = ValidatorListHeader::deserialize_vec(&mut serialized).unwrap(); let list = ValidatorListHeader::deserialize_mut_slice( &mut big_vec, @@ -1207,7 +1207,7 @@ mod test { fn validator_list_iter() { let max_validators = 10; let stake_list = test_validator_list(max_validators); - let mut serialized = stake_list.try_to_vec().unwrap(); + let mut serialized = borsh::to_vec(&stake_list).unwrap(); let (_, big_vec) = ValidatorListHeader::deserialize_vec(&mut serialized).unwrap(); for (a, b) in big_vec .deserialize_slice::(0, big_vec.len() as usize) diff --git a/stake-pool/program/tests/deposit.rs b/stake-pool/program/tests/deposit.rs index 716f3fbec75..0b333e47cfc 100644 --- a/stake-pool/program/tests/deposit.rs +++ b/stake-pool/program/tests/deposit.rs @@ -4,7 +4,6 @@ mod helpers; use { - borsh::BorshSerialize, helpers::*, solana_program::{ borsh1::try_from_slice_unchecked, @@ -498,9 +497,7 @@ async fn fail_with_wrong_stake_program_id() { let instruction = Instruction { program_id: id(), accounts, - data: instruction::StakePoolInstruction::DepositStake - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&instruction::StakePoolInstruction::DepositStake).unwrap(), }; let mut transaction = diff --git a/stake-pool/program/tests/helpers/mod.rs b/stake-pool/program/tests/helpers/mod.rs index e87d153c63c..b68d7c8c78c 100644 --- a/stake-pool/program/tests/helpers/mod.rs +++ b/stake-pool/program/tests/helpers/mod.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] use { - borsh::{BorshDeserialize, BorshSerialize}, + borsh::BorshDeserialize, solana_program::{ borsh1::{get_instance_packed_len, get_packed_len, try_from_slice_unchecked}, hash::Hash, @@ -2539,7 +2539,7 @@ pub fn add_stake_pool_account( stake_pool_pubkey: &Pubkey, stake_pool: &state::StakePool, ) { - let mut stake_pool_bytes = stake_pool.try_to_vec().unwrap(); + let mut stake_pool_bytes = borsh::to_vec(&stake_pool).unwrap(); // more room for optionals stake_pool_bytes.extend_from_slice(Pubkey::default().as_ref()); stake_pool_bytes.extend_from_slice(Pubkey::default().as_ref()); @@ -2559,11 +2559,11 @@ pub fn add_validator_list_account( validator_list: &state::ValidatorList, max_validators: u32, ) { - let mut validator_list_bytes = validator_list.try_to_vec().unwrap(); + let mut validator_list_bytes = borsh::to_vec(&validator_list).unwrap(); // add extra room if needed for _ in validator_list.validators.len()..max_validators as usize { validator_list_bytes - .append(&mut state::ValidatorStakeInfo::default().try_to_vec().unwrap()); + .append(&mut borsh::to_vec(&state::ValidatorStakeInfo::default()).unwrap()); } let validator_list_account = SolanaAccount::create( ACCOUNT_RENT_EXEMPTION, diff --git a/stake-pool/program/tests/initialize.rs b/stake-pool/program/tests/initialize.rs index 6b15631aaf4..fa65c709908 100644 --- a/stake-pool/program/tests/initialize.rs +++ b/stake-pool/program/tests/initialize.rs @@ -5,7 +5,6 @@ mod helpers; use { - borsh::BorshSerialize, helpers::*, solana_program::{ borsh1::{get_instance_packed_len, get_packed_len, try_from_slice_unchecked}, @@ -1200,7 +1199,7 @@ async fn fail_without_manager_signature() { referral_fee: stake_pool_accounts.referral_fee, max_validators: stake_pool_accounts.max_validators, }; - let data = init_data.try_to_vec().unwrap(); + let data = borsh::to_vec(&init_data).unwrap(); let accounts = vec![ AccountMeta::new(stake_pool_accounts.stake_pool.pubkey(), true), AccountMeta::new_readonly(stake_pool_accounts.manager.pubkey(), false), diff --git a/stake-pool/program/tests/set_funding_authority.rs b/stake-pool/program/tests/set_funding_authority.rs index eb24a10397c..ee2722d81d6 100644 --- a/stake-pool/program/tests/set_funding_authority.rs +++ b/stake-pool/program/tests/set_funding_authority.rs @@ -4,7 +4,6 @@ mod helpers; use { - borsh::BorshSerialize, helpers::*, solana_program::{ borsh1::try_from_slice_unchecked, @@ -136,9 +135,10 @@ async fn fail_without_signature() { let (mut banks_client, payer, recent_blockhash, stake_pool_accounts, new_authority) = setup().await; - let data = instruction::StakePoolInstruction::SetFundingAuthority(FundingType::StakeDeposit) - .try_to_vec() - .unwrap(); + let data = borsh::to_vec(&instruction::StakePoolInstruction::SetFundingAuthority( + FundingType::StakeDeposit, + )) + .unwrap(); let accounts = vec![ AccountMeta::new(stake_pool_accounts.stake_pool.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.manager.pubkey(), false), diff --git a/stake-pool/program/tests/set_manager.rs b/stake-pool/program/tests/set_manager.rs index 9ce2b6387c8..3172d3bf3ee 100644 --- a/stake-pool/program/tests/set_manager.rs +++ b/stake-pool/program/tests/set_manager.rs @@ -4,7 +4,6 @@ mod helpers; use { - borsh::BorshSerialize, helpers::*, solana_program::{ borsh1::try_from_slice_unchecked, @@ -134,9 +133,7 @@ async fn test_set_manager_without_existing_signature() { let (mut banks_client, payer, recent_blockhash, stake_pool_accounts, new_pool_fee, new_manager) = setup().await; - let data = instruction::StakePoolInstruction::SetManager - .try_to_vec() - .unwrap(); + let data = borsh::to_vec(&instruction::StakePoolInstruction::SetManager).unwrap(); let accounts = vec![ AccountMeta::new(stake_pool_accounts.stake_pool.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.manager.pubkey(), false), @@ -177,9 +174,7 @@ async fn test_set_manager_without_new_signature() { let (mut banks_client, payer, recent_blockhash, stake_pool_accounts, new_pool_fee, new_manager) = setup().await; - let data = instruction::StakePoolInstruction::SetManager - .try_to_vec() - .unwrap(); + let data = borsh::to_vec(&instruction::StakePoolInstruction::SetManager).unwrap(); let accounts = vec![ AccountMeta::new(stake_pool_accounts.stake_pool.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.manager.pubkey(), true), diff --git a/stake-pool/program/tests/set_staker.rs b/stake-pool/program/tests/set_staker.rs index 9d382e30521..bef7c8837d1 100644 --- a/stake-pool/program/tests/set_staker.rs +++ b/stake-pool/program/tests/set_staker.rs @@ -4,7 +4,6 @@ mod helpers; use { - borsh::BorshSerialize, helpers::*, solana_program::{ borsh1::try_from_slice_unchecked, @@ -150,9 +149,7 @@ async fn fail_set_staker_without_signature() { let (mut banks_client, payer, recent_blockhash, stake_pool_accounts, new_staker) = setup().await; - let data = instruction::StakePoolInstruction::SetStaker - .try_to_vec() - .unwrap(); + let data = borsh::to_vec(&instruction::StakePoolInstruction::SetStaker).unwrap(); let accounts = vec![ AccountMeta::new(stake_pool_accounts.stake_pool.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.manager.pubkey(), false), diff --git a/stake-pool/program/tests/vsa_add.rs b/stake-pool/program/tests/vsa_add.rs index ded392063cb..3016a28d8b9 100644 --- a/stake-pool/program/tests/vsa_add.rs +++ b/stake-pool/program/tests/vsa_add.rs @@ -5,7 +5,6 @@ mod helpers; use { bincode::deserialize, - borsh::BorshSerialize, helpers::*, solana_program::{ borsh1::try_from_slice_unchecked, @@ -292,13 +291,12 @@ async fn fail_without_signature() { let instruction = Instruction { program_id: id(), accounts, - data: instruction::StakePoolInstruction::AddValidatorToPool( + data: borsh::to_vec(&instruction::StakePoolInstruction::AddValidatorToPool( validator_stake .validator_stake_seed .map(|s| s.get()) .unwrap_or(0), - ) - .try_to_vec() + )) .unwrap(), }; @@ -348,13 +346,12 @@ async fn fail_with_wrong_stake_program_id() { let instruction = Instruction { program_id: id(), accounts, - data: instruction::StakePoolInstruction::AddValidatorToPool( + data: borsh::to_vec(&instruction::StakePoolInstruction::AddValidatorToPool( validator_stake .validator_stake_seed .map(|s| s.get()) .unwrap_or(0), - ) - .try_to_vec() + )) .unwrap(), }; let mut transaction = Transaction::new_with_payer(&[instruction], Some(&payer.pubkey())); @@ -402,13 +399,12 @@ async fn fail_with_wrong_system_program_id() { let instruction = Instruction { program_id: id(), accounts, - data: instruction::StakePoolInstruction::AddValidatorToPool( + data: borsh::to_vec(&instruction::StakePoolInstruction::AddValidatorToPool( validator_stake .validator_stake_seed .map(|s| s.get()) .unwrap_or(0), - ) - .try_to_vec() + )) .unwrap(), }; let mut transaction = Transaction::new_with_payer(&[instruction], Some(&payer.pubkey())); diff --git a/stake-pool/program/tests/vsa_remove.rs b/stake-pool/program/tests/vsa_remove.rs index ea9f7cc9ba7..46571865b2b 100644 --- a/stake-pool/program/tests/vsa_remove.rs +++ b/stake-pool/program/tests/vsa_remove.rs @@ -5,7 +5,6 @@ mod helpers; use { bincode::deserialize, - borsh::BorshSerialize, helpers::*, solana_program::{ borsh1::try_from_slice_unchecked, @@ -139,9 +138,7 @@ async fn fail_with_wrong_stake_program_id() { let instruction = Instruction { program_id: id(), accounts, - data: instruction::StakePoolInstruction::RemoveValidatorFromPool - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&instruction::StakePoolInstruction::RemoveValidatorFromPool).unwrap(), }; let mut transaction = @@ -356,9 +353,7 @@ async fn fail_no_signature() { let instruction = Instruction { program_id: id(), accounts, - data: instruction::StakePoolInstruction::RemoveValidatorFromPool - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&instruction::StakePoolInstruction::RemoveValidatorFromPool).unwrap(), }; let transaction = Transaction::new_signed_with_payer( diff --git a/stake-pool/program/tests/withdraw.rs b/stake-pool/program/tests/withdraw.rs index 1718eba0fb7..84401a1e91c 100644 --- a/stake-pool/program/tests/withdraw.rs +++ b/stake-pool/program/tests/withdraw.rs @@ -4,7 +4,6 @@ mod helpers; use { - borsh::BorshSerialize, helpers::*, solana_program::{ borsh1::try_from_slice_unchecked, @@ -291,9 +290,10 @@ async fn fail_with_wrong_stake_program() { let instruction = Instruction { program_id: id(), accounts, - data: instruction::StakePoolInstruction::WithdrawStake(tokens_to_burn) - .try_to_vec() - .unwrap(), + data: borsh::to_vec(&instruction::StakePoolInstruction::WithdrawStake( + tokens_to_burn, + )) + .unwrap(), }; let transaction = Transaction::new_signed_with_payer( diff --git a/stateless-asks/program/src/instruction.rs b/stateless-asks/program/src/instruction.rs index 71fef665f72..07e79af4536 100644 --- a/stateless-asks/program/src/instruction.rs +++ b/stateless-asks/program/src/instruction.rs @@ -63,7 +63,7 @@ pub fn accept_offer( taker_size, bump_seed, }; - let data = init_data.try_to_vec().unwrap(); + let data = borsh::to_vec(&init_data).unwrap(); let mut accounts = vec![ AccountMeta::new_readonly(*maker_wallet, false), AccountMeta::new_readonly(*taker_wallet, true), @@ -113,7 +113,7 @@ pub fn accept_offer_with_metadata( taker_size, bump_seed, }; - let data = init_data.try_to_vec().unwrap(); + let data = borsh::to_vec(&init_data).unwrap(); let mut accounts = vec![ AccountMeta::new_readonly(*maker_wallet, false), AccountMeta::new_readonly(*taker_wallet, true), diff --git a/token-metadata/example/tests/emit.rs b/token-metadata/example/tests/emit.rs index b016a8dbd9d..bfac603451b 100644 --- a/token-metadata/example/tests/emit.rs +++ b/token-metadata/example/tests/emit.rs @@ -8,9 +8,7 @@ use { borsh1::try_from_slice_unchecked, program::MAX_RETURN_DATA, pubkey::Pubkey, signature::Signer, signer::keypair::Keypair, transaction::Transaction, }, - spl_token_metadata_interface::{ - borsh::BorshSerialize, instruction::emit, state::TokenMetadata, - }, + spl_token_metadata_interface::{borsh, instruction::emit, state::TokenMetadata}, test_case::test_case, }; @@ -79,7 +77,7 @@ async fn success(start: Option, end: Option) { .await .unwrap(); - let metadata_buffer = token_metadata.try_to_vec().unwrap(); + let metadata_buffer = borsh::to_vec(&token_metadata).unwrap(); if let Some(check_buffer) = TokenMetadata::get_slice(&metadata_buffer, start, end) { if !check_buffer.is_empty() { // pad the data if necessary diff --git a/token-metadata/interface/src/instruction.rs b/token-metadata/interface/src/instruction.rs index 6be22fc47dc..bcb606b3a8b 100644 --- a/token-metadata/interface/src/instruction.rs +++ b/token-metadata/interface/src/instruction.rs @@ -201,23 +201,23 @@ impl TokenMetadataInstruction { match self { Self::Initialize(data) => { buf.extend_from_slice(Initialize::SPL_DISCRIMINATOR_SLICE); - buf.append(&mut data.try_to_vec().unwrap()); + buf.append(&mut borsh::to_vec(data).unwrap()); } Self::UpdateField(data) => { buf.extend_from_slice(UpdateField::SPL_DISCRIMINATOR_SLICE); - buf.append(&mut data.try_to_vec().unwrap()); + buf.append(&mut borsh::to_vec(data).unwrap()); } Self::RemoveKey(data) => { buf.extend_from_slice(RemoveKey::SPL_DISCRIMINATOR_SLICE); - buf.append(&mut data.try_to_vec().unwrap()); + buf.append(&mut borsh::to_vec(data).unwrap()); } Self::UpdateAuthority(data) => { buf.extend_from_slice(UpdateAuthority::SPL_DISCRIMINATOR_SLICE); - buf.append(&mut data.try_to_vec().unwrap()); + buf.append(&mut borsh::to_vec(data).unwrap()); } Self::Emit(data) => { buf.extend_from_slice(Emit::SPL_DISCRIMINATOR_SLICE); - buf.append(&mut data.try_to_vec().unwrap()); + buf.append(&mut borsh::to_vec(data).unwrap()); } }; buf @@ -333,7 +333,7 @@ mod test { ) { let mut expect = vec![]; expect.extend_from_slice(discriminator.as_ref()); - expect.append(&mut data.try_to_vec().unwrap()); + expect.append(&mut borsh::to_vec(&data).unwrap()); let packed = instruction.pack(); assert_eq!(packed, expect); let unpacked = TokenMetadataInstruction::unpack(&expect).unwrap(); diff --git a/token/program-2022-test/tests/token_metadata_emit.rs b/token/program-2022-test/tests/token_metadata_emit.rs index 0812a225a01..9de6a5e37f8 100644 --- a/token/program-2022-test/tests/token_metadata_emit.rs +++ b/token/program-2022-test/tests/token_metadata_emit.rs @@ -10,9 +10,7 @@ use { }, spl_token_2022::processor::Processor, spl_token_client::token::ExtensionInitializationParams, - spl_token_metadata_interface::{ - borsh::BorshSerialize, instruction::emit, state::TokenMetadata, - }, + spl_token_metadata_interface::{instruction::emit, state::TokenMetadata}, std::{convert::TryInto, sync::Arc}, test_case::test_case, }; @@ -113,7 +111,7 @@ async fn success(start: Option, end: Option) { .await .unwrap(); - let metadata_buffer = token_metadata.try_to_vec().unwrap(); + let metadata_buffer = borsh::to_vec(&token_metadata).unwrap(); if let Some(check_buffer) = TokenMetadata::get_slice(&metadata_buffer, start, end) { if !check_buffer.is_empty() { // pad the data if necessary