add token,tokens,refill_gas to api spec

This commit is contained in:
William Luke 2021-11-23 11:11:58 +03:00
parent 3c3745228e
commit 421e1cbf32
2 changed files with 102 additions and 29 deletions

View File

@ -7,7 +7,6 @@ from urllib.parse import parse_qsl, urlparse
from cic_eth.server.celery_helper import call from cic_eth.server.celery_helper import call
from cic_eth.server.UWSGIOpenAPIRequest import UWSGIOpenAPIRequest from cic_eth.server.UWSGIOpenAPIRequest import UWSGIOpenAPIRequest
from openapi_core import create_spec from openapi_core import create_spec
from openapi_core.validation.request.datatypes import OpenAPIRequest
from openapi_core.validation.request.validators import RequestValidator from openapi_core.validation.request.validators import RequestValidator
from openapi_spec_validator.schemas import read_yaml_file from openapi_spec_validator.schemas import read_yaml_file
@ -22,15 +21,15 @@ log = logging.getLogger()
# TODO Implement wei conversions # TODO Implement wei conversions
# uwsgi application # uwsgi application
def application(env, start_response): def application(env, start_response):
# Validate incoming request against the open api spec
oAPIRequest = UWSGIOpenAPIRequest(env) oAPIRequest = UWSGIOpenAPIRequest(env)
validator = RequestValidator(spec) validator = RequestValidator(spec)
result = validator.validate(oAPIRequest) result = validator.validate(oAPIRequest)
# raise errors if request invalid
# result.raise_for_errors()
if result.errors: if result.errors:
# get list of errors
json_data = json.dumps(list(map(lambda e: str(e), result.errors))) json_data = json.dumps(list(map(lambda e: str(e), result.errors)))
content = json_data.encode('utf-8') content = json_data.encode('utf-8')
headers = [] headers = []
@ -39,12 +38,11 @@ def application(env, start_response):
headers.append(('Content-Type', 'application/json',)) headers.append(('Content-Type', 'application/json',))
start_response('400 Invalid Request', headers) start_response('400 Invalid Request', headers)
return [content] return [content]
parsed_url = urlparse(env.get('REQUEST_URI')) # /api
parsed_url = urlparse(env.get('REQUEST_URI'))
path = parsed_url.path path = parsed_url.path
params = dict(parse_qsl(parsed_url.query)) params = dict(parse_qsl(parsed_url.query))
# Setup Channel to receive the result
if path == '/transactions': if path == '/transactions':
address = params.pop('address') address = params.pop('address')
print('address', address, ) print('address', address, )
@ -95,8 +93,10 @@ def application(env, start_response):
data = call('tokens', token_symbols, **params) data = call('tokens', token_symbols, **params)
elif path == '/default_token': 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) json_data = json.dumps(data)
content = json_data.encode('utf-8') content = json_data.encode('utf-8')
headers = [] headers = []

View File

@ -13,12 +13,99 @@ info:
servers: servers:
- url: / - url: /
paths: paths:
/default_token: /tokens:
description: Retrieves the default fallback token of the custodial network.
get: get:
tags: tags:
- Token - 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 operationId: get_default_token
responses: responses:
"200": "200":
@ -27,13 +114,11 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/Token" $ref: "#/components/schemas/Token"
x-openapi-router-controller: cic_eth.server.controllers.token_controller
/balance: /balance:
description: Retrieves the current token balance of the given address
get: get:
tags: tags:
- Account - Account
description: Retrieve Address Balance description: Retrieves the current token balance of the given address
operationId: account_balance operationId: account_balance
parameters: parameters:
- name: address - name: address
@ -63,15 +148,11 @@ paths:
items: items:
$ref: "#/components/schemas/TokenBalance" $ref: "#/components/schemas/TokenBalance"
x-openapi-router-controller: cic_eth.server.controllers.account_controller
/transactions: /transactions:
description:
Retrieve an aggregate list of latest transactions of internal and
(optionally) external origin in reverse chronological order.
get: get:
tags: tags:
- Account - 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 operationId: list_transactions
parameters: parameters:
- name: address - name: address
@ -95,15 +176,11 @@ paths:
type: array type: array
items: items:
$ref: "#/components/schemas/Transaction" $ref: "#/components/schemas/Transaction"
x-openapi-router-controller: cic_eth.server.controllers.account_controller
/create_account: /create_account:
description:
Creates a new blockchain address encrypted with the given password
and returns the new address
post: post:
tags: tags:
- Account - 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 operationId: create_account_post
parameters: parameters:
- name: password - name: password
@ -127,9 +204,7 @@ paths:
schema: schema:
type: string type: string
example: "bea54d37f1a469515bda96e116695cedd323c182" example: "bea54d37f1a469515bda96e116695cedd323c182"
x-openapi-router-controller: cic_eth.server.controllers.account_controller
/transfer: /transfer:
description: Performs a transfer of ERC20 tokens from one address to another.
post: post:
tags: tags:
- Account - Account
@ -165,7 +240,6 @@ paths:
application/json: application/json:
schema: schema:
type: string type: string
x-openapi-router-controller: cic_eth.server.controllers.account_controller
/transfer_from: /transfer_from:
post: post:
tags: tags:
@ -212,7 +286,6 @@ paths:
application/json: application/json:
schema: schema:
type: string type: string
x-openapi-router-controller: cic_eth.server.controllers.account_controller
components: components:
schemas: schemas:
Transaction: Transaction: