Skip to content

Commit

Permalink
Merge pull request #6 from bnb-chain/feat-pancake-address
Browse files Browse the repository at this point in the history
feat:add pancake address
  • Loading branch information
constwz authored Nov 2, 2023
2 parents a3fb218 + 9bd71c0 commit 9029018
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,6 @@
"api_key": {"type": "apiKey", "in": "header", "name": "Authorization"}
},
}

EXTERNAL_ADDRESS_LIST = env("EXTERNAL_ADDRESS_LIST", default="").split(",")
TOKEN_LIST = env("TOKEN_LIST", default="").split(",")
9 changes: 8 additions & 1 deletion safe_transaction_service/history/services/balance_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ def get_balances(
for one hour
"""

if safe_address in settings.EXTERNAL_ADDRESS_LIST:
balances = self._get_balances(safe_address, only_trusted, exclude_spam)
return balances

# Cache based on the number of erc20 events and the ether transferred, and also check outgoing ether
# transactions that will not emit events on non L2 networks
events_sending_eth = (
Expand Down Expand Up @@ -210,6 +214,9 @@ def _get_balances(
erc20_addresses = self._filter_addresses(
all_erc20_addresses, only_trusted, exclude_spam
)
for tokenAddress in settings.TOKEN_LIST:
if tokenAddress not in erc20_addresses:
erc20_addresses.append(tokenAddress)

try:
raw_balances = []
Expand All @@ -220,7 +227,7 @@ def _get_balances(
balances = self.ethereum_client.erc20.get_balances(
safe_address, erc20_addresses_chunk
)

logger.debug(balances)
# Skip ether transfer if already there
raw_balances.extend(balances[1:] if raw_balances else balances)

Expand Down
6 changes: 5 additions & 1 deletion safe_transaction_service/history/services/safe_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from dataclasses import dataclass, replace
from datetime import datetime
from typing import Optional, Tuple, Union
from django.conf import settings

from eth_typing import ChecksumAddress
from web3 import Web3
Expand Down Expand Up @@ -165,6 +166,9 @@ def get_safe_info_from_blockchain(self, safe_address: ChecksumAddress) -> SafeIn
safe = Safe(safe_address, self.ethereum_client)
safe_info = safe.retrieve_all_info()
# Return same master copy information than the db method
if safe_address in settings.EXTERNAL_ADDRESS_LIST:
return safe_info

return replace(
safe_info,
version=SafeMasterCopy.objects.get_version_for_address(
Expand All @@ -175,7 +179,7 @@ def get_safe_info_from_blockchain(self, safe_address: ChecksumAddress) -> SafeIn
raise NodeConnectionException from exc
except CannotRetrieveSafeInfoException as exc:
raise CannotGetSafeInfoFromBlockchain(safe_address) from exc

def get_safe_info_from_db(self, safe_address: ChecksumAddress) -> SafeInfo:
try:
return SafeLastStatus.objects.get_or_generate(safe_address).get_safe_info()
Expand Down
4 changes: 3 additions & 1 deletion safe_transaction_service/history/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,9 @@ def get(self, request, address, *args, **kwargs):
},
)

if not SafeContract.objects.filter(address=address).exists():
logger.debug("param:%s", address)
logger.debug(settings.EXTERNAL_ADDRESS_LIST)
if (not SafeContract.objects.filter(address=address).exists()) and (address not in settings.EXTERNAL_ADDRESS_LIST):
return Response(status=status.HTTP_404_NOT_FOUND)

try:
Expand Down

0 comments on commit 9029018

Please sign in to comment.