42: Fail on multiple SPL token accounts for the same mint
This commit is contained in:
@@ -55,6 +55,7 @@ public interface SolanaBlockChain {
|
|||||||
* @return a map of SPL mint addresses to token holding information
|
* @return a map of SPL mint addresses to token holding information
|
||||||
* @throws IOException if the token holdings could not be fetched or parsed
|
* @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 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(
|
Map<ΩSPLMintAddressΩ, SPLTokenHolding> getSPLTokenHoldings(
|
||||||
ΩSolanaAddressΩ ownerAddress,
|
ΩSolanaAddressΩ ownerAddress,
|
||||||
|
|||||||
@@ -149,14 +149,25 @@ public class SolanaBlockChainImpl implements SolanaBlockChain {
|
|||||||
String uiAmountString = tokenAmount.path("uiAmountString").asText();
|
String uiAmountString = tokenAmount.path("uiAmountString").asText();
|
||||||
BigDecimal uiAmount = new BigDecimal(uiAmountString);
|
BigDecimal uiAmount = new BigDecimal(uiAmountString);
|
||||||
|
|
||||||
result.put(mint, new SPLTokenHolding(
|
SPLTokenHolding holding = new SPLTokenHolding(
|
||||||
tokenAccount,
|
tokenAccount,
|
||||||
mint,
|
mint,
|
||||||
uiAmount,
|
uiAmount,
|
||||||
rawAmount,
|
rawAmount,
|
||||||
decimals,
|
decimals,
|
||||||
splProgram.getAddress()
|
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;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user