Fallback to base64 account encoding if json parse fails (#11483)

* Fallback to base64 account encoding if json parse fails

* Remove default binary conversion
This commit is contained in:
Justin Starry 2020-08-09 18:28:25 +08:00 committed by GitHub
parent a9f76862fb
commit ebc45bd73f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 8 deletions

View File

@ -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 {
@ -59,7 +53,9 @@ 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) =
@ -67,7 +63,7 @@ impl UiAccount {
{
UiAccountData::Json(parsed_data)
} else {
account.data.into()
UiAccountData::Binary64(base64::encode(account.data))
}
}
};