Remove dependency on hex (#21567)

* Remove dependency on `hex`

* Update lock file

* Use `debug_struct` instead of own format

* Share code, add test, and fix rent_epoch spelling

Co-authored-by: Tyera Eulberg <tyera@solana.com>
This commit is contained in:
fee1-dead
2021-12-04 11:53:35 +08:00
committed by GitHub
parent e130b2cffc
commit c4a9c8b5e9
8 changed files with 136 additions and 49 deletions

View File

@ -4,10 +4,10 @@ use {
lamports::LamportsError,
pubkey::Pubkey,
},
solana_program::{account_info::AccountInfo, sysvar::Sysvar},
solana_program::{account_info::AccountInfo, debug_account_data::*, sysvar::Sysvar},
std::{
cell::{Ref, RefCell},
cmp, fmt,
fmt,
rc::Rc,
sync::Arc,
},
@ -280,22 +280,16 @@ impl ReadableAccount for Ref<'_, Account> {
}
fn debug_fmt<T: ReadableAccount>(item: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let data_len = cmp::min(64, item.data().len());
let data_str = if data_len > 0 {
format!(" data: {}", hex::encode(item.data()[..data_len].to_vec()))
} else {
"".to_string()
};
write!(
f,
"Account {{ lamports: {} data.len: {} owner: {} executable: {} rent_epoch: {}{} }}",
item.lamports(),
item.data().len(),
item.owner(),
item.executable(),
item.rent_epoch(),
data_str,
)
let mut f = f.debug_struct("Account");
f.field("lamports", &item.lamports())
.field("data.len", &item.data().len())
.field("owner", &item.owner())
.field("executable", &item.executable())
.field("rent_epoch", &item.rent_epoch());
debug_account_data(item.data(), &mut f);
f.finish()
}
impl fmt::Debug for Account {