|
1 | | -use base64::{engine::general_purpose::STANDARD as Base64Engine, Engine}; |
| 1 | +use base64::{Engine, engine::general_purpose::STANDARD as Base64Engine}; |
2 | 2 | use serde::{Deserialize, Serialize}; |
3 | | -use serde_with::{serde_as, DisplayFromStr}; |
| 3 | +use serde_with::{DisplayFromStr, serde_as}; |
4 | 4 | use solana_compute_budget_interface::ComputeBudgetInstruction; |
5 | 5 | use solana_sdk::{ |
6 | 6 | instruction::Instruction, |
7 | | - message::{v0, AccountMeta, VersionedMessage}, |
| 7 | + message::{AccountMeta, VersionedMessage, v0}, |
8 | 8 | pubkey::Pubkey, |
9 | 9 | transaction::VersionedTransaction, |
10 | 10 | }; |
@@ -92,11 +92,16 @@ impl SolanaInstructionData { |
92 | 92 | pub fn get_data_bytes(&self) -> Result<Vec<u8>, SolanaTransactionError> { |
93 | 93 | match self.encoding { |
94 | 94 | // try to decode both prefixed and non-prefixed hex |
95 | | - InstructionDataEncoding::Hex => Ok(hex::decode(&self.data) |
96 | | - .or_else(|_| hex::decode(&self.data[2..])) |
97 | | - .map_err(|e| SolanaTransactionError::InvalidData { |
| 95 | + InstructionDataEncoding::Hex => { |
| 96 | + let s = self |
| 97 | + .data |
| 98 | + .strip_prefix("0x") |
| 99 | + .or_else(|| self.data.strip_prefix("0X")) |
| 100 | + .unwrap_or(self.data.as_str()); |
| 101 | + hex::decode(s).map_err(|e| SolanaTransactionError::InvalidData { |
98 | 102 | error: e.to_string(), |
99 | | - })?), |
| 103 | + }) |
| 104 | + } |
100 | 105 | InstructionDataEncoding::Base64 => { |
101 | 106 | Ok(Base64Engine.decode(&self.data).map_err(|e| { |
102 | 107 | SolanaTransactionError::InvalidData { |
|
0 commit comments