Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Fallback to base64 account encoding if json parse fails (#11483)
Browse files Browse the repository at this point in the history
* Fallback to base64 account encoding if json parse fails

* Remove default binary conversion

(cherry picked from commit ebc45bd)
  • Loading branch information
jstarry authored and mvines committed Aug 9, 2020
1 parent 8bcc04c commit 768c6b4
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions account-decoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ pub enum UiAccountData {
Binary64(String),
}

impl From<Vec<u8>> for UiAccountData {
fn from(data: Vec<u8>) -> Self {
Self::Binary(bs58::encode(data).into_string())
}
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum UiAccountEncoding {
Expand All @@ -59,15 +53,17 @@ impl UiAccount {
additional_data: Option<AccountAdditionalData>,
) -> Self {
let data = match encoding {
UiAccountEncoding::Binary => account.data.into(),
UiAccountEncoding::Binary => {
UiAccountData::Binary(bs58::encode(account.data).into_string())
}
UiAccountEncoding::Binary64 => UiAccountData::Binary64(base64::encode(account.data)),
UiAccountEncoding::JsonParsed => {
if let Ok(parsed_data) =
parse_account_data(pubkey, &account.owner, &account.data, additional_data)
{
UiAccountData::Json(parsed_data)
} else {
account.data.into()
UiAccountData::Binary64(base64::encode(account.data))
}
}
};
Expand Down

0 comments on commit 768c6b4

Please sign in to comment.