From 7376b4974f5ffffc4ad7265b586b75031099de12 Mon Sep 17 00:00:00 2001 From: Phillip Jensen Date: Fri, 6 Sep 2024 10:23:07 +0200 Subject: [PATCH] Fix wallet not being identified --- stats-backend/api2/scanner.py | 82 +++------------------------------- stats-backend/api2/utils.py | 18 ++++++-- stats-backend/core/settings.py | 16 +++++++ 3 files changed, 37 insertions(+), 79 deletions(-) diff --git a/stats-backend/api2/scanner.py b/stats-backend/api2/scanner.py index 7b076f3..bdcf945 100644 --- a/stats-backend/api2/scanner.py +++ b/stats-backend/api2/scanner.py @@ -21,7 +21,7 @@ from django.db.models.functions import Abs from django.db import transaction import calendar -from .utils import identify_network_by_offer +from .utils import identify_network_by_offer,identify_wallet_and_network from django.db import transaction from django.db.models import OuterRef, Subquery @@ -147,20 +147,13 @@ def update_providers_info(node_props): is_online = check_node_status(obj.node_id) obj.online = is_online is_online_checked_providers.add(obj.node_id) - obj.network = identify_network_by_offer(offerobj) + obj.network = data['network'] obj.save() print(f"Done updating {len(unique_providers)} providers") -TESTNET_KEYS = [ - "golem.com.payment.platform.erc20-goerli-tglm.address", - "golem.com.payment.platform.erc20-mumbai-tglm.address", - "golem.com.payment.platform.erc20-holesky-tglm.address", - "golem.com.payment.platform.erc20next-goerli-tglm.address", - "golem.com.payment.platform.erc20next-mumbai-tglm.address", - "golem.com.payment.platform.erc20next-holesky-tglm.address", -] + examples_dir = pathlib.Path(__file__).resolve().parent.parent sys.path.append(str(examples_dir)) @@ -326,72 +319,9 @@ async def list_offers( data = event.props if not event.issuer in current_scan_providers: current_scan_providers.add(event.issuer) - if "golem.com.payment.platform.zksync-mainnet-glm.address" in str( - event.props - ): - data["wallet"] = event.props[ - "golem.com.payment.platform.zksync-mainnet-glm.address" - ] - elif "golem.com.payment.platform.zksync-rinkeby-tglm.address" in str( - event.props - ): - data["wallet"] = event.props[ - "golem.com.payment.platform.zksync-rinkeby-tglm.address" - ] - elif "golem.com.payment.platform.erc20-mainnet-glm.address" in str( - event.props - ): - data["wallet"] = event.props[ - "golem.com.payment.platform.erc20-mainnet-glm.address" - ] - elif "golem.com.payment.platform.erc20-polygon-glm.address" in str( - event.props - ): - data["wallet"] = event.props[ - "golem.com.payment.platform.erc20-polygon-glm.address" - ] - elif "golem.com.payment.platform.erc20-goerli-tglm.address" in str( - event.props - ): - data["wallet"] = event.props[ - "golem.com.payment.platform.erc20-goerli-tglm.address" - ] - elif "golem.com.payment.platform.erc20-rinkeby-tglm.address" in str( - event.props - ): - data["wallet"] = event.props[ - "golem.com.payment.platform.erc20-rinkeby-tglm.address" - ] - elif "golem.com.payment.platform.polygon-polygon-glm.address" in str( - event.props - ): - data["wallet"] = event.props[ - "golem.com.payment.platform.polygon-polygon-glm.address" - ] - elif "golem.com.payment.platform.erc20next-mainnet-glm.address" in str( - event.props - ): - data["wallet"] = event.props[ - "golem.com.payment.platform.erc20next-mainnet-glm.address" - ] - elif "golem.com.payment.platform.erc20next-polygon-glm.address" in str( - event.props - ): - data["wallet"] = event.props[ - "golem.com.payment.platform.erc20next-polygon-glm.address" - ] - elif "golem.com.payment.platform.erc20next-goerli-tglm.address" in str( - event.props - ): - data["wallet"] = event.props[ - "golem.com.payment.platform.erc20next-goerli-tglm.address" - ] - elif "golem.com.payment.platform.erc20next-rinkeby-tglm.address" in str( - event.props - ): - data["wallet"] = event.props[ - "golem.com.payment.platform.erc20next-rinkeby-tglm.address" - ] + wallet, network = identify_wallet_and_network(event.props) + data["wallet"] = wallet + data["network"] = network data["node_id"] = event.issuer node_props.append(json.dumps(data)) diff --git a/stats-backend/api2/utils.py b/stats-backend/api2/utils.py index 36a462d..69917dc 100644 --- a/stats-backend/api2/utils.py +++ b/stats-backend/api2/utils.py @@ -5,10 +5,22 @@ def identify_network_by_offer(offer): - for driver in settings.GOLEM_MAINNET_PAYMENT_DRIVERS: - if f"golem.com.payment.platform.{driver}.address" in offer.properties: + for key in settings.GOLEM_MAINNET_KEYS: + if key in offer.properties: return "mainnet" - return "testnet" + for key in settings.GOLEM_TESTNET_KEYS: + if key in offer.properties: + return "testnet" + return "unknown" # If neither mainnet nor testnet keys are found + +def identify_wallet_and_network(event_props): + for key in settings.GOLEM_MAINNET_KEYS: + if key in event_props: + return event_props[key], "mainnet" + for key in settings.GOLEM_TESTNET_KEYS: + if key in event_props: + return event_props[key], "testnet" + return None, "unknown" def is_provider_online(provider): diff --git a/stats-backend/core/settings.py b/stats-backend/core/settings.py index 3c42167..d1ead5b 100644 --- a/stats-backend/core/settings.py +++ b/stats-backend/core/settings.py @@ -24,6 +24,22 @@ "erc20-polygon-glm", "erc20next-polygon-glm", ] +GOLEM_TESTNET_KEYS = [ + "golem.com.payment.platform.erc20-goerli-tglm.address", + "golem.com.payment.platform.erc20-amoy-tglm.address", + "golem.com.payment.platform.erc20-holesky-tglm.address", + "golem.com.payment.platform.erc20-mumbai-tglm.address", + "golem.com.payment.platform.erc20next-goerli-tglm.address", + "golem.com.payment.platform.erc20next-mumbai-tglm.address", + "golem.com.payment.platform.erc20next-holesky-tglm.address", + "golem.com.payment.platform.erc20-sepolia-tglm.address", +] + +GOLEM_MAINNET_KEYS = [ + "golem.com.payment.platform.erc20-mainnet-glm.address", + "golem.com.payment.platform.erc20-polygon-glm.address", + +] TESTING = len(sys.argv) > 1 and sys.argv[1] == "test"