Skip to content

Commit

Permalink
token 2022: add alloc_and_serialize for fixed-len extensions (#5672)
Browse files Browse the repository at this point in the history
* token 2022: add alloc_and_serialize for fixed-len extensions

* add tandem try_get_new_account_len functions

* refactor alloc_and_serialize

* added tests for alloc_and_serialize (fixed)

* address feedback
  • Loading branch information
buffalojoec authored Nov 8, 2023
1 parent 91846f3 commit 6c83a84
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 54 deletions.
6 changes: 4 additions & 2 deletions token/client/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3458,7 +3458,8 @@ where
let account = self.get_account(self.pubkey).await?;
let account_lamports = account.lamports;
let mint_state = self.unpack_mint_info(account)?;
let new_account_len = mint_state.try_get_new_account_len(token_metadata)?;
let new_account_len = mint_state
.try_get_new_account_len_for_variable_len_extension::<TokenMetadata>(token_metadata)?;
let new_rent_exempt_minimum = self
.client
.get_minimum_balance_for_rent_exemption(new_account_len)
Expand Down Expand Up @@ -3540,7 +3541,8 @@ where
let mint_state = self.unpack_mint_info(account)?;
let mut token_metadata = mint_state.get_variable_len_extension::<TokenMetadata>()?;
token_metadata.update(field, value);
let new_account_len = mint_state.try_get_new_account_len(&token_metadata)?;
let new_account_len = mint_state
.try_get_new_account_len_for_variable_len_extension::<TokenMetadata>(&token_metadata)?;
let new_rent_exempt_minimum = self
.client
.get_minimum_balance_for_rent_exemption(new_account_len)
Expand Down
Loading

0 comments on commit 6c83a84

Please sign in to comment.