diff --git a/apps/cic-eth/cic_eth/runnable/daemons/server.py b/apps/cic-eth/cic_eth/runnable/daemons/server.py index e6f66084..a258213f 100644 --- a/apps/cic-eth/cic_eth/runnable/daemons/server.py +++ b/apps/cic-eth/cic_eth/runnable/daemons/server.py @@ -7,7 +7,6 @@ from urllib.parse import parse_qsl, urlparse from cic_eth.server.celery_helper import call from cic_eth.server.UWSGIOpenAPIRequest import UWSGIOpenAPIRequest from openapi_core import create_spec -from openapi_core.validation.request.datatypes import OpenAPIRequest from openapi_core.validation.request.validators import RequestValidator from openapi_spec_validator.schemas import read_yaml_file @@ -22,15 +21,15 @@ log = logging.getLogger() # TODO Implement wei conversions # uwsgi application + + def application(env, start_response): + # Validate incoming request against the open api spec oAPIRequest = UWSGIOpenAPIRequest(env) validator = RequestValidator(spec) result = validator.validate(oAPIRequest) - # raise errors if request invalid - # result.raise_for_errors() if result.errors: - # get list of errors json_data = json.dumps(list(map(lambda e: str(e), result.errors))) content = json_data.encode('utf-8') headers = [] @@ -39,12 +38,11 @@ def application(env, start_response): headers.append(('Content-Type', 'application/json',)) start_response('400 Invalid Request', headers) return [content] - parsed_url = urlparse(env.get('REQUEST_URI')) # /api + + parsed_url = urlparse(env.get('REQUEST_URI')) path = parsed_url.path params = dict(parse_qsl(parsed_url.query)) - # Setup Channel to receive the result - if path == '/transactions': address = params.pop('address') print('address', address, ) @@ -95,8 +93,10 @@ def application(env, start_response): data = call('tokens', token_symbols, **params) elif path == '/default_token': - data = call('default_token', ) - + data = call('default_token') + else: + start_response('404 Seems like you are lost', []) + return [] json_data = json.dumps(data) content = json_data.encode('utf-8') headers = [] diff --git a/apps/cic-eth/cic_eth/server/openapi/server.yaml b/apps/cic-eth/cic_eth/server/openapi/server.yaml index c43bd27a..80bb2984 100644 --- a/apps/cic-eth/cic_eth/server/openapi/server.yaml +++ b/apps/cic-eth/cic_eth/server/openapi/server.yaml @@ -13,12 +13,99 @@ info: servers: - url: / paths: - /default_token: - description: Retrieves the default fallback token of the custodial network. + /tokens: get: tags: - Token - description: Retrieve transactions + description: Perform a token data lookup from the token index. The token index will enforce unique associations between token symbol and contract address. + operationId: get_tokens + parameters: + - name: token_symbols + in: query + description: Token symbol to look up + required: true + schema: + type: array + example: ["GTF"] + items: + type: string + - name: proof + in: query + description: | + Proofs to add to signature verification for the token + - None (Default), in which case proof checks are skipped (although there may still be builtin proof checks being performed) + - Single string, where the same proof is used for each token lookup + - Array of strings, where the respective proof is used for the respective token. number of proofs must match the number of tokens. + - Array of lists, where the respective proofs in each list is used for the respective token. number of lists of proofs must match the number of tokens. + + required: false + schema: + oneOf: + - type: array + items: + type: string + - type: string + + responses: + "200": + description: OK. + content: + application/json: + schema: + $ref: "#/components/schemas/Token" + /token: + get: + tags: + - Token + description: Single-token alias for tokens method. + operationId: get_token + parameters: + - name: token_symbol + in: query + description: Token symbol to look up + required: true + schema: + type: string + example: "GFT" + - name: proof + in: query + description: Proofs to add to signature verification for the token + required: false + schema: + type: string + + responses: + "200": + description: OK. + content: + application/json: + schema: + $ref: "#/components/schemas/Token" + /refill_gas: + post: + tags: + - Account + description: Creates a new gas refill transaction with the registered gas provider address. + operationId: post_refill_gas + parameters: + - name: address + in: query + required: true + schema: + type: string + example: "0xe88ba386f0efc7117e8d0d17a750fce492516ecb" + responses: + "200": + description: OK. + content: + application/json: + schema: + $ref: "#/components/schemas/Token" + /default_token: + get: + tags: + - Token + description: Retrieves the default fallback token of the custodial network. operationId: get_default_token responses: "200": @@ -27,13 +114,11 @@ paths: application/json: schema: $ref: "#/components/schemas/Token" - x-openapi-router-controller: cic_eth.server.controllers.token_controller /balance: - description: Retrieves the current token balance of the given address get: tags: - Account - description: Retrieve Address Balance + description: Retrieves the current token balance of the given address operationId: account_balance parameters: - name: address @@ -63,15 +148,11 @@ paths: items: $ref: "#/components/schemas/TokenBalance" - x-openapi-router-controller: cic_eth.server.controllers.account_controller /transactions: - description: - Retrieve an aggregate list of latest transactions of internal and - (optionally) external origin in reverse chronological order. get: tags: - Account - description: Retrieve Address Balance + description: Retrieve an aggregate list of latest transactions of internal and (optionally) external origin in reverse chronological order. operationId: list_transactions parameters: - name: address @@ -95,15 +176,11 @@ paths: type: array items: $ref: "#/components/schemas/Transaction" - x-openapi-router-controller: cic_eth.server.controllers.account_controller /create_account: - description: - Creates a new blockchain address encrypted with the given password - and returns the new address post: tags: - Account - description: Creates a new blockchain address + description: Creates a new blockchain address encrypted with the given password and returns the new address operationId: create_account_post parameters: - name: password @@ -127,9 +204,7 @@ paths: schema: type: string example: "bea54d37f1a469515bda96e116695cedd323c182" - x-openapi-router-controller: cic_eth.server.controllers.account_controller /transfer: - description: Performs a transfer of ERC20 tokens from one address to another. post: tags: - Account @@ -165,7 +240,6 @@ paths: application/json: schema: type: string - x-openapi-router-controller: cic_eth.server.controllers.account_controller /transfer_from: post: tags: @@ -212,7 +286,6 @@ paths: application/json: schema: type: string - x-openapi-router-controller: cic_eth.server.controllers.account_controller components: schemas: Transaction: