File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
basics/favorites/anchor/programs/favorites/src Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,16 @@ pub mod favorites {
28
28
}
29
29
30
30
// We can also add a get_favorites instruction handler to return the user's favorite number and color
31
+ pub fn get_favorites ( context : Context < GetFavorites > ) -> Result < ( ) > {
32
+ let favorites = & context. accounts . favorites ;
33
+ msg ! ( "User {}'s favorites: number = {}, color = {}, hobbies = {:?}" ,
34
+ context. accounts. user. key( ) ,
35
+ favorites. number,
36
+ favorites. color,
37
+ favorites. hobbies
38
+ ) ;
39
+ Ok ( ( ) )
40
+ }
31
41
}
32
42
33
43
// What we will put inside the Favorites PDA
@@ -59,3 +69,15 @@ pub struct SetFavorites<'info> {
59
69
60
70
pub system_program : Program < ' info , System > ,
61
71
}
72
+
73
+ // When people call the get_favorites instruction, they will need to provide the account to read
74
+ #[ derive( Accounts ) ]
75
+ pub struct GetFavorites < ' info > {
76
+ pub user : Signer < ' info > ,
77
+
78
+ #[ account(
79
+ seeds = [ b"favorites" , user. key( ) . as_ref( ) ] ,
80
+ bump,
81
+ ) ]
82
+ pub favorites : Account < ' info , Favorites > ,
83
+ }
You can’t perform that action at this time.
0 commit comments