Browse Source

Update README example

armaniferrante 4 years ago
parent
commit
cddc4f6bb6
1 changed files with 7 additions and 6 deletions
  1. 7 6
      README.md

+ 7 - 6
README.md

@@ -35,17 +35,17 @@ use anchor::prelude::*;
 mod basic_1 {
 mod basic_1 {
     use super::*;
     use super::*;
 
 
-    #[access_control(not_zero(data))]
     pub fn initialize(ctx: Context<Initialize>, authority: Pubkey) -> ProgramResult {
     pub fn initialize(ctx: Context<Initialize>, authority: Pubkey) -> ProgramResult {
         let my_account = &mut ctx.accounts.my_account;
         let my_account = &mut ctx.accounts.my_account;
-        my_account.initialized = true;
         my_account.authority = authority;
         my_account.authority = authority;
         Ok(())
         Ok(())
     }
     }
 
 
+    #[access_control(not_zero(data))]
     pub fn update(ctx: Context<Update>, data: u64) -> ProgramResult {
     pub fn update(ctx: Context<Update>, data: u64) -> ProgramResult {
         let my_account = &mut ctx.accounts.my_account;
         let my_account = &mut ctx.accounts.my_account;
         my_account.data = data;
         my_account.data = data;
+        Ok(())
     }
     }
 }
 }
 
 
@@ -53,7 +53,7 @@ mod basic_1 {
 
 
 #[derive(Accounts)]
 #[derive(Accounts)]
 pub struct Initialize<'info> {
 pub struct Initialize<'info> {
-    #[account(mut, "!my_account.initialized")]
+    #[account(init)]
     pub my_account: ProgramAccount<'info, MyAccount>,
     pub my_account: ProgramAccount<'info, MyAccount>,
 }
 }
 
 
@@ -61,13 +61,15 @@ pub struct Initialize<'info> {
 pub struct Update<'info> {
 pub struct Update<'info> {
     #[account(signer)]
     #[account(signer)]
     pub authority: AccountInfo<'info>,
     pub authority: AccountInfo<'info>,
+    #[account(mut, "&my_account.authority == authority.key")]
+    pub my_account: ProgramAccount<'info, MyAccount>,
 }
 }
 
 
 // Define program owned accounts.
 // Define program owned accounts.
 
 
-#[derive(AnchorSerialize, AnchorDeserialize)]
+#[account]
 pub struct MyAccount {
 pub struct MyAccount {
-    pub initialized: bool,
+    pub authority: Pubkey,
     pub data: u64,
     pub data: u64,
 }
 }
 
 
@@ -81,7 +83,6 @@ fn not_zero(data: u64) -> ProgramResult {
 }
 }
 ```
 ```
 
 
-
 ## Accounts attribute syntax.
 ## Accounts attribute syntax.
 
 
 There are several inert attributes (attributes that are consumed only for the
 There are several inert attributes (attributes that are consumed only for the