Gateway

class services.perpetual.gateway.gateway.Gateway

Perpetual services HTTP gateway for external interactions.

async add_transaction(request: aiohttp.web_request.Request) aiohttp.web_response.Response

/add_transaction endpoint

Parameters
  • tx_id (int) – Transaction sequence number issued by the caller.

  • tx (Transaction) – Transaction body

Available tx types:

Example

Deposit

http

POST /gateway/add_transaction HTTP/1.1
Accept: application/json

        {
            "tx": {
                "amount": "2569146471088859254",
                "position_id": "7758176404715800194",
                "public_key": "0x37ebdcde87a1613e443df789558867f5ba91faf7a024204f7c1bd874da5e70a",
                "type": "DEPOSIT"
            },
            "tx_id": 1
        }

curl

curl -i -X POST https://nohost/gateway/add_transaction -H "Accept: application/json" --data-raw '{

            "tx": {

                "amount": "2569146471088859254",

                "position_id": "7758176404715800194",

                "public_key": "0x37ebdcde87a1613e443df789558867f5ba91faf7a024204f7c1bd874da5e70a",

                "type": "DEPOSIT"

            },

            "tx_id": 1

        }'

wget

wget -S -O- https://nohost/gateway/add_transaction --header="Accept: application/json" --post-data='{

            "tx": {

                "amount": "2569146471088859254",

                "position_id": "7758176404715800194",

                "public_key": "0x37ebdcde87a1613e443df789558867f5ba91faf7a024204f7c1bd874da5e70a",

                "type": "DEPOSIT"

            },

            "tx_id": 1

        }'

httpie

echo '{

            "tx": {

                "amount": "2569146471088859254",

                "position_id": "7758176404715800194",

                "public_key": "0x37ebdcde87a1613e443df789558867f5ba91faf7a024204f7c1bd874da5e70a",

                "type": "DEPOSIT"

            },

            "tx_id": 1

        }' | http POST https://nohost/gateway/add_transaction Accept:application/json

python-requests

requests.post('https://nohost/gateway/add_transaction', headers={'Accept': 'application/json'}, data='{\r\n\n            "tx": {\r\n\n                "amount": "2569146471088859254",\r\n\n                "position_id": "7758176404715800194",\r\n\n                "public_key": "0x37ebdcde87a1613e443df789558867f5ba91faf7a024204f7c1bd874da5e70a",\r\n\n                "type": "DEPOSIT"\r\n\n            },\r\n\n            "tx_id": 1\r\n\n        }')

response

HTTP/1.1 200 OK
Content-Type: application/json

{"code": "TRANSACTION_RECEIVED", "tx_id": 5678}

Response:

Parameters
  • code – The response code of the request.

  • tx_id – The tx_id of the request this reponse belongs to.

filter_tx(tx: services.everest.api.gateway.transaction.EverestTransaction)

Blocks transactions of specific types.

async get_first_unused_tx_id(request: aiohttp.web_request.Request) aiohttp.web_response.Response

Gets the next transaction id that all of its predecessors exist in the system. If no ids exist in the system - then 0 will be returned.

While most of the time this implies the next tx_id used should be the returned value, this is not guaranteed, since while this value is returned, some new transaction may be written, rendering the returned response irrelevant.

Returns

The next consecutive tx_id, all of its predecessors exist in our system.

Return type

int

Example

http

GET /gateway/get_first_unused_tx_id HTTP/1.1
Host: localhost:9611
Accept: application/json

HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 8

5678

curl

curl -i -X GET https://localhost:9611/gateway/get_first_unused_tx_id -H "Accept: application/json" --data-raw 'HTTP/1.1 200 OK

Content-Type: text/plain; charset=utf-8

Content-Length: 8



5678'

wget

wget -S -O- https://localhost:9611/gateway/get_first_unused_tx_id --header="Accept: application/json" --body-data='HTTP/1.1 200 OK

Content-Type: text/plain; charset=utf-8

Content-Length: 8



5678'

httpie

echo 'HTTP/1.1 200 OK

Content-Type: text/plain; charset=utf-8

Content-Length: 8



5678' | http https://localhost:9611/gateway/get_first_unused_tx_id Accept:application/json

python-requests

requests.get('https://localhost:9611/gateway/get_first_unused_tx_id', headers={'Accept': 'application/json'}, data='HTTP/1.1 200 OK\r\n\nContent-Type: text/plain; charset=utf-8\r\n\nContent-Length: 8\r\n\n\r\n\n5678')
async get_starkex_contract_address(request)

Gets the StarkEx contract address. This is the address used for registering keys and tokens, and performing onchain deposits and withdrawals.

Returns

On-chain StarkEx contract address.

Return type

str

Example

http

GET /gateway/get_starkex_contract_address HTTP/1.1
Host: localhost:9411
Accept: application/json

curl

curl -i -X GET https://localhost:9411/gateway/get_starkex_contract_address -H "Accept: application/json"

wget

wget -S -O- https://localhost:9411/gateway/get_starkex_contract_address --header="Accept: application/json"

httpie

http https://localhost:9411/gateway/get_starkex_contract_address Accept:application/json

python-requests

requests.get('https://localhost:9411/gateway/get_starkex_contract_address', headers={'Accept': 'application/json'})

response

HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 44

"0x8013A6840804aA0DC68f544cBa0a9baF1bE2315A"
set_alternative_endpoint_config(request)

Updates the alternative-transaction endpoint configuration. This type of request is allowed only in setups that support dynamically configuring the endpoint for alternative transactions.

Note: The updated configuration will be used by the alternative-transaction mechanism only if dynamic configuration is enabled.

The dynamic configuration request class: AlternativeEndpointSettingRequest

Returns

A message stating if the configuration request is accepted or rejected.

Return type

str

Example

http

POST /gateway/set_alternative_endpoint_config HTTP/1.1
Host: localhost:9411
Accept: application/json

{
    "bearer_token": "123-456-789",
    "client_certificate": null,
    "client_key": null,
    "failure_description_url": null,
    "server_certificate": null,
    "url": "https://sample-alternative-tx-endpoint"
}

curl

curl -i -X POST https://localhost:9411/gateway/set_alternative_endpoint_config -H "Accept: application/json" --data-raw '{

    "bearer_token": "123-456-789",

    "client_certificate": null,

    "client_key": null,

    "failure_description_url": null,

    "server_certificate": null,

    "url": "https://sample-alternative-tx-endpoint"

}'

wget

wget -S -O- https://localhost:9411/gateway/set_alternative_endpoint_config --header="Accept: application/json" --post-data='{

    "bearer_token": "123-456-789",

    "client_certificate": null,

    "client_key": null,

    "failure_description_url": null,

    "server_certificate": null,

    "url": "https://sample-alternative-tx-endpoint"

}'

httpie

echo '{

    "bearer_token": "123-456-789",

    "client_certificate": null,

    "client_key": null,

    "failure_description_url": null,

    "server_certificate": null,

    "url": "https://sample-alternative-tx-endpoint"

}' | http POST https://localhost:9411/gateway/set_alternative_endpoint_config Accept:application/json

python-requests

requests.post('https://localhost:9411/gateway/set_alternative_endpoint_config', headers={'Accept': 'application/json'}, data='{\r\n\n    "bearer_token": "123-456-789",\r\n\n    "client_certificate": null,\r\n\n    "client_key": null,\r\n\n    "failure_description_url": null,\r\n\n    "server_certificate": null,\r\n\n    "url": "https://sample-alternative-tx-endpoint"\r\n\n}')

response

HTTP/1.1 200 OK
Content-Type: application/json

{"Alternative Strategy config is set"}