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:
parent
a9f76862fb
commit
ebc45bd73f
|
@ -37,12 +37,6 @@ pub enum UiAccountData {
|
||||||
Binary64(String),
|
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)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub enum UiAccountEncoding {
|
pub enum UiAccountEncoding {
|
||||||
|
@ -59,7 +53,9 @@ impl UiAccount {
|
||||||
additional_data: Option<AccountAdditionalData>,
|
additional_data: Option<AccountAdditionalData>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let data = match encoding {
|
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::Binary64 => UiAccountData::Binary64(base64::encode(account.data)),
|
||||||
UiAccountEncoding::JsonParsed => {
|
UiAccountEncoding::JsonParsed => {
|
||||||
if let Ok(parsed_data) =
|
if let Ok(parsed_data) =
|
||||||
|
@ -67,7 +63,7 @@ impl UiAccount {
|
||||||
{
|
{
|
||||||
UiAccountData::Json(parsed_data)
|
UiAccountData::Json(parsed_data)
|
||||||
} else {
|
} else {
|
||||||
account.data.into()
|
UiAccountData::Binary64(base64::encode(account.data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue