# REST API

## Send a transaction to the contract

<mark style="color:green;">`POST`</mark> `http://relayer/transaction`

This method checks an incoming transaction, builds the zkSNARK Merkle tree proof, and sends the transaction to the Pool contract. The transaction doesn’t process immediately because contract interaction is completed in a serial manner. Incoming transactions are put into the job queue. The method returns `jobId` on success

#### Request Body

| Name                                       | Type       | Description                                                                                     |
| ------------------------------------------ | ---------- | ----------------------------------------------------------------------------------------------- |
| proof<mark style="color:red;">\*</mark>    | Dictionary | Transaction proof (built by a client)                                                           |
| memo<mark style="color:red;">\*</mark>     | String     | Memo block, Base64-encoded                                                                      |
| tx\_type<mark style="color:red;">\*</mark> | Integer    | 0: deposit, 1: transfer, 2: withdrawal                                                          |
| depositSignature                           | String     | Account nullifier signature with the client's native chain private key (for withdrawal tx only) |

{% tabs %}
{% tab title="201: Created Transaction has been pushed to the job queue" %}

```javascript
{
    "jobId": "1"
}
```

{% endtab %}

{% tab title="400: Bad Request Error while parsing the input JSON" %}

```javascript
{
    error: "Error while parsing the input JSON",
    description: "tx_type is incorrect"
}
```

{% endtab %}

{% tab title="500: Internal Server Error Something went wrong" %}

```javascript
{
    error: "An internal error has occured. Please try again later",
    description: "optional error description"
}
```

{% endtab %}
{% endtabs %}

## Get the job status

<mark style="color:blue;">`GET`</mark> `http://relayer/job/:id`

Returns incoming transaction processing state. `jobId` is returned by /transaction method

#### Query Parameters

| Name                                 | Type    | Description    |
| ------------------------------------ | ------- | -------------- |
| id<mark style="color:red;">\*</mark> | Integer | Job identifier |

{% tabs %}
{% tab title="200: OK Job status in body" %}

```javascript
{
    "state": "failed",
    "txHash": null
}
```

{% endtab %}

{% tab title="404: Not Found Job with specified ID not found" %}

```javascript
"Job 2 not found"
```

{% endtab %}

{% tab title="500: Internal Server Error Something went wrong" %}

```javascript
{
    error: "An internal error has occured. Please try again later",
    description: "optional error description"
}}
```

{% endtab %}
{% endtabs %}

## Query transactions

<mark style="color:blue;">`GET`</mark> `http://relayer/transactions/:limit/:offset`

Returns memo blocks and out commits for transactions at the specified offset. This method is used by clients to synchronize account state.

#### Query Parameters

| Name                                     | Type    | Description                                                                           |
| ---------------------------------------- | ------- | ------------------------------------------------------------------------------------- |
| limit<mark style="color:red;">\*</mark>  | Integer | Number of transactions to query                                                       |
| offset<mark style="color:red;">\*</mark> | Integer | The Index of the first transaction (in the Merkle tree, should be  a multiple of 128) |

{% tabs %}
{% tab title="200: OK Array of requested transactions" %}

```javascript
[
    (Buffer|null)
]
```

{% endtab %}

{% tab title="400: Bad Request Check query parameters" %}

```javascript
{
    error: "Incorrect parameters",
    description: "limit is too high"
}
```

{% endtab %}

{% tab title="500: Internal Server Error Something went wrong" %}

```javascript
{
    error: "An internal error has occured. Please try again later",
    description: "optional error description"
}
```

{% endtab %}
{% endtabs %}

## Get Merkle tree proofs at the specified position

<mark style="color:blue;">`GET`</mark> `http://relayer/merkle/proof?[index]`

{% tabs %}
{% tab title="200: OK Success" %}

```javascript
{
    root, // Merkle tree root for this proofs
    deltaIndex, // this index should be used for building tx proof
    proofs // Merkle tree proofs
}
```

{% endtab %}

{% tab title="404: Not Found Specified index doesn't exist in the current tree" %}

```javascript
"Incorrect index"
```

{% endtab %}

{% tab title="500: Internal Server Error Something went wrong" %}

```javascript
{
    error: "An internal error has occured. Please try again later",
    description: "optional error description"
}
```

{% endtab %}
{% endtabs %}

## Get Merkle tree root node at the specified index

<mark style="color:blue;">`GET`</mark> `http://relayer/merkle/root/:index`

#### Query Parameters

| Name  | Type    | Description |
| ----- | ------- | ----------- |
| index | Integer |             |

{% tabs %}
{% tab title="200: OK Success" %}

```javascript
"11469701942666298368112882412133877458305516134926649826543144744382391691533"
```

{% endtab %}

{% tab title="404: Not Found Index not exist in the Merkle tree" %}

```javascript
"Index not exist in the Merkle tree"
```

{% endtab %}

{% tab title="500: Internal Server Error Something went wrong" %}

```javascript
{
    error: "An internal error has occured. Please try again later",
    description: "optional error description"
}
```

{% endtab %}
{% endtabs %}

## Calculate transaction proof

<mark style="color:green;">`POST`</mark> `http://relayer/proof_tx`

Builds zkSNARK proof for the transaction based on public and secret transaction input calculated by a client.

**WARNING:** This is a debug method used to decrease client overhead. DO NOT use  in production, as the client should pass public and secret transactional data. This significantly decreases overall security!

#### Request Body

| Name                                  | Type       | Description                   |
| ------------------------------------- | ---------- | ----------------------------- |
| pub<mark style="color:red;">\*</mark> | Dictionary | Public inputs for the circuit |
| sec<mark style="color:red;">\*</mark> | Dictionary | Secret inputs for the circuit |

{% tabs %}
{% tab title="200: OK Proof has been calculated successfully" %}

```javascript
{
    proof // Transaction proof
}
```

{% endtab %}

{% tab title="400: Bad Request Error in the public or secret input" %}

```javascript
{
    error: "Error while parsing the input JSON",
    description: "cannot find pub field"
}
```

{% endtab %}

{% tab title="500: Internal Server Error Something went wrong" %}

```javascript
{
    error: "An internal error has occured. Please try again later",
    description: "optional error description"
}
```

{% endtab %}
{% endtabs %}

## Get the next index in the Merkle tree

<mark style="color:blue;">`GET`</mark> `http://relayer/delta_index`

{% tabs %}
{% tab title="200: OK An integer value of the index" %}
0
{% endtab %}

{% tab title="500: Internal Server Error Something went wrong" %}

```javascript
{
    error: "An internal error has occured. Please try again later",
    description: "optional error description"
}
```

{% endtab %}
{% endtabs %}

## Get current Merkle tree root and delta index

<mark style="color:blue;">`GET`</mark> `http://relayer/info`

{% tabs %}
{% tab title="200: OK Success" %}

```javascript
{
    "root": "11469701942666298368112882412133877458305516134926649826543144744382391691533",
    "deltaIndex": 0
}
```

{% endtab %}

{% tab title="500: Internal Server Error Something went wrong" %}

```javascript
{
    error: "An internal error has occured. Please try again later",
    description: "optional error description"
}
```

{% endtab %}
{% endtabs %}
