Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Gracefully handle missing token contract functions that are optional #71

Open
mmhh1910 opened this issue Mar 7, 2018 · 2 comments
Open
Labels
bug Something isn't working

Comments

@mmhh1910
Copy link
Contributor

mmhh1910 commented Mar 7, 2018

Backend assumes that fuctions like decimals are always implemented in token contracts. This is not the case and some functions are optional per: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md

We should handle all contract calls for these optional functions gracefully.

Example calls stack on exception:

  File "/usr/local/lib/python3.6/site-packages/engineio/asyncio_server.py", line 266, in _trigger_event
    ret = await self.handlers[event](*args)
  File "/usr/local/lib/python3.6/site-packages/socketio/asyncio_server.py", line 364, in _handle_eio_message
    await self._handle_event(sid, pkt.namespace, pkt.id, pkt.data)
  File "/usr/local/lib/python3.6/site-packages/socketio/asyncio_server.py", line 294, in _handle_event
    await self._handle_event_internal(self, sid, data, namespace, id)
  File "/usr/local/lib/python3.6/site-packages/socketio/asyncio_server.py", line 297, in _handle_event_internal
    r = await server._trigger_event(data[0], namespace, sid, *data[1:])
  File "/usr/local/lib/python3.6/site-packages/socketio/asyncio_server.py", line 325, in _trigger_event
    ret = await self.handlers[namespace][event](*args)
  File "/usr/src/app/app/services/websocket_server.py", line 372, in get_market
    "sells": [format_order(order) for order in orders_sells]
  File "/usr/src/app/app/services/websocket_server.py", line 372, in <listcomp>
    "sells": [format_order(order) for order in orders_sells]
  File "/usr/src/app/app/services/websocket_server.py", line 277, in format_order
    price = base_contract.denormalize_value(record["amount_get"]) / coin_contract.denormalize_value(record["amount_give"])
  File "/usr/src/app/app/src/erc20_token.py", line 31, in denormalize_value
    return value * Decimal(10.0 ** -self.decimals)
  File "/usr/src/app/app/src/erc20_token.py", line 42, in decimals
    cache[self.addr] = self._call_decimals()
  File "/usr/src/app/app/src/erc20_token.py", line 53, in _call_decimals
    raise ValueError(error_msg)
ValueError: Contract 0xb15fe5a123e647ba594cea7a1e648646f95eb4aa does not support method`decimals()', returned '0x'
@mmhh1910 mmhh1910 changed the title Gracefully handle missing token contract function that are optional Gracefully handle missing token contract functions that are optional Mar 7, 2018
@freeatnet
Copy link
Contributor

Took the liberty of formatting the code block :)

@freeatnet freeatnet added the bug Something isn't working label Mar 7, 2018
@mmhh1910
Copy link
Contributor Author

mmhh1910 commented Mar 9, 2018

freeatnet:

I think we should support DECIMALS and potentially support an alternate method of getting decimals (etherscan?), but yes, in the updates thread, we should catch, log, and discard exceptions on a per-record basis

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants