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 /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/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/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/add_transaction Accept:application/json
python-requests
requests.post('https://nohost/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.
- 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 /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/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/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/get_first_unused_tx_id Accept:application/json
python-requests
requests.get('https://localhost:9611/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')