-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from graphsense/feature/tron
Merge Tron Changes to develop
- Loading branch information
Showing
19 changed files
with
420 additions
and
97 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
from openapi_server.models.token_config import TokenConfig | ||
from openapi_server.models.token_configs import TokenConfigs | ||
|
||
from gsrest.util import is_eth_like | ||
|
||
async def list_supported_tokens(request, currency): | ||
db = request.app['db'] | ||
if currency == "eth": | ||
if is_eth_like(currency): | ||
return TokenConfigs([ | ||
TokenConfig(ticker=k.lower(), | ||
decimals=v["decimals"], | ||
peg_currency=v["peg_currency"].lower()) | ||
for k, v in db.get_token_configuration("eth").items() | ||
for k, v in db.get_token_configuration(currency).items() | ||
]) | ||
else: | ||
return TokenConfigs([]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from gsrest.util.tron import tron_address_to_evm_string, evm_to_tron_address_string, partial_tron_to_partial_evm | ||
from gsrest.util.bch import try_bch_address_to_legacy | ||
from gsrest.util.evm import eth_address_to_hex, is_hex_string | ||
|
||
|
||
def cannonicalize_address(currency, address, partial=False) -> str: | ||
try: | ||
if currency == "trx": | ||
if partial: | ||
return partial_tron_to_partial_evm(address) | ||
else: | ||
return tron_address_to_evm_string(address, validate=False) | ||
elif currency == "bch": | ||
return try_bch_address_to_legacy(address) | ||
elif isinstance(address, str): | ||
return address | ||
else: | ||
raise Exception( | ||
f"Don't know how to encode address, {address} {currency}") | ||
except ValueError: | ||
return address | ||
|
||
|
||
def address_to_user_format(currency, db_address) -> str: | ||
if currency == "eth": | ||
if isinstance(db_address, bytes): | ||
return eth_address_to_hex(db_address) | ||
else: | ||
return db_address | ||
elif currency == "trx": | ||
if isinstance(db_address, bytes): | ||
return evm_to_tron_address_string(eth_address_to_hex(db_address)) | ||
else: | ||
if is_hex_string(db_address): | ||
return evm_to_tron_address_string(db_address) | ||
else: | ||
return db_address | ||
elif isinstance(db_address, str): | ||
return db_address | ||
else: | ||
raise Exception( | ||
f"Don't know how to decode db address, {db_address} {currency}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from cashaddress.convert import Address, to_legacy_address, InvalidAddress | ||
|
||
# Patch P2SH32 legacy address support | ||
# https://bch.info/en/upgrade | ||
if ("P2SH32", 5, False) not in Address.VERSION_MAP["legacy"]: | ||
Address.VERSION_MAP["legacy"].append(("P2SH32", 5, False)) | ||
if ("P2SH32", 11, False) not in Address.VERSION_MAP["cash"]: | ||
Address.VERSION_MAP["cash"].append(("P2SH32", 11, False)) | ||
|
||
|
||
def bch_address_to_legacy(address): | ||
return to_legacy_address(address) | ||
|
||
|
||
def try_bch_address_to_legacy(address): | ||
try: | ||
return bch_address_to_legacy(address) | ||
except InvalidAddress: | ||
return address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import Optional | ||
|
||
from gsrest.util.string_edit import remove_prefix | ||
|
||
|
||
def eth_address_to_hex(address): | ||
if not isinstance(address, bytes): | ||
return address | ||
return '0x' + bytes_to_hex(address) | ||
|
||
|
||
def is_hex_string(string: Optional[str]) -> bool: | ||
return string is not None and string.startswith("0x") and len(string) >= 2 | ||
|
||
|
||
def bytes_to_hex(b: bytes) -> Optional[str]: | ||
r = bytes(b).hex() | ||
return r if len(r) > 0 else None | ||
|
||
|
||
def hex_str_to_bytes(hex_str: str) -> bytes: | ||
return bytes.fromhex(hex_str) | ||
|
||
|
||
def strip_0x(string: Optional[str]) -> Optional[str]: | ||
return remove_prefix(string, "0x") if is_hex_string(string) else string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.