Add Binary64 option for account data (#11474)

* Add Binary64 option for account data

* Decode into binary64

* Reword docs
This commit is contained in:
sakridge
2020-08-08 22:40:13 -07:00
committed by GitHub
parent 4d918f83ff
commit 068d23f298
8 changed files with 59 additions and 18 deletions

View File

@ -9,6 +9,7 @@ license = "Apache-2.0"
edition = "2018"
[dependencies]
base64 = "0.12.3"
bincode = "1.3.1"
bs58 = "0.3.1"
Inflector = "0.11.4"

View File

@ -30,6 +30,7 @@ pub struct UiAccount {
pub enum UiAccountData {
Binary(String),
Json(ParsedAccount),
Binary64(String),
}
impl From<Vec<u8>> for UiAccountData {
@ -43,6 +44,7 @@ impl From<Vec<u8>> for UiAccountData {
pub enum UiAccountEncoding {
Binary,
JsonParsed,
Binary64,
}
impl UiAccount {
@ -53,6 +55,7 @@ impl UiAccount {
) -> Self {
let data = match encoding {
UiAccountEncoding::Binary => account.data.into(),
UiAccountEncoding::Binary64 => UiAccountData::Binary64(base64::encode(account.data)),
UiAccountEncoding::JsonParsed => {
if let Ok(parsed_data) =
parse_account_data(&account.owner, &account.data, additional_data)
@ -76,6 +79,7 @@ impl UiAccount {
let data = match &self.data {
UiAccountData::Json(_) => None,
UiAccountData::Binary(blob) => bs58::decode(blob).into_vec().ok(),
UiAccountData::Binary64(blob) => base64::decode(blob).ok(),
}?;
Some(Account {
lamports: self.lamports,