Debug for Account
Derive prints the full userdata vec which is questionably useful.
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
use crate::pubkey::Pubkey;
|
||||
use std::{cmp, fmt};
|
||||
|
||||
/// An Account with userdata that is stored on chain
|
||||
#[repr(C)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, Eq, PartialEq)]
|
||||
#[derive(Serialize, Deserialize, Clone, Default, Eq, PartialEq)]
|
||||
pub struct Account {
|
||||
/// tokens in the account
|
||||
pub tokens: u64,
|
||||
@ -14,6 +15,29 @@ pub struct Account {
|
||||
pub executable: bool,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Account {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let userdata_len = cmp::min(64, self.userdata.len());
|
||||
let userdata_str = if userdata_len > 0 {
|
||||
format!(
|
||||
" userdata: {}",
|
||||
hex::encode(self.userdata[..userdata_len].to_vec())
|
||||
)
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
write!(
|
||||
f,
|
||||
"Account {{ tokens: {} userdata.len: {} owner: {} executable: {}{} }}",
|
||||
self.tokens,
|
||||
self.userdata.len(),
|
||||
self.owner,
|
||||
self.executable,
|
||||
userdata_str,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Account {
|
||||
// TODO do we want to add executable and leader_owner even though they should always be false/default?
|
||||
pub fn new(tokens: u64, space: usize, owner: Pubkey) -> Account {
|
||||
|
Reference in New Issue
Block a user