15: Check returned data before decoding

This commit is contained in:
2026-06-26 16:59:24 +02:00
parent 8f0f4061ee
commit 0c2f00f791
@@ -52,8 +52,17 @@ public class AnchorIdlJupiterPerpsPositionServiceImpl implements JupiterPerpsPos
Set<JupiterPerpsPosition> positions = new HashSet<>();
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(
accountInfo.address(),
address,
accountInfo
);
positions.add(position);
@@ -61,6 +70,7 @@ public class AnchorIdlJupiterPerpsPositionServiceImpl implements JupiterPerpsPos
return Set.copyOf(positions);
}
private static final ΩJupiterPerpsProgramIdΩ JUPITER_PERPS_PROGRAM_ID =
"PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu";
private static final int POSITION_OWNER_OFFSET = 8;