diff --git a/src/processor/fast/utils/requires.rs b/src/processor/fast/utils/requires.rs index 521d6ee9..f4688b8e 100644 --- a/src/processor/fast/utils/requires.rs +++ b/src/processor/fast/utils/requires.rs @@ -74,12 +74,10 @@ pub fn require_pda( return Err(ProgramError::InvalidSeeds); } - if !info.is_writable().eq(&is_writable) { - // TODO (snawaz): misleading msg - // also better use more granular error here ProgramError::InvalidPermission + if is_writable && !info.is_writable() { log!("Account needs to be writable. Label: {}", label); pubkey::log(info.key()); - return Err(ProgramError::InvalidAccountData); + return Err(ProgramError::Immutable); } Ok(pda.1) @@ -124,7 +122,7 @@ pub fn require_uninitialized_account( if is_writable && !info.is_writable() { log!("Account needs to be writable. label: {}, account: ", label); pubkey::log(info.key()); - return Err(ProgramError::InvalidAccountData); + return Err(ProgramError::Immutable); } Ok(()) @@ -176,7 +174,7 @@ pub fn require_initialized_pda( if is_writable && !info.is_writable() { log!("Account needs to be writable. label: {}, account: ", label); pubkey::log(info.key()); - return Err(ProgramError::InvalidAccountData); + return Err(ProgramError::Immutable); } Ok(pda.1) diff --git a/src/processor/utils/loaders.rs b/src/processor/utils/loaders.rs index a88deb00..21e012fd 100644 --- a/src/processor/utils/loaders.rs +++ b/src/processor/utils/loaders.rs @@ -50,11 +50,9 @@ pub fn load_pda( return Err(ProgramError::InvalidSeeds); } - if !info.is_writable.eq(&is_writable) { - // TODO (snawaz): misleading msg - // also better use more granular error here ProgramError::InvalidPermission + if is_writable && !info.is_writable { msg!("Account {} ({}) needs to be writable", label, info.key); - return Err(ProgramError::InvalidAccountData); + return Err(ProgramError::Immutable); } Ok(pda.1) @@ -103,7 +101,7 @@ pub fn load_initialized_pda( if is_writable && !info.is_writable { msg!("Account {} is not writable", info.key); - return Err(ProgramError::InvalidAccountData); + return Err(ProgramError::Immutable); } Ok(pda.1) @@ -143,7 +141,7 @@ pub fn load_uninitialized_account( if is_writable && !info.is_writable { msg!("Account {} ({}) needs to be writable", label, info.key); - return Err(ProgramError::InvalidAccountData); + return Err(ProgramError::Immutable); } Ok(()) @@ -178,7 +176,7 @@ pub fn load_account( if is_writable && !info.is_writable { msg!("Account {} ({}) needs to be writable", label, info.key); - return Err(ProgramError::InvalidAccountData); + return Err(ProgramError::Immutable); } Ok(())