15: Check returned data before decoding

This commit is contained in:
2026-06-26 16:59:24 +02:00
parent 8f0f4061ee
commit 0c2f00f791
@@ -52,15 +52,25 @@ public class AnchorIdlJupiterPerpsPositionServiceImpl implements JupiterPerpsPos
Set<JupiterPerpsPosition> positions = new HashSet<>(); Set<JupiterPerpsPosition> positions = new HashSet<>();
for (SolanaAccountInfo accountInfo : accountInfos) { for (SolanaAccountInfo accountInfo : accountInfos) {
ΩSolanaAddressΩ address = accountInfo.address();
ΩSolanaProgramIdΩ programId = accountInfo.owner();
if (!JUPITER_PERPS_PROGRAM_ID.equals(programId)) {
String errorMsg = "Account '" + address + "' is not owned by Jupiter Perps program '" +
programId + "'";
throw new IllegalArgumentException(errorMsg);
}
JupiterPerpsPosition position = positionDecoder.decode( JupiterPerpsPosition position = positionDecoder.decode(
accountInfo.address(), address,
accountInfo accountInfo
); );
positions.add(position); positions.add(position);
} }
return Set.copyOf(positions); return Set.copyOf(positions);
} }
private static final ΩJupiterPerpsProgramIdΩ JUPITER_PERPS_PROGRAM_ID = private static final ΩJupiterPerpsProgramIdΩ JUPITER_PERPS_PROGRAM_ID =
"PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu"; "PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu";
private static final int POSITION_OWNER_OFFSET = 8; private static final int POSITION_OWNER_OFFSET = 8;