# RPC API

#### RPC Endpoints

You can make JSON RPC calls to GlitchD DA endpoints at <https://da.glitchd.network>.

#### DA RPC API Interface

| Method       | Params                                                                    | Return              | Description                                                                      |
| ------------ | ------------------------------------------------------------------------- | ------------------- | -------------------------------------------------------------------------------- |
| `commit`     | `blobs []Blob, namespace Namespace`                                       | `[]Commitment`      | Returns Commitment for each given Blob                                           |
| `get`        | `ids []Id, namespace Namespace`                                           | `[]Blob`            | Returns Blob for each given Id                                                   |
| `get_proofs` | `ids []Id, namespace Namespace`                                           | `[]Proof`           | Returns proofs for each given Id                                                 |
| `submit`     | `blobs []Blob, namespace Namespace`                                       | `[][]Id,Commitment` | Returns tuple of Id and Commitment for each given Blob                           |
| `validate`   | `ids []Id, commitments []Commitment, proofs []Proof, namespace Namespace` | `[]bool`            | Returns array of validation results for set of given ids, commitments and proofs |

Where:

* `Id` - \[]bytes
* `Blob` - \[]bytes
* `Commitment` - \[]bytes
* `Proof` - \[]bytes

#### RPC API Request/Response examples:

Service provided all requests and responses in [RPC 2.0 format](https://www.jsonrpc.org/specification)

`commit` Request body The argument is byte array

```json
   {
    "jsonrpc":"2.0",
    "id": 128,
    "method": "commit",
    "params": [
        [[104,101,108,108,111]],
        "namespace"
    ]
}
```

Success response should return an array of commitments of the byte array

```json
   {
    "jsonrpc":"2.0",
    "result":[[179,75,83,34,165,175,249,223,47,197,64,246,39,144,246,178,41,129,180,213,74,140,54,81,194,150,87,48,172,66,114,200,132,185,173,238,171,189,233,151,60,138,111,177,2,96,22,134]],
    "id":128
    }
```

`get` Request body

```json
   {
    "jsonrpc":"2.0",
    "id": 128,
    "method": "get",
    "params": [
        [
            [1,97,54,102,57,50,55,97,102,51,53,100,98,50,50,100,49,55,98,53,51,100,55,102,54,51,97,52,98,52,97,102,102,99,55,48,49,48,55,100,54,56,49,97,98,101,98,48,102,97,53,50,53,57,57,101,56,57,50,57,49,54,99,97]
        ],
        "namespace"
    ]
}
```

Success response

```json
   {
    "jsonrpc":"2.0",
    "result":[[104,101,108,108,111]],
    "id":128
    }
```

!!! In case there is no data in storage(means nothing was submitted before) it returns `empty bytes array`

`get_proofs` Request body

```json
   {
    "jsonrpc":"2.0",
    "id": 128,
    "method": "get_proofs",
    "params": [
        [
            [1,97,54,102,57,50,55,97,102,51,53,100,98,50,50,100,49,55,98,53,51,100,55,102,54,51,97,52,98,52,97,102,102,99,55,48,49,48,55,100,54,56,49,97,98,101,98,48,102,97,53,50,53,57,57,101,56,57,50,57,49,54,99,97]
        ],
        "namespace"
    ]
}
```

Success response

```json
   {
    "jsonrpc":"2.0",
    "result":[[166,226,152,3,148,197,142,68,37,3,30,235,83,168,156,244,25,94,85,95,38,18,205,209,242,109,0,45,121,48,13,160,133,205,96,223,139,179,76,141,151,183,74,156,153,101,48,136]],
    "id":128
    }
```

!!! In case there is no data in storage(means nothing was submitted before) it returns `empty string` Proof

`submit` Request body

```json
   {
    "jsonrpc":"2.0",
    "id": 128,
    "method": "submit",
    "params": [
        [[104,101,108,108,111]],
        "namespace"
    ]
}
```

Success response

```json
   {
    "jsonrpc":"2.0",
    "result":[
        [
            [1,97,54,102,57,50,55,97,102,51,53,100,98,50,50,100,49,55,98,53,51,100,55,102,54,51,97,52,98,52,97,102,102,99,55,48,49,48,55,100,54,56,49,97,98,101,98,48,102,97,53,50,53,57,57,101,56,57,50,57,49,54,99,97],
            [179,75,83,34,165,175,249,223,47,197,64,246,39,144,246,178,41,129,180,213,74,140,54,81,194,150,87,48,172,66,114,200,132,185,173,238,171,189,233,151,60,138,111,177,2,96,22,134]
        ]
    ],
    "id":128
    }
```

`validate` Request body 1st params argument is a "hello" string Id and Commitment("${Id}-{Commitment}"), see `Submit` example 2nd onw is a data with corrupted proof byte array

```json
   {
    "jsonrpc":"2.0",
    "id": 128,
    "method": "validate",
    "params": [
        [
            [1,97,54,102,57,50,55,97,102,51,53,100,98,50,50,100,49,55,98,53,51,100,55,102,54,51,97,52,98,52,97,102,102,99,55,48,49,48,55,100,54,56,49,97,98,101,98,48,102,97,53,50,53,57,57,101,56,57,50,57,49,54,99,97]
        ],
        [
            [179,75,83,34,165,175,249,223,47,197,64,246,39,144,246,178,41,129,180,213,74,140,54,81,194,150,87,48,172,66,114,200,132,185,173,238,171,189,233,151,60,138,111,177,2,96,22,134]
        ],
        [
            [166,226,152,3,148,197,142,68,37,3,30,235,83,168,156,244,25,94,85,95,38,18,205,209,242,109,0,45,121,48,13,160,133,205,96,223,139,179,76,141,151,183,74,156,153,101,48,136]
        ],
        "namespace"
    ]
}
```

Success response should return true and false

```json
   {
    "jsonrpc": "2.0",
    "result": [
        true
    ],
    "id": 128
}
```

!!! In case there is no data in storage(means nothing was submitted before) it returns `false` validation result

`ERROR RESPONSE` In case the request has invalid params

```json
{
    "jsonrpc":"2.0",
    "id": 128,
    "method": "submit",
    "params": [22]
}
```

it returns params validation error:

```json
{
    "jsonrpc": "2.0",
    "error": {
        "code": -32602,
        "message": "Invalid params",
        "data": "invalid type: integer `22`, expected byte array at line 1 column 3"
    },
    "id": 128
}
```
