Skip to content

Commit

Permalink
warn about incorrect origin definition in TokenScript
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesSmartCell committed Dec 10, 2023
1 parent 9dc6963 commit a44fc42
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static boolean isInfura(String rpcServerUrl)
put(POLYGON_TEST_ID, new NetworkInfo(C.POLYGON_TEST_NETWORK, C.POLYGON_SYMBOL,
MUMBAI_TEST_RPC_URL,
"https://mumbai.polygonscan.com/tx/", POLYGON_TEST_ID,
MUMBAI_FALLBACK_RPC_URL, " https://api-testnet.polygonscan.com/api?"));
MUMBAI_FALLBACK_RPC_URL, "https://api-testnet.polygonscan.com/api?"));
put(OPTIMISTIC_MAIN_ID, new NetworkInfo(C.OPTIMISTIC_NETWORK, C.ETH_SYMBOL,
OPTIMISTIC_MAIN_URL,
"https://optimistic.etherscan.io/tx/", OPTIMISTIC_MAIN_ID, OPTIMISTIC_MAIN_FALLBACK_URL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3130,6 +3130,11 @@ public Single<List<TokenLocator>> getAllTokenDefinitions(boolean refresh)
//Import script from scriptURI
public Single<TokenDefinition> checkServerForScript(Token token, MutableLiveData<Boolean> updateFlag)
{
if (token == null)
{
return Single.fromCallable(TokenDefinition::new);
}

TokenScriptFile tf = getTokenScriptFile(token);

if ((tf != null && tf.exists()) && !isInSecureZone(tf))
Expand Down
17 changes: 15 additions & 2 deletions lib/src/main/java/com/alphawallet/token/tools/TokenDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ public TokenDefinition(InputStream xmlAsset, Locale locale, ParseResult result)
parseTags(xml);
extractSignedInfo(xml);
//scanAttestation(xml);
checkOrigin();
}
catch (IOException|SAXException e)
{
Expand All @@ -523,6 +524,15 @@ public TokenDefinition(InputStream xmlAsset, Locale locale, ParseResult result)
}
}

private void checkOrigin() throws SAXException
{
ContractInfo thisScript = contracts.get(holdingToken);
if (thisScript == null)
{
throw new SAXException("PARSE ERROR: Origins Token '" + holdingToken + "' not defined.");
}
}

private void extractTags(Element token) throws Exception
{
//trawl through the child nodes, interpret each in turn
Expand All @@ -534,8 +544,11 @@ private void extractTags(Element token) throws Exception
switch (element.getLocalName())
{
case "origins":
TSOrigins origin = parseOrigins(element); //parseOrigins(element);
if (origin.isType(TSOriginType.Contract) || origin.isType(TSOriginType.Attestation)) holdingToken = origin.getOriginName();
TSOrigins origin = parseOrigins(element);
if (origin.isType(TSOriginType.Contract) || origin.isType(TSOriginType.Attestation))
{
holdingToken = origin.getOriginName();
}
break;
case "contract":
handleAddresses(element);
Expand Down

0 comments on commit a44fc42

Please sign in to comment.