From 987d3fcaf7ac1028852ffe7e8193d5cbc7294006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Mon, 24 Jan 2022 18:37:11 +0100 Subject: [PATCH] Implements account resizing in BorrowedAccount. --- sdk/src/transaction_context.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sdk/src/transaction_context.rs b/sdk/src/transaction_context.rs index 45ef3fe9bfd376..8d29989f91426c 100644 --- a/sdk/src/transaction_context.rs +++ b/sdk/src/transaction_context.rs @@ -472,10 +472,15 @@ impl<'a> BorrowedAccount<'a> { self.verify_writability() } - /*pub fn realloc(&self, new_len: usize, zero_init: bool) { + /// Resizes the account data (transaction wide) + /// + /// Fills it with zeros at the end if is extended or truncates at the end otherwise. + pub fn set_data_length(&mut self, new_len: usize) -> Result<(), InstructionError> { + self.account.data_mut().resize(new_len, 0); // TODO: return Err(InstructionError::InvalidRealloc); // TODO: return Err(InstructionError::AccountDataSizeChanged); - }*/ + self.verify_writability() + } /// Deserializes the account data into a state pub fn get_state(&self) -> Result {