Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion client/src/mock_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ impl RpcSender for MockSender {
}),
meta: Some(UiTransactionStatusMeta {
err: None,
status: Ok(()),
fee: 0,
pre_balances: vec![499999999999999950, 50, 1],
post_balances: vec![499999999999999950, 50, 1],
Expand Down
4 changes: 2 additions & 2 deletions sdk/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ pub enum InstructionError {
/// Borsh versions. Only programs can use this error because they are
/// consistent across Solana software versions.
///
#[error("Failed to serialize or deserialize account data: {0}")]
BorshIoError(String),
#[error("Failed to serialize or deserialize account data")]
BorshIoError,

/// An account does not have enough lamports to be rent-exempt
#[error("An account does not have enough lamports to be rent-exempt")]
Expand Down
18 changes: 9 additions & 9 deletions sdk/program/src/program_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub enum ProgramError {
MaxSeedLengthExceeded,
#[error("Provided seeds do not result in a valid address")]
InvalidSeeds,
#[error("IO Error: {0}")]
BorshIoError(String),
#[error("IO Error")]
BorshIoError,
#[error("An account does not have enough lamports to be rent-exempt")]
AccountNotRentExempt,
#[error("Unsupported sysvar")]
Expand Down Expand Up @@ -93,7 +93,7 @@ impl PrintProgramError for ProgramError {
Self::AccountBorrowFailed => msg!("Error: AccountBorrowFailed"),
Self::MaxSeedLengthExceeded => msg!("Error: MaxSeedLengthExceeded"),
Self::InvalidSeeds => msg!("Error: InvalidSeeds"),
Self::BorshIoError(_) => msg!("Error: BorshIoError"),
Self::BorshIoError => msg!("Error: BorshIoError"),
Self::AccountNotRentExempt => msg!("Error: AccountNotRentExempt"),
Self::UnsupportedSysvar => msg!("Error: UnsupportedSysvar"),
Self::IllegalOwner => msg!("Error: IllegalOwner"),
Expand Down Expand Up @@ -161,7 +161,7 @@ impl From<ProgramError> for u64 {
ProgramError::AccountBorrowFailed => ACCOUNT_BORROW_FAILED,
ProgramError::MaxSeedLengthExceeded => MAX_SEED_LENGTH_EXCEEDED,
ProgramError::InvalidSeeds => INVALID_SEEDS,
ProgramError::BorshIoError(_) => BORSH_IO_ERROR,
ProgramError::BorshIoError => BORSH_IO_ERROR,
ProgramError::AccountNotRentExempt => ACCOUNT_NOT_RENT_EXEMPT,
ProgramError::UnsupportedSysvar => UNSUPPORTED_SYSVAR,
ProgramError::IllegalOwner => ILLEGAL_OWNER,
Expand Down Expand Up @@ -201,7 +201,7 @@ impl From<u64> for ProgramError {
ACCOUNT_BORROW_FAILED => Self::AccountBorrowFailed,
MAX_SEED_LENGTH_EXCEEDED => Self::MaxSeedLengthExceeded,
INVALID_SEEDS => Self::InvalidSeeds,
BORSH_IO_ERROR => Self::BorshIoError("Unknown".to_string()),
BORSH_IO_ERROR => Self::BorshIoError,
ACCOUNT_NOT_RENT_EXEMPT => Self::AccountNotRentExempt,
UNSUPPORTED_SYSVAR => Self::UnsupportedSysvar,
ILLEGAL_OWNER => Self::IllegalOwner,
Expand Down Expand Up @@ -235,7 +235,7 @@ impl TryFrom<InstructionError> for ProgramError {
Self::Error::AccountBorrowFailed => Ok(Self::AccountBorrowFailed),
Self::Error::MaxSeedLengthExceeded => Ok(Self::MaxSeedLengthExceeded),
Self::Error::InvalidSeeds => Ok(Self::InvalidSeeds),
Self::Error::BorshIoError(err) => Ok(Self::BorshIoError(err)),
Self::Error::BorshIoError => Ok(Self::BorshIoError),
Self::Error::AccountNotRentExempt => Ok(Self::AccountNotRentExempt),
Self::Error::UnsupportedSysvar => Ok(Self::UnsupportedSysvar),
Self::Error::IllegalOwner => Ok(Self::IllegalOwner),
Expand Down Expand Up @@ -273,7 +273,7 @@ where
ACCOUNT_BORROW_FAILED => Self::AccountBorrowFailed,
MAX_SEED_LENGTH_EXCEEDED => Self::MaxSeedLengthExceeded,
INVALID_SEEDS => Self::InvalidSeeds,
BORSH_IO_ERROR => Self::BorshIoError("Unknown".to_string()),
BORSH_IO_ERROR => Self::BorshIoError,
ACCOUNT_NOT_RENT_EXEMPT => Self::AccountNotRentExempt,
UNSUPPORTED_SYSVAR => Self::UnsupportedSysvar,
ILLEGAL_OWNER => Self::IllegalOwner,
Expand Down Expand Up @@ -306,7 +306,7 @@ impl From<PubkeyError> for ProgramError {
}

impl From<BorshIoError> for ProgramError {
fn from(error: BorshIoError) -> Self {
Self::BorshIoError(format!("{}", error))
fn from(_: BorshIoError) -> Self {
Self::BorshIoError
}
}
30 changes: 26 additions & 4 deletions transaction-status/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ impl Default for TransactionStatusMeta {
#[serde(rename_all = "camelCase")]
pub struct UiTransactionStatusMeta {
pub err: Option<TransactionError>,
pub status: TransactionResult<()>, // This field is deprecated. See https://github.com/solana-labs/solana/issues/9302
pub fee: u64,
pub pre_balances: Vec<u64>,
pub post_balances: Vec<u64>,
Expand Down Expand Up @@ -407,7 +406,6 @@ impl UiTransactionStatusMeta {
let account_keys = AccountKeys::new(static_keys, Some(&meta.loaded_addresses));
Self {
err: meta.status.clone().err(),
status: meta.status,
fee: meta.fee,
pre_balances: meta.pre_balances,
post_balances: meta.post_balances,
Expand Down Expand Up @@ -440,7 +438,6 @@ impl UiTransactionStatusMeta {
fn build_simple(meta: TransactionStatusMeta, show_rewards: bool) -> Self {
Self {
err: meta.status.clone().err(),
status: meta.status,
fee: meta.fee,
pre_balances: meta.pre_balances,
post_balances: meta.post_balances,
Expand Down Expand Up @@ -470,7 +467,6 @@ impl From<TransactionStatusMeta> for UiTransactionStatusMeta {
fn from(meta: TransactionStatusMeta) -> Self {
Self {
err: meta.status.clone().err(),
status: meta.status,
fee: meta.fee,
pre_balances: meta.pre_balances,
post_balances: meta.post_balances,
Expand Down Expand Up @@ -959,6 +955,12 @@ pub enum EncodedTransaction {
Accounts(UiAccountsList),
}

impl std::default::Default for EncodedTransaction {
fn default() -> Self {
Self::LegacyBinary(String::new())
}
}

impl EncodableWithMeta for VersionedTransaction {
type Encoded = EncodedTransaction;
fn encode_with_meta(
Expand Down Expand Up @@ -1466,4 +1468,24 @@ mod test {
expected_json_output_value
);
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_deserialize_encoded_transaction() {
const JSON_STR: &str = include_str!("./tests/transaction-1.json");
let tx: EncodedTransactionWithStatusMeta = serde_json::from_str(JSON_STR).unwrap();

eprintln!("tx {:?}", tx);
}

#[test]
fn test_deserialize_ui_confirmed_block() {
const JSON_STR: &str = include_str!("./tests/388662392.json");
let res: UiConfirmedBlock = serde_json::from_str(JSON_STR).unwrap();
eprintln!("res {:?}", res);
}
Comment on lines +1473 to +1490
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we check in these tests?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just testing if its able to deserialize what gets returned from RPC

}
Loading