3
3
parse_address_lookup_table:: parse_address_lookup_table,
4
4
parse_bpf_loader:: parse_bpf_upgradeable_loader, parse_config:: parse_config,
5
5
parse_nonce:: parse_nonce, parse_stake:: parse_stake, parse_sysvar:: parse_sysvar,
6
- parse_token:: parse_token , parse_vote:: parse_vote,
6
+ parse_token:: parse_token_v2 , parse_vote:: parse_vote,
7
7
} ,
8
8
inflector:: Inflector ,
9
9
serde_json:: Value ,
10
10
solana_sdk:: {
11
- address_lookup_table, instruction:: InstructionError , pubkey:: Pubkey , stake , system_program ,
12
- sysvar, vote,
11
+ address_lookup_table, clock :: UnixTimestamp , instruction:: InstructionError , pubkey:: Pubkey ,
12
+ stake , system_program , sysvar, vote,
13
13
} ,
14
+ spl_token_2022:: extension:: interest_bearing_mint:: InterestBearingConfig ,
14
15
std:: collections:: HashMap ,
15
16
thiserror:: Error ,
16
17
} ;
@@ -84,16 +85,57 @@ pub enum ParsableAccount {
84
85
Vote ,
85
86
}
86
87
88
+ #[ deprecated( since = "2.0.0" , note = "Use `AccountAdditionalDataV2` instead" ) ]
87
89
#[ derive( Clone , Copy , Default ) ]
88
90
pub struct AccountAdditionalData {
89
91
pub spl_token_decimals : Option < u8 > ,
90
92
}
91
93
94
+ #[ derive( Clone , Copy , Default ) ]
95
+ pub struct AccountAdditionalDataV2 {
96
+ pub spl_token_additional_data : Option < SplTokenAdditionalData > ,
97
+ }
98
+
99
+ #[ derive( Clone , Copy , Default ) ]
100
+ pub struct SplTokenAdditionalData {
101
+ pub decimals : u8 ,
102
+ pub interest_bearing_config : Option < ( InterestBearingConfig , UnixTimestamp ) > ,
103
+ }
104
+
105
+ impl SplTokenAdditionalData {
106
+ pub fn with_decimals ( decimals : u8 ) -> Self {
107
+ Self {
108
+ decimals,
109
+ ..Default :: default ( )
110
+ }
111
+ }
112
+ }
113
+
114
+ #[ deprecated( since = "2.0.0" , note = "Use `parse_account_data_v2` instead" ) ]
115
+ #[ allow( deprecated) ]
92
116
pub fn parse_account_data (
93
117
pubkey : & Pubkey ,
94
118
program_id : & Pubkey ,
95
119
data : & [ u8 ] ,
96
120
additional_data : Option < AccountAdditionalData > ,
121
+ ) -> Result < ParsedAccount , ParseAccountError > {
122
+ parse_account_data_v2 (
123
+ pubkey,
124
+ program_id,
125
+ data,
126
+ additional_data. map ( |d| AccountAdditionalDataV2 {
127
+ spl_token_additional_data : d
128
+ . spl_token_decimals
129
+ . map ( SplTokenAdditionalData :: with_decimals) ,
130
+ } ) ,
131
+ )
132
+ }
133
+
134
+ pub fn parse_account_data_v2 (
135
+ pubkey : & Pubkey ,
136
+ program_id : & Pubkey ,
137
+ data : & [ u8 ] ,
138
+ additional_data : Option < AccountAdditionalDataV2 > ,
97
139
) -> Result < ParsedAccount , ParseAccountError > {
98
140
let program_name = PARSABLE_PROGRAM_IDS
99
141
. get ( program_id)
@@ -108,9 +150,9 @@ pub fn parse_account_data(
108
150
}
109
151
ParsableAccount :: Config => serde_json:: to_value ( parse_config ( data, pubkey) ?) ?,
110
152
ParsableAccount :: Nonce => serde_json:: to_value ( parse_nonce ( data) ?) ?,
111
- ParsableAccount :: SplToken | ParsableAccount :: SplToken2022 => {
112
- serde_json :: to_value ( parse_token ( data, additional_data. spl_token_decimals ) ? ) ?
113
- }
153
+ ParsableAccount :: SplToken | ParsableAccount :: SplToken2022 => serde_json :: to_value (
154
+ parse_token_v2 ( data, additional_data. spl_token_additional_data . as_ref ( ) ) ? ,
155
+ ) ? ,
114
156
ParsableAccount :: Stake => serde_json:: to_value ( parse_stake ( data) ?) ?,
115
157
ParsableAccount :: Sysvar => serde_json:: to_value ( parse_sysvar ( data, pubkey) ?) ?,
116
158
ParsableAccount :: Vote => serde_json:: to_value ( parse_vote ( data) ?) ?,
@@ -143,13 +185,13 @@ mod test {
143
185
let account_pubkey = solana_sdk:: pubkey:: new_rand ( ) ;
144
186
let other_program = solana_sdk:: pubkey:: new_rand ( ) ;
145
187
let data = vec ! [ 0 ; 4 ] ;
146
- assert ! ( parse_account_data ( & account_pubkey, & other_program, & data, None ) . is_err( ) ) ;
188
+ assert ! ( parse_account_data_v2 ( & account_pubkey, & other_program, & data, None ) . is_err( ) ) ;
147
189
148
190
let vote_state = VoteState :: default ( ) ;
149
191
let mut vote_account_data: Vec < u8 > = vec ! [ 0 ; VoteState :: size_of( ) ] ;
150
192
let versioned = VoteStateVersions :: new_current ( vote_state) ;
151
193
VoteState :: serialize ( & versioned, & mut vote_account_data) . unwrap ( ) ;
152
- let parsed = parse_account_data (
194
+ let parsed = parse_account_data_v2 (
153
195
& account_pubkey,
154
196
& vote_program_id ( ) ,
155
197
& vote_account_data,
@@ -161,7 +203,7 @@ mod test {
161
203
162
204
let nonce_data = Versions :: new ( State :: Initialized ( Data :: default ( ) ) ) ;
163
205
let nonce_account_data = bincode:: serialize ( & nonce_data) . unwrap ( ) ;
164
- let parsed = parse_account_data (
206
+ let parsed = parse_account_data_v2 (
165
207
& account_pubkey,
166
208
& system_program:: id ( ) ,
167
209
& nonce_account_data,
0 commit comments