FORMAT: 1A

# Pocket Node WebSocket Endpoint
This is the blueprint for the Pocket Node WebSocket API Endpoint.

# Error Messages

## Message processing errors
These errors happen before the blockchain processing the message and are mostly related to the 
request following the correct structure or the requested network not being available in this node.
Message processing errors have the following structure:

```
{
    "error": true,
    "error_msg": "Network not found",
    "request": "{Your original message object is echoed here}"
}
```

## Blockchain processing errors
These errors happen when the submitted query or transaction is not valid after it's processed by the
actual network is intended for. Both queries and transaction have their own `error` and `error_msg` properties
within the `payload` property described below.

# Message ID
In the endpoints described below, you will find an `id` property as part of every request. 
This ID property is purely for client-side use, and is intended to match a response message with it's 
appropiate request. The `id` property can be either a `String` or a `Number`.

# Message URL
The URL described below are purely for illustration purposes, the only available route for WebSocket
connection is the root `/` path. The message routing will be done based on the `url` parameter on each message.

# Group Health
Represents the Node information and configuration, including what networks it supports.

# Health [/health]

## Retrieve Node Health Information [POST]

+ Request  (text/json)

        {
            "id": 1,
            "url": "/health",
            "payload": {}
        }


+ Response 200 (text/json)

        {
            "id": 1,
            "url": "/health",
            "payload":
            {
                "version": "0.0.1",
                "networks": [
                    {
                        network: "ETH",
                        version: "0.0.6",
                        package_name: "pnp-eth",
                        subnetworks: ["5777"]
                    }
                ]
            }
        }

# Group Queries
A query is a transaction to read data from the specified network. The `query` object will be described per network plugin,
see `/health` to determine which plugin a given Pocket Node is using to service requests for a given network (e.g. ETH).
The `result` attribute in the response can be either an `Object`, an `Array`, a `String` or a `Number`.

# Queries [/queries]

## Submit a Query [POST]

+ Request  (text/json)

        {
            "id": 2,
            "url": "/queries",
            "payload":
                {
                    "network": "ETH",
                    "subnetwork": "5777",
                    "query": {
                        "rpc_method": "eth_getBalance",
                        "rpc_params": ["0x0", "latest"]
                    },
                    "decoder": {}
                }
        }

+ Response 200 (text/json)


        {
            "id": 2,
            "url": "/queries",
            "payload":
                {
                    "network": "ETH",
                    "subnetwork": "4",
                    "query": {
                        "rpc_method": "eth_getBalance",
                        "rpc_params": ["0x0", "latest"]
                    },
                    "decoder": {},
                    "result": "{Object containing result}|[Array containing multiple results]|'String value'|Numeric Value",
                    "decoded": false,
                    "error": false,
                    "error_msg": null
                }
        }
        
# Group Transactions
A transaction is an operation that alters the state of the network. Most networks accept signed transactions
coded as hex strings, and these should be the input of the `serialized_tx` field. The `tx_metadata` is for 
networks that required different data structures to represent a transaction. No Pocket Node is going to sign a transaction,
signatures must happen client-side. 

# Transactions [/transactions]

## Submit a Transaction [POST]

+ Request  (text/json)


        {
            "id": 3,
            "url": "/transactions",
            "payload":
                {
                    {
                        "network": "ETH",
                        "subnetwork": "4",
                        "serialized_tx": "0x0",
                        "tx_metadata": {}
                    }
                }
        }
        

+ Response 200 (text/json)


        {
            "id": 3,
            "url": "/transactions",
            "payload":
                {
                    "network": "ETH",
                    "subnetwork": "4",
                    "serialized_tx": "0x000",
                    "tx_metadata": {},
                    "hash": "0x000",
                    "metadata": {},
                    "error": false,
                    "error_msg": null
                }
        }
        
