From d9967ebebc2668111d1daf0a8c06d2f6d5e9049c Mon Sep 17 00:00:00 2001 From: KuhnChris Date: Mon, 21 Jan 2019 21:52:44 +0100 Subject: [PATCH 1/3] Added first draft for new V3 Infura Auth --- app/app/local.env | 3 +++ app/app/settings.py | 2 ++ app/dashboard/tests/test_dashboard_utils.py | 5 ++++- app/dashboard/utils.py | 11 +++++++++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/app/local.env b/app/app/local.env index 5cf4529082a..77ef19e66a5 100644 --- a/app/app/local.env +++ b/app/app/local.env @@ -31,3 +31,6 @@ GITHUB_API_TOKEN= GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= GITHUB_APP_NAME= + +INFURA_USE_V3=False +INFURA_V3_PROJECT_ID=abcdefabcdef123412341234 diff --git a/app/app/settings.py b/app/app/settings.py index 6d0e314c7e3..2d493c54ac2 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -692,6 +692,8 @@ # Web3 WEB3_HTTP_PROVIDER = env('WEB3_HTTP_PROVIDER', default='https://rinkeby.infura.io') +INFURA_USE_V3 = env.bool('INFURA_USE_V3',False) +INFURA_V3_PROJECT_ID = env('INFURA_V3_PROJECT_ID','') # COLO Coin COLO_ACCOUNT_ADDRESS = env('COLO_ACCOUNT_ADDRESS', default='') # TODO diff --git a/app/dashboard/tests/test_dashboard_utils.py b/app/dashboard/tests/test_dashboard_utils.py index 2618f0c75ca..be501ea5059 100644 --- a/app/dashboard/tests/test_dashboard_utils.py +++ b/app/dashboard/tests/test_dashboard_utils.py @@ -42,7 +42,10 @@ def test_get_web3(): assert isinstance(web3_provider, Web3) assert len(web3_provider.providers) == 1 assert isinstance(web3_provider.providers[0], HTTPProvider) - assert web3_provider.providers[0].endpoint_uri == f'https://{network}.infura.io' + if settings.INFURA_USE_V3: + assert web3_provider.providers[0].endpoint_uri == f'https://{network}.infura.io/v3/{settings.INFURA_V3_PROJECT_ID}' + else: + assert web3_provider.providers[0].endpoint_uri == f'https://{network}.infura.io' @staticmethod def test_get_bounty_contract(): diff --git a/app/dashboard/utils.py b/app/dashboard/utils.py index 0eefd30ac16..2da32ea9099 100644 --- a/app/dashboard/utils.py +++ b/app/dashboard/utils.py @@ -261,9 +261,16 @@ def get_web3(network, sockets=False): """ if network in ['mainnet', 'rinkeby', 'ropsten']: if sockets: - provider = WebsocketProvider(f'wss://{network}.infura.io/ws') + if settings.INFURA_USE_V3: + provider = WebsocketProvider(f'wss://{network}.infura.io/ws/v3/{settings.INFURA_V3_PROJECT_ID}') + else: + provider = WebsocketProvider(f'wss://{network}.infura.io/ws') else: - provider = HTTPProvider(f'https://{network}.infura.io') + if settings.INFURA_USE_V3: + provider = HTTPProvider(f'https://{network}.infura.io') + else: + provider = HTTPProvider(f'https://{network}.infura.io/v3/{settings.INFURA_V3_PROJECT_ID}') + w3 = Web3(provider) if network == 'rinkeby': w3.middleware_stack.inject(geth_poa_middleware, layer=0) From 7dda76397995545c95c2a09c7e239fb51a0cf9ac Mon Sep 17 00:00:00 2001 From: octavioamu Date: Wed, 20 Mar 2019 14:54:13 -0300 Subject: [PATCH 2/3] changes for infura new endpoints --- app/app/local.env | 3 +-- app/app/settings.py | 4 ++-- app/dashboard/utils.py | 4 ++-- docs/ENVIRONMENT_VARIABLES.md | 2 ++ 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/app/local.env b/app/app/local.env index 77ef19e66a5..686cbaaf75c 100644 --- a/app/app/local.env +++ b/app/app/local.env @@ -32,5 +32,4 @@ GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= GITHUB_APP_NAME= -INFURA_USE_V3=False -INFURA_V3_PROJECT_ID=abcdefabcdef123412341234 +INFURA_USE_V3=True diff --git a/app/app/settings.py b/app/app/settings.py index 2d493c54ac2..a513a3902b2 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -692,8 +692,8 @@ # Web3 WEB3_HTTP_PROVIDER = env('WEB3_HTTP_PROVIDER', default='https://rinkeby.infura.io') -INFURA_USE_V3 = env.bool('INFURA_USE_V3',False) -INFURA_V3_PROJECT_ID = env('INFURA_V3_PROJECT_ID','') +INFURA_USE_V3 = env.bool('INFURA_USE_V3', False) +INFURA_V3_PROJECT_ID = env('INFURA_V3_PROJECT_ID', default='1e0a90928efe4bb78bb1eeceb8aacc27') # COLO Coin COLO_ACCOUNT_ADDRESS = env('COLO_ACCOUNT_ADDRESS', default='') # TODO diff --git a/app/dashboard/utils.py b/app/dashboard/utils.py index 2da32ea9099..7d093eab3b4 100644 --- a/app/dashboard/utils.py +++ b/app/dashboard/utils.py @@ -267,9 +267,9 @@ def get_web3(network, sockets=False): provider = WebsocketProvider(f'wss://{network}.infura.io/ws') else: if settings.INFURA_USE_V3: - provider = HTTPProvider(f'https://{network}.infura.io') - else: provider = HTTPProvider(f'https://{network}.infura.io/v3/{settings.INFURA_V3_PROJECT_ID}') + else: + provider = HTTPProvider(f'https://{network}.infura.io') w3 = Web3(provider) if network == 'rinkeby': diff --git a/docs/ENVIRONMENT_VARIABLES.md b/docs/ENVIRONMENT_VARIABLES.md index 0179a72f9b7..f8d0c2477fd 100644 --- a/docs/ENVIRONMENT_VARIABLES.md +++ b/docs/ENVIRONMENT_VARIABLES.md @@ -120,6 +120,8 @@ The below environment variables are useful for overwriting [Django Silk](https:/ | Variable | Description | Type | Default | | --- | --- | --- | --- | | WEB3_HTTP_PROVIDER | The Web3 HTTP provider URI to be used. | `str` | https://rinkeby.infura.io | +| INFURA_USE_V3 | Use new API | `bool` | False | +| INFURA_V3_PROJECT_ID | Infura Project ID | `str` | 1e0a90928efe4bb78bb1eeceb8aacc27 | ## VSCode Remote Debugging From c52e6d096eb3c2337ca2098af52f34761d19a55d Mon Sep 17 00:00:00 2001 From: Dan Lipert Date: Thu, 21 Mar 2019 22:16:14 +0900 Subject: [PATCH 3/3] add settings import for test --- app/dashboard/tests/test_dashboard_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/dashboard/tests/test_dashboard_utils.py b/app/dashboard/tests/test_dashboard_utils.py index be501ea5059..b0e86198bfe 100644 --- a/app/dashboard/tests/test_dashboard_utils.py +++ b/app/dashboard/tests/test_dashboard_utils.py @@ -19,6 +19,7 @@ """ from unittest.mock import patch +from django.conf import settings from django.test.client import RequestFactory from dashboard.utils import (