diff --git a/cmd/api.go b/cmd/api.go index 8b97d076c..2d1ce79df 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -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) diff --git a/docs/rest-server.md b/docs/rest-server.md new file mode 100644 index 000000000..cdb3ac958 --- /dev/null +++ b/docs/rest-server.md @@ -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"}}} + +``` \ No newline at end of file