Skip to content

Commit 3142052

Browse files
committed
bubble up exact instruction error
1 parent 53885f1 commit 3142052

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

auction-server/src/api.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ pub enum InstructionError {
131131
MissingCreateAtaInstruction(Pubkey),
132132
InvalidMemoInstructionCount { expected: usize, found: usize },
133133
InvalidMemoString { expected: String, found: String },
134-
UnsupportedInvocationOfUserWallet,
135134
UnapprovedProgramId(Pubkey),
136135
}
137136

@@ -276,12 +275,6 @@ impl std::fmt::Display for InstructionError {
276275
expected, found
277276
)
278277
}
279-
InstructionError::UnsupportedInvocationOfUserWallet => {
280-
write!(
281-
f,
282-
"Invocation of user wallet is not supported in this instruction"
283-
)
284-
}
285278
InstructionError::UnapprovedProgramId(program_id) => {
286279
write!(f, "Instruction has unapproved program id: {:?}", program_id)
287280
}

auction-server/src/auction/service/verification.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -277,24 +277,19 @@ impl Service {
277277
user_wallet: &Pubkey,
278278
ix_index: usize,
279279
) -> Result<(), RestError> {
280-
if self
281-
.check_approved_program_instruction(program_id, ix)
282-
.is_ok()
283-
{
284-
Ok(())
285-
} else {
286-
// TODO: this loop will be slow and invoke many rpc calls if there are many lookup accounts. either parallelize this extraction or limit number of lookup accounts
287-
for i in 0..ix.accounts.len() {
288-
let account_key = self.extract_account(tx, ix, i).await?;
289-
if account_key == *user_wallet {
290-
return Err(RestError::InvalidInstruction(
291-
Some(ix_index),
292-
InstructionError::UnsupportedInvocationOfUserWallet,
293-
));
280+
match self.check_approved_program_instruction(program_id, ix) {
281+
Ok(()) => Ok(()),
282+
Err(e) => {
283+
// TODO: this loop will be slow and invoke many rpc calls if there are many lookup accounts. either parallelize this extraction or limit number of lookup accounts
284+
for i in 0..ix.accounts.len() {
285+
let account_key = self.extract_account(tx, ix, i).await?;
286+
if account_key == *user_wallet {
287+
return Err(RestError::InvalidInstruction(Some(ix_index), e));
288+
}
294289
}
295-
}
296290

297-
Ok(())
291+
Ok(())
292+
}
298293
}
299294
}
300295

@@ -2760,6 +2755,7 @@ mod tests {
27602755
),
27612756
];
27622757
for instruction in instructions.into_iter() {
2758+
let program_id = instruction.program_id;
27632759
let result = get_verify_bid_result(
27642760
service.clone(),
27652761
searcher.insecure_clone(),
@@ -2771,7 +2767,7 @@ mod tests {
27712767
result.unwrap_err(),
27722768
RestError::InvalidInstruction(
27732769
Some(0),
2774-
InstructionError::UnsupportedInvocationOfUserWallet
2770+
InstructionError::UnapprovedProgramId(program_id)
27752771
)
27762772
);
27772773
}

0 commit comments

Comments
 (0)