mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-02-17 20:03:21 +00:00
35 lines
1.2 KiB
Rust
35 lines
1.2 KiB
Rust
use nssa_core::{
|
|
account::{Account, AccountWithMetadata, Data},
|
|
program::AccountPostState,
|
|
};
|
|
use token_core::{TokenDefinition, TokenHolding};
|
|
|
|
pub fn initialize_account(
|
|
definition_account: AccountWithMetadata,
|
|
account_to_initialize: AccountWithMetadata,
|
|
) -> Vec<AccountPostState> {
|
|
assert_eq!(
|
|
account_to_initialize.account,
|
|
Account::default(),
|
|
"Only Uninitialized accounts can be initialized"
|
|
);
|
|
|
|
// TODO: #212 We should check that this is an account owned by the token program.
|
|
// This check can't be done here since the ID of the program is known only after compiling it
|
|
//
|
|
// Check definition account is valid
|
|
let definition = TokenDefinition::try_from(&definition_account.account.data)
|
|
.expect("Definition account must be valid");
|
|
let holding =
|
|
TokenHolding::zeroized_from_definition(definition_account.account_id, &definition);
|
|
|
|
let definition_post = definition_account.account;
|
|
let mut account_to_initialize = account_to_initialize.account;
|
|
account_to_initialize.data = Data::from(&holding);
|
|
|
|
vec![
|
|
AccountPostState::new(definition_post),
|
|
AccountPostState::new_claimed(account_to_initialize),
|
|
]
|
|
}
|