sdk: Add Borsh support for types and utilities (#15290)
* sdk: Add Borsh to Pubkey * Add serialization error for easier borsh integration * Add Borsh usage to banks-client and sdk * Rename SerializationError -> IOError * Add new errors to proto * Update Cargo lock * Update Cargo.lock based on CI * Clippy * Update ABI on bank * Address review feedback * Update sanity program instruction count test
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
use crate::sanitize::Sanitize;
|
||||
use crate::{pubkey::Pubkey, short_vec};
|
||||
use bincode::serialize;
|
||||
use borsh::BorshSerialize;
|
||||
use serde::Serialize;
|
||||
use thiserror::Error;
|
||||
|
||||
@ -186,6 +187,12 @@ pub enum InstructionError {
|
||||
|
||||
#[error("Incorrect authority provided")]
|
||||
IncorrectAuthority,
|
||||
|
||||
#[error("Failed to serialize or deserialize account data: {0}")]
|
||||
IOError(String),
|
||||
|
||||
#[error("An account does not have enough lamports to be rent-exempt")]
|
||||
AccountNotRentExempt,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
||||
@ -207,6 +214,19 @@ impl Instruction {
|
||||
accounts,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_borsh<T: BorshSerialize>(
|
||||
program_id: Pubkey,
|
||||
data: &T,
|
||||
accounts: Vec<AccountMeta>,
|
||||
) -> Self {
|
||||
let data = data.try_to_vec().unwrap();
|
||||
Self {
|
||||
program_id,
|
||||
data,
|
||||
accounts,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn checked_add(a: u64, b: u64) -> Result<u64, InstructionError> {
|
||||
|
Reference in New Issue
Block a user