42: Fail on multiple SPL token accounts for the same mint

This commit is contained in:
2026-08-05 10:12:39 +02:00
parent bbba18dcae
commit d4e6d3438b
2 changed files with 14 additions and 2 deletions
@@ -55,6 +55,7 @@ public interface SolanaBlockChain {
* @return a map of SPL mint addresses to token holding information
* @throws IOException if the token holdings could not be fetched or parsed
* @throws InterruptedException if the calling thread is interrupted while fetching token holdings
* @throws IllegalStateException if multiple token accounts for the same mint is detected, as this is not supported yet.
*/
Map<ΩSPLMintAddressΩ, SPLTokenHolding> getSPLTokenHoldings(
ΩSolanaAddressΩ ownerAddress,
@@ -149,14 +149,25 @@ public class SolanaBlockChainImpl implements SolanaBlockChain {
String uiAmountString = tokenAmount.path("uiAmountString").asText();
BigDecimal uiAmount = new BigDecimal(uiAmountString);
result.put(mint, new SPLTokenHolding(
SPLTokenHolding holding = new SPLTokenHolding(
tokenAccount,
mint,
uiAmount,
rawAmount,
decimals,
splProgram.getAddress()
));
);
SPLTokenHolding previous = result.putIfAbsent(mint, holding);
if (previous != null) {
throw new IllegalStateException(
"Multiple SPL token accounts found for mint "
+ mint
+ " and owner "
+ ownerAddress
);
}
}
return result;