@@ -52,12 +52,18 @@ impl Processor {
52
52
Ok ( ( ) )
53
53
}
54
54
55
- /// Processes an [InitializeAccount](enum.TokenInstruction.html) instruction.
56
- pub fn process_initialize_account ( accounts : & [ AccountInfo ] ) -> ProgramResult {
55
+ fn _process_initialize_account (
56
+ accounts : & [ AccountInfo ] ,
57
+ owner : Option < & Pubkey > ,
58
+ ) -> ProgramResult {
57
59
let account_info_iter = & mut accounts. iter ( ) ;
58
60
let new_account_info = next_account_info ( account_info_iter) ?;
59
61
let mint_info = next_account_info ( account_info_iter) ?;
60
- let owner_info = next_account_info ( account_info_iter) ?;
62
+ let owner = if let Some ( owner) = owner {
63
+ owner
64
+ } else {
65
+ next_account_info ( account_info_iter) ?. key
66
+ } ;
61
67
let new_account_info_data_len = new_account_info. data_len ( ) ;
62
68
let rent = & Rent :: from_account_info ( next_account_info ( account_info_iter) ?) ?;
63
69
@@ -76,7 +82,7 @@ impl Processor {
76
82
}
77
83
78
84
account. mint = * mint_info. key ;
79
- account. owner = * owner_info . key ;
85
+ account. owner = * owner ;
80
86
account. delegate = COption :: None ;
81
87
account. delegated_amount = 0 ;
82
88
account. state = AccountState :: Initialized ;
@@ -97,6 +103,16 @@ impl Processor {
97
103
Ok ( ( ) )
98
104
}
99
105
106
+ /// Processes an [InitializeAccount](enum.TokenInstruction.html) instruction.
107
+ pub fn process_initialize_account ( accounts : & [ AccountInfo ] ) -> ProgramResult {
108
+ Self :: _process_initialize_account ( accounts, None )
109
+ }
110
+
111
+ /// Processes an [InitializeAccount2](enum.TokenInstruction.html) instruction.
112
+ pub fn process_initialize_account2 ( accounts : & [ AccountInfo ] , owner : Pubkey ) -> ProgramResult {
113
+ Self :: _process_initialize_account ( accounts, Some ( & owner) )
114
+ }
115
+
100
116
/// Processes a [InitializeMultisig](enum.TokenInstruction.html) instruction.
101
117
pub fn process_initialize_multisig ( accounts : & [ AccountInfo ] , m : u8 ) -> ProgramResult {
102
118
let account_info_iter = & mut accounts. iter ( ) ;
@@ -641,6 +657,10 @@ impl Processor {
641
657
msg ! ( "Instruction: InitializeAccount" ) ;
642
658
Self :: process_initialize_account ( accounts)
643
659
}
660
+ TokenInstruction :: InitializeAccount2 { owner } => {
661
+ msg ! ( "Instruction: InitializeAccount2" ) ;
662
+ Self :: process_initialize_account2 ( accounts, owner)
663
+ }
644
664
TokenInstruction :: InitializeMultisig { m } => {
645
665
msg ! ( "Instruction: InitializeMultisig" ) ;
646
666
Self :: process_initialize_multisig ( accounts, m)
@@ -5660,4 +5680,52 @@ mod tests {
5660
5680
let account = Account :: unpack_unchecked ( & account_account. data ) . unwrap ( ) ;
5661
5681
assert_eq ! ( account. state, AccountState :: Initialized ) ;
5662
5682
}
5683
+
5684
+ #[ test]
5685
+ fn test_initialize_account2 ( ) {
5686
+ let program_id = Pubkey :: new_unique ( ) ;
5687
+ let account_key = Pubkey :: new_unique ( ) ;
5688
+ let mut account_account = SolanaAccount :: new (
5689
+ account_minimum_balance ( ) ,
5690
+ Account :: get_packed_len ( ) ,
5691
+ & program_id,
5692
+ ) ;
5693
+ let mut account2_account = SolanaAccount :: new (
5694
+ account_minimum_balance ( ) ,
5695
+ Account :: get_packed_len ( ) ,
5696
+ & program_id,
5697
+ ) ;
5698
+ let owner_key = Pubkey :: new_unique ( ) ;
5699
+ let mut owner_account = SolanaAccount :: default ( ) ;
5700
+ let mint_key = Pubkey :: new_unique ( ) ;
5701
+ let mut mint_account =
5702
+ SolanaAccount :: new ( mint_minimum_balance ( ) , Mint :: get_packed_len ( ) , & program_id) ;
5703
+ let mut rent_sysvar = rent_sysvar ( ) ;
5704
+
5705
+ // create mint
5706
+ do_process_instruction (
5707
+ initialize_mint ( & program_id, & mint_key, & owner_key, None , 2 ) . unwrap ( ) ,
5708
+ vec ! [ & mut mint_account, & mut rent_sysvar] ,
5709
+ )
5710
+ . unwrap ( ) ;
5711
+
5712
+ do_process_instruction (
5713
+ initialize_account ( & program_id, & account_key, & mint_key, & owner_key) . unwrap ( ) ,
5714
+ vec ! [
5715
+ & mut account_account,
5716
+ & mut mint_account,
5717
+ & mut owner_account,
5718
+ & mut rent_sysvar,
5719
+ ] ,
5720
+ )
5721
+ . unwrap ( ) ;
5722
+
5723
+ do_process_instruction (
5724
+ initialize_account2 ( & program_id, & account_key, & mint_key, & owner_key) . unwrap ( ) ,
5725
+ vec ! [ & mut account2_account, & mut mint_account, & mut rent_sysvar] ,
5726
+ )
5727
+ . unwrap ( ) ;
5728
+
5729
+ assert_eq ! ( account_account, account2_account) ;
5730
+ }
5663
5731
}
0 commit comments