- تاریخ انتشار : شنبه ۲۰ بهمن ۱۴۰۳ - ۴:۳۳
- کد خبر : 1003 چاپ خبر
Solana: Can Other Programs Write to PDA Accounts even if the `Account` type is used and the ownership is checked?
Here is the design of the article on this subject: Solana: Can other programs write on PDA accounts, even if the “account” type is used and the property is verified? When creating decentralized applications (DAPP) on salt, you may meet scenarios in which other programs must access the plasma data account (PDA). The anchoring frame
Here is the design of the article on this subject:
Solana: Can other programs write on PDA accounts, even if the “account” type is used and the property is verified?
When creating decentralized applications (DAPP) on salt, you may meet scenarios in which other programs must access the plasma data account (PDA). The anchoring frame provides a practical way to manage these interactions using macro
[accounts]. However, we often wonder: can other programs write on PDA accounts if the type of “account” is used and the property is verified?
The anchor frame
[Account] Macro
In the anchoring of the frame [
[account]] Macro allows you to define the plasma data account in the program. This account has its own set of variable memory, transactions and methods that can be called. The type of “account” is used to represent these variables and transactions.
When defining the account, the control frame if the ownership of the account is correct, verification:
- The owner of the account is not a current program.
- If the property control fails, the account is marked as uninhabited.
Can other programs write on PDA accounts with a proven property?
Let us see if other programs can write on PDA accounts, even if the type of “account” is used and the property is verified. The short answer is: yes, but only under certain conditions.
After defining the account using macro anchor “[
[
(account]]”] framework adds a variable memory set linked to the owner of the account. You can get other programs for these variables Who have the permission to save on PDA accounts. However, the property control always applies and if it fails, the account is marked as involuntary.
To write on a PDA account with a proven property, you must:
- Make sure the program has the authorizations necessary to access the variable memory linked to the owner of the account.
- Check that the type of "account" is properly used, checking the property of the account before writing it.
Code example: writing on a PDA account with a proven property
Here is an example of fragment of the Solana program code:
Rust
Use Anchor_lang :: Prelude :: *;
#[program]
Pub mod my_program {
Use great :: {myaccount, mystage};
#[account]
Pub struct myaccount {
Pub storage_var1: U8,
Pub storage_var2: i32,
}
[Param]
FN CREATE_ACCOUNT PUB (
_ONNE: CONPECTID,
_Data: [U8; 32],
) ->
Leave my_account = myaccount {
Storage_var1: 42,
Storage_var2: 123,
};
Self :: set_initial_value (my_account).
OK (my_account)
}
#[action]
FN Write_to_Storage Pub (
Mut self: Account <'_>,
_Data: [U8; 32],
) ->
If! self.uwner.key == Current_program.Key {
Return err (Error :: InvalidProgramD);
}
// Save variable memory
ALL RIGHT (())
}
#[action]
Pub FN Read_from_storage (
Mut self: Account <'_>,
_Data: [U8; 32],
) ->
If! self.uwner.key == Current_program.Key {
Return err (Error :: InvalidProgramD);
}
// Read from variable memory
ALL RIGHT (())
}
#[program]
Pub Mod Main {
Use Super :: *;
Const storage_var1: U8 = 42;
Const storage_var2: i32 = 123;
Pub fn my_program () ->
Leave my_account = Myaccount :: Create ()?;
OK (my_account)
}
}
}
'
In this example, the functions "write_to_storage I` Read_from_storage ‘check if they have the consent of access to variable memory linked to the owner of the account. Otherwise, they refer an error.
لینک کوتاه
برچسب ها
- نظرات ارسال شده توسط شما، پس از تایید توسط مدیران سایت منتشر خواهد شد.
- نظراتی که حاوی تهمت یا افترا باشد منتشر نخواهد شد.
- نظراتی که به غیر از زبان فارسی یا غیر مرتبط با خبر باشد منتشر نخواهد شد.
ارسال نظر شما
مجموع نظرات : 0 در انتظار بررسی : 0 انتشار یافته : 0