Skip to content

Commit

Permalink
Add rest server doc
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilkumarpilli committed Feb 4, 2021
1 parent 16bf3df commit bc84060
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 19 deletions.
19 changes: 0 additions & 19 deletions cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,25 +184,6 @@ func getAPICmd() *cobra.Command {
// Data for this should be stored in the ServicesManager struct
r.HandleFunc("/listen/{path}/{strategy}/{name}", PostRelayerListenHandler(sm)).Methods("POST")

// TODO: do we want to add the transaction commands here to?
// initial thoughts: expose high level transactions
// tx create-clients
// POST /paths/{name}/clients
// tx update-clients
// PUT /paths/{name}/clients
// tx connection
// POST /paths/{name}/connections
// tx channel
// POST /paths/{name}/channels
// tx link
// POST /paths/{name}/link
// tx relay-packets
// POST /paths/{name}/relay/packets
// tx relay-acks
// POST /paths/{name}/relay/acks
// tx transfer
// POST /paths/{name}/transfers

// TODO: listen validation in config
fmt.Println("listening on", config.Global.APIListenPort)

Expand Down
74 changes: 74 additions & 0 deletions docs/rest-server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Rest Server

## rly api

To start rest server, just run command `rly api`. This will start local server by default on `0.0.0.0:5183`. To modify api listen address, please edit `global.api-listen-addr` value in `~/.relayer/config/config.yaml` file.

```shell
$ rly api
listening on :5183
```

## Testing

Start two test chains for testing rest-server by running below commands:

```bash
# ensure go and jq are installed
# Go Documentation: https://golang.org/doc/install
# jq Documentation: https://stedolan.github.io/jq/download

# First, download and build the gaia source code so we have a working blockchain to test against
$ make get-gaia build-gaia

# two-chainz creates two gaia-based chains with data directories in this repo
# it also builds and configures the relayer for operations with those chains
$ ./scripts/two-chainz
# NOTE: If you want to stop the two gaia-based chains running in the background use `killall gaiad`

# At this point the relayer --home directory is ready for normal operations between
# ibc-0 and ibc-1. Looking at the folder structure of the relayer at this point is helpful
```

Now, lets test some rest routes using `curl` command in shell:

```bash
# Get all the chains that are ready to relay over
$ curl http://localhost:5183/chains

[{"key":"testkey","chain-id":"ibc-0","rpc-addr":"http://localhost:26657","account-prefix":"cosmos","gas-adjustment":1.5,"gas-prices":"0.025stake","trusting-period":"336h"},{"key":"testkey","chain-id":"ibc-1","rpc-addr":"http://localhost:26557","account-prefix":"cosmos","gas-adjustment":1.5,"gas-prices":"0.025stake","trusting-period":"336h"}]

# Add a new chain
# Here we are sending request body json as value to -d flag in curl
$ curl -d '{"key":"testkey3","rpc-addr":"http://localhost:26657","account-prefix":"ibc","gas-adjustment":"2","gas-prices":"0.05stake","trusting-period":"33h"}' -H 'Content-Type: application/json' http://localhost:5183/chains/ibc-2

"chain ibc-2 added successfully"

# Add new path to relay over
$ curl -d '{"src-chain-id":"ibc-0","dst-chain-id":"ibc-1","src":{"client-id":"","connection-id":"","channel-id":"","port-id":"transfer","order":"unordered","version":"ics20-1"},"dst":{"client-id":"","connection-id":"","channel-id":"","port-id":"transfer","order":"unordered","version":"ics20-1"}}' -H 'Content-Type: application/json' http://localhost:5183/paths/demo-path

# Here we are creating path by sending data in format
{
src-chain-id string
dst-chain-id string
src PathEnd
dst PathEnd
}

# We can also create path by sending file path instead of src and dst data in below format
{
file string
src-chain-id string
dst-chain-id string
}

$ curl -d '{"file":"/root/go/src/github.com/cosmos/relayer/configs/akash/demo.json","src-chain-id":"ibc-0","dst-chain-id":"ibc-1"}' -H 'Content-Type: application/json' http://localhost:5183/paths/demo2

"path demo2 added successfully"

# Get all paths
$ curl http://localhost:5183/paths

{"demo-path":{"src":{"chain-id":"ibc-0","client-id":"07-tendermint-0","connection-id":"connection-0","channel-id":"channel-0","port-id":"transfer","order":"unordered","version":"ics20-1"},"dst":{"chain-id":"ibc-1","client-id":"07-tendermint-0","connection-id":"connection-0","channel-id":"channel-0","port-id":"transfer","order":"unordered","version":"ics20-1"},"strategy":{"type":"naive"}},"demo2":{"src":{"chain-id":"ibc-0","port-id":"transfer","order":"unordered","version":"ics20-1"},"dst":{"chain-id":"ibc-1","port-id":"transfer","order":"unordered","version":"ics20-1"},"strategy":{"type":"naive"}}}

```

0 comments on commit bc84060

Please sign in to comment.