MCPcopy Create free account
hub / github.com/Bonfida/dex-v4 / parse

Method parse

program/src/processor/new_order.rs:132–186  ·  view source on GitHub ↗
(
        program_id: &Pubkey,
        accounts: &'a [AccountInfo<'b>],
        has_discount_token_account: bool,
    )

Source from the content-addressed store, hash-verified

130
131impl<'a, 'b: 'a> Accounts<'a, AccountInfo<'b>> {
132 pub fn parse(
133 program_id: &Pubkey,
134 accounts: &'a [AccountInfo<'b>],
135 has_discount_token_account: bool,
136 ) -> Result<Self, ProgramError> {
137 let accounts_iter = &mut accounts.iter();
138 let a = Self {
139 spl_token_program: next_account_info(accounts_iter)?,
140 system_program: next_account_info(accounts_iter)?,
141 market: next_account_info(accounts_iter)?,
142 orderbook: next_account_info(accounts_iter)?,
143 event_queue: next_account_info(accounts_iter)?,
144 bids: next_account_info(accounts_iter)?,
145 asks: next_account_info(accounts_iter)?,
146 base_vault: next_account_info(accounts_iter)?,
147 quote_vault: next_account_info(accounts_iter)?,
148 user: next_account_info(accounts_iter)?,
149 user_token_account: next_account_info(accounts_iter)?,
150 user_owner: next_account_info(accounts_iter)?,
151 discount_token_account: if has_discount_token_account {
152 next_account_info(accounts_iter).ok()
153 } else {
154 None
155 },
156 fee_referral_account: next_account_info(accounts_iter).ok(),
157 };
158
159 check_signer(a.user_owner).map_err(|e| {
160 msg!("The user account owner should be a signer for this transaction!");
161 e
162 })?;
163
164 check_account_key(
165 a.spl_token_program,
166 &spl_token::ID,
167 DexError::InvalidSplTokenProgram,
168 )?;
169 check_account_key(
170 a.system_program,
171 &system_program::ID,
172 DexError::InvalidSystemProgramAccount,
173 )?;
174
175 if let Some(discount_account) = a.discount_token_account {
176 check_account_owner(
177 discount_account,
178 &spl_token::ID,
179 DexError::InvalidSplTokenProgram,
180 )?
181 }
182 check_account_owner(a.user, program_id, DexError::InvalidStateAccountOwner)?;
183 check_account_owner(a.market, program_id, DexError::InvalidStateAccountOwner)?;
184
185 Ok(a)
186 }
187
188 pub fn load_user_account(
189 &self,

Callers

nothing calls this directly

Calls 3

check_signerFunction · 0.85
check_account_keyFunction · 0.85
check_account_ownerFunction · 0.85

Tested by

no test coverage detected