15: Check returned data before decoding
This commit is contained in:
+11
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user