Skip to content

Commit bbd57d4

Browse files
authored
account: Temporarily revert breaking changes (anza-xyz#549)
* Revert "Remove `fn create` from `WritableAccount` (anza-xyz#522)" This reverts commit 604f9bf. * Revert "Remove `to_account_shared_data` from ReadableAccount (anza-xyz#386)" This reverts commit 9c74622.
1 parent db8feec commit bbd57d4

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

account/src/lib.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ pub trait WritableAccount: ReadableAccount {
204204
fn copy_into_owner_from_slice(&mut self, source: &[u8]);
205205
fn set_executable(&mut self, executable: bool);
206206
fn set_rent_epoch(&mut self, epoch: Epoch);
207+
#[deprecated(since = "3.3.0")]
208+
fn create(
209+
lamports: u64,
210+
data: Vec<u8>,
211+
owner: Pubkey,
212+
executable: bool,
213+
rent_epoch: Epoch,
214+
) -> Self;
207215
}
208216

209217
pub trait ReadableAccount: Sized {
@@ -212,6 +220,17 @@ pub trait ReadableAccount: Sized {
212220
fn owner(&self) -> &Pubkey;
213221
fn executable(&self) -> bool;
214222
fn rent_epoch(&self) -> Epoch;
223+
#[deprecated(since = "3.2.0")]
224+
fn to_account_shared_data(&self) -> AccountSharedData {
225+
#[allow(deprecated)]
226+
AccountSharedData::create(
227+
self.lamports(),
228+
self.data().to_vec(),
229+
*self.owner(),
230+
self.executable(),
231+
self.rent_epoch(),
232+
)
233+
}
215234
}
216235

217236
impl<T> ReadableAccount for T
@@ -273,6 +292,21 @@ impl WritableAccount for Account {
273292
fn set_rent_epoch(&mut self, epoch: Epoch) {
274293
self.rent_epoch = epoch;
275294
}
295+
fn create(
296+
lamports: u64,
297+
data: Vec<u8>,
298+
owner: Pubkey,
299+
executable: bool,
300+
rent_epoch: Epoch,
301+
) -> Self {
302+
Account {
303+
lamports,
304+
data,
305+
owner,
306+
executable,
307+
rent_epoch,
308+
}
309+
}
276310
}
277311

278312
impl WritableAccount for AccountSharedData {
@@ -294,6 +328,21 @@ impl WritableAccount for AccountSharedData {
294328
fn set_rent_epoch(&mut self, epoch: Epoch) {
295329
self.rent_epoch = epoch;
296330
}
331+
fn create(
332+
lamports: u64,
333+
data: Vec<u8>,
334+
owner: Pubkey,
335+
executable: bool,
336+
rent_epoch: Epoch,
337+
) -> Self {
338+
AccountSharedData {
339+
lamports,
340+
data: Arc::new(data),
341+
owner,
342+
executable,
343+
rent_epoch,
344+
}
345+
}
297346
}
298347

299348
impl ReadableAccount for AccountSharedData {
@@ -312,6 +361,10 @@ impl ReadableAccount for AccountSharedData {
312361
fn rent_epoch(&self) -> Epoch {
313362
self.rent_epoch
314363
}
364+
fn to_account_shared_data(&self) -> AccountSharedData {
365+
// avoid data copy here
366+
self.clone()
367+
}
315368
}
316369

317370
fn debug_fmt<T: ReadableAccount>(item: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -792,6 +845,18 @@ pub mod tests {
792845
account2.serialize_data(&"hello world").unwrap();
793846
}
794847

848+
#[test]
849+
#[allow(deprecated)]
850+
fn test_to_account_shared_data() {
851+
let key = Pubkey::new_unique();
852+
let (account1, account2) = make_two_accounts(&key);
853+
assert!(accounts_equal(&account1, &account2));
854+
let account3 = account1.to_account_shared_data();
855+
let account4 = account2.to_account_shared_data();
856+
assert!(accounts_equal(&account1, &account3));
857+
assert!(accounts_equal(&account1, &account4));
858+
}
859+
795860
#[test]
796861
fn test_account_shared_data() {
797862
let key = Pubkey::new_unique();

0 commit comments

Comments
 (0)