@@ -17,7 +17,7 @@ pub const DESTINATION_TOKEN_ACCOUNT_INDEX: u8 = 2;
17
17
pub const AUTHORITY_ACCOUNT_INDEX : u8 = 3 ;
18
18
19
19
/// Number of extra accounts in the ExtraAccountMetaList account
20
- pub const EXTRA_ACCOUNTS_LEN : u8 = 1 ;
20
+ pub const EXTRA_ACCOUNTS_LEN : u8 = 2 ;
21
21
22
22
#[ program]
23
23
pub mod dummy_transfer_hook {
@@ -31,21 +31,30 @@ pub mod dummy_transfer_hook {
31
31
pub fn initialize_extra_account_meta_list (
32
32
ctx : Context < InitializeExtraAccountMetaList > ,
33
33
) -> Result < ( ) > {
34
- let account_metas = vec ! [ ExtraAccountMeta :: new_with_seeds(
35
- & [
36
- Seed :: Literal {
37
- bytes: "dummy_account" . as_bytes( ) . to_vec( ) ,
38
- } ,
39
- // owner field of the sender token account
40
- Seed :: AccountData {
41
- account_index: SENDER_TOKEN_ACCOUNT_INDEX ,
42
- data_index: 32 ,
43
- length: 32 ,
44
- } ,
45
- ] ,
46
- false , // is_signer
47
- false , // is_writable
48
- ) ?] ;
34
+ let account_metas = vec ! [
35
+ ExtraAccountMeta :: new_with_seeds(
36
+ & [
37
+ Seed :: Literal {
38
+ bytes: "dummy_account" . as_bytes( ) . to_vec( ) ,
39
+ } ,
40
+ // owner field of the sender token account
41
+ Seed :: AccountData {
42
+ account_index: SENDER_TOKEN_ACCOUNT_INDEX ,
43
+ data_index: 32 ,
44
+ length: 32 ,
45
+ } ,
46
+ ] ,
47
+ false , // is_signer
48
+ false , // is_writable
49
+ ) ?,
50
+ ExtraAccountMeta :: new_with_seeds(
51
+ & [ Seed :: Literal {
52
+ bytes: "counter" . as_bytes( ) . to_vec( ) ,
53
+ } ] ,
54
+ false , // is_signer
55
+ true , // is_writable
56
+ ) ?,
57
+ ] ;
49
58
50
59
assert_eq ! ( EXTRA_ACCOUNTS_LEN as usize , account_metas. len( ) ) ;
51
60
@@ -58,8 +67,8 @@ pub mod dummy_transfer_hook {
58
67
Ok ( ( ) )
59
68
}
60
69
61
- pub fn transfer_hook ( _ctx : Context < TransferHook > , _amount : u64 ) -> Result < ( ) > {
62
- // NOTE: for now, the account constraints implement all the restrictions.
70
+ pub fn transfer_hook ( ctx : Context < TransferHook > , _amount : u64 ) -> Result < ( ) > {
71
+ ctx . accounts . counter . count += 1 ;
63
72
Ok ( ( ) )
64
73
}
65
74
@@ -87,6 +96,12 @@ pub mod dummy_transfer_hook {
87
96
}
88
97
}
89
98
99
+ #[ account]
100
+ #[ derive( InitSpace ) ]
101
+ pub struct Counter {
102
+ pub count : u64 ,
103
+ }
104
+
90
105
#[ derive( Accounts ) ]
91
106
pub struct InitializeExtraAccountMetaList < ' info > {
92
107
#[ account( mut ) ]
@@ -104,6 +119,16 @@ pub struct InitializeExtraAccountMetaList<'info> {
104
119
pub mint : InterfaceAccount < ' info , Mint > ,
105
120
pub token_program : Interface < ' info , TokenInterface > ,
106
121
pub associated_token_program : Program < ' info , AssociatedToken > ,
122
+
123
+ #[ account(
124
+ init,
125
+ payer = payer,
126
+ space = 8 + Counter :: INIT_SPACE ,
127
+ seeds = [ b"counter" ] ,
128
+ bump
129
+ ) ]
130
+ pub counter : Account < ' info , Counter > ,
131
+
107
132
pub system_program : Program < ' info , System > ,
108
133
}
109
134
@@ -136,4 +161,11 @@ pub struct TransferHook<'info> {
136
161
/// CHECK: dummy account. It just tests that the off-chain code correctly
137
162
/// computes and the on-chain code correctly passes on the PDA.
138
163
pub dummy_account : AccountInfo < ' info > ,
164
+
165
+ #[ account(
166
+ mut ,
167
+ seeds = [ b"counter" ] ,
168
+ bump
169
+ ) ]
170
+ pub counter : Account < ' info , Counter > ,
139
171
}
0 commit comments