Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Implements ReadableAccount for RefMut Account and AccountSharedData #34370

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion sdk/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use {
},
solana_program::{account_info::AccountInfo, debug_account_data::*, sysvar::Sysvar},
std::{
cell::{Ref, RefCell},
cell::{Ref, RefCell, RefMut},
fmt,
mem::MaybeUninit,
ptr,
Expand Down Expand Up @@ -351,6 +351,34 @@ impl ReadableAccount for Ref<'_, AccountSharedData> {
}
}

impl ReadableAccount for RefMut<'_, AccountSharedData> {
fn lamports(&self) -> u64 {
self.lamports
}
fn data(&self) -> &[u8] {
&self.data
}
fn owner(&self) -> &Pubkey {
&self.owner
}
fn executable(&self) -> bool {
self.executable
}
fn rent_epoch(&self) -> Epoch {
self.rent_epoch
}
fn to_account_shared_data(&self) -> AccountSharedData {
AccountSharedData {
lamports: self.lamports(),
// avoid data copy here
data: Arc::clone(&self.data),
owner: *self.owner(),
executable: self.executable(),
rent_epoch: self.rent_epoch(),
}
}
}

impl ReadableAccount for Ref<'_, Account> {
fn lamports(&self) -> u64 {
self.lamports
Expand All @@ -369,6 +397,24 @@ impl ReadableAccount for Ref<'_, Account> {
}
}

impl ReadableAccount for RefMut<'_, Account> {
fn lamports(&self) -> u64 {
self.lamports
}
fn data(&self) -> &[u8] {
&self.data
}
fn owner(&self) -> &Pubkey {
&self.owner
}
fn executable(&self) -> bool {
self.executable
}
fn rent_epoch(&self) -> Epoch {
self.rent_epoch
}
}

fn debug_fmt<T: ReadableAccount>(item: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut f = f.debug_struct("Account");

Expand Down