Last active
December 2, 2020 16:29
-
-
Save thr0wn/f6151ba06c8ae2d94575c7c6a282d5aa to your computer and use it in GitHub Desktop.
tx-mining-service patch
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
diff --git a/Pipfile b/Pipfile | |
index 7abf186..2e73894 100644 | |
--- a/Pipfile | |
+++ b/Pipfile | |
@@ -20,6 +20,7 @@ aiohttp = "*" | |
base58 = "*" | |
structlog = "*" | |
prometheus-client = "*" | |
+aiohttp_cors="*" | |
[requires] | |
python_version = "3.8" | |
diff --git a/txstratum/api.py b/txstratum/api.py | |
index 2060166..1132393 100644 | |
--- a/txstratum/api.py | |
+++ b/txstratum/api.py | |
@@ -6,11 +6,13 @@ import json | |
from typing import TYPE_CHECKING, Optional | |
from aiohttp import web | |
+import aiohttp_cors | |
from txstratum.commons import TokenCreationTransaction, Transaction | |
from txstratum.jobs import JobStatus, MinerTxJob | |
from txstratum.utils import tx_or_block_from_bytes | |
+ | |
if TYPE_CHECKING: | |
from txstratum.manager import TxMiningManager | |
@@ -34,11 +36,18 @@ class App: | |
self.max_tx_weight: float = max_tx_weight or MAX_TX_WEIGHT | |
self.tx_timeout: float = tx_timeout or TX_TIMEOUT | |
self.app = web.Application() | |
- self.app.router.add_get('/health-check', self.health_check) | |
- self.app.router.add_get('/mining-status', self.mining_status) | |
- self.app.router.add_get('/job-status', self.job_status) | |
- self.app.router.add_post('/submit-job', self.submit_job) | |
- self.app.router.add_post('/cancel-job', self.cancel_job) | |
+ cors = aiohttp_cors.setup(self.app, defaults={ | |
+ "*": aiohttp_cors.ResourceOptions( | |
+ allow_credentials=True, | |
+ expose_headers="*", | |
+ allow_headers="*", | |
+ ) | |
+ }) | |
+ cors.add(self.app.router.add_get('/health-check', self.health_check)) | |
+ cors.add(self.app.router.add_get('/mining-status', self.mining_status)) | |
+ cors.add(self.app.router.add_get('/job-status', self.job_status)) | |
+ cors.add(self.app.router.add_post('/submit-job', self.submit_job)) | |
+ cors.add(self.app.router.add_post('/cancel-job', self.cancel_job)) | |
async def health_check(self, request: web.Request) -> web.Response: | |
"""Return that the service is running.""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment