From 3d529d19fa82e5f37c88fd4cdc0f11c62b8875b1 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Tue, 2 Dec 2025 10:48:21 -0300 Subject: [PATCH] solve comments --- nssa/core/src/program.rs | 2 +- nssa/program_methods/guest/src/bin/token.rs | 39 ++++++++++----------- nssa/src/public_transaction/transaction.rs | 2 +- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/nssa/core/src/program.rs b/nssa/core/src/program.rs index 1028d54..b48a08b 100644 --- a/nssa/core/src/program.rs +++ b/nssa/core/src/program.rs @@ -14,7 +14,7 @@ pub struct ProgramInput { /// A 32-byte seed used to compute a *Program-Derived AccountId* (PDA). /// -/// Each program can derive up to `2^32` unique account IDs by choosing different +/// Each program can derive up to `2^256` unique account IDs by choosing different /// seeds. PDAs allow programs to control namespaced account identifiers without /// collisions between programs. #[derive(Serialize, Deserialize, Clone)] diff --git a/nssa/program_methods/guest/src/bin/token.rs b/nssa/program_methods/guest/src/bin/token.rs index 0109c2b..b527045 100644 --- a/nssa/program_methods/guest/src/bin/token.rs +++ b/nssa/program_methods/guest/src/bin/token.rs @@ -82,25 +82,25 @@ impl TokenHolding { fn parse(data: &[u8]) -> Option { if data.len() != TOKEN_HOLDING_DATA_SIZE || data[0] != TOKEN_HOLDING_TYPE { - None - } else { - let account_type = data[0]; - let definition_id = AccountId::new( - data[1..33] - .try_into() - .expect("Defintion ID must be 32 bytes long"), - ); - let balance = u128::from_le_bytes( - data[33..] - .try_into() - .expect("balance must be 16 bytes little-endian"), - ); - Some(Self { - definition_id, - balance, - account_type, - }) + return None; } + + let account_type = data[0]; + let definition_id = AccountId::new( + data[1..33] + .try_into() + .expect("Defintion ID must be 32 bytes long"), + ); + let balance = u128::from_le_bytes( + data[33..] + .try_into() + .expect("balance must be 16 bytes little-endian"), + ); + Some(Self { + definition_id, + balance, + account_type, + }) } fn into_data(self) -> Data { @@ -211,7 +211,7 @@ fn initialize_account(pre_states: &[AccountWithMetadata]) -> Vec { panic!("Only uninitialized accounts can be initialized"); } - // TODO: We should check that this is an account owned by the token program. + // 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 @@ -278,7 +278,6 @@ fn main() { write_nssa_outputs(pre_states, post_states); } - #[cfg(test)] mod tests { use nssa_core::account::{Account, AccountId, AccountWithMetadata}; diff --git a/nssa/src/public_transaction/transaction.rs b/nssa/src/public_transaction/transaction.rs index cafa27b..b8c0a8d 100644 --- a/nssa/src/public_transaction/transaction.rs +++ b/nssa/src/public_transaction/transaction.rs @@ -145,7 +145,7 @@ impl PublicTransaction { // authorized by program through the PDA mechanism let is_authorized = signer_account_ids.contains(&account_id) || authorized_pdas.contains(&account_id); - if pre.is_authorized && !is_authorized { + if pre.is_authorized != is_authorized { return Err(NssaError::InvalidProgramBehavior); } }