Skip to content

Commit

Permalink
readme: added status usage
Browse files Browse the repository at this point in the history
  • Loading branch information
0xluk committed Jan 15, 2024
1 parent d046a56 commit bf0bfc6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 14 deletions.
37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,30 @@ $ curl "localhost:8080/v1/bx/bacab66e7cbbb950c8b80facef94c5f0bf478ee3ab8ac270f54
}
```

## Getting bx by id:
```bash
$ curl "localhost:8080/v1/status"
{
"epoch": 91,
"bxid": [
91,
12017682
],
"txid": [
91,
12017336
],
"quorum": [
91,
12017688
],
"tick": [
91,
12017336
]
}
```

## Getting latest tick info:
```bash
$ curl "localhost:8080/v1/tick-info"
Expand Down Expand Up @@ -142,19 +166,6 @@ $ curl "localhost:8080/v1/tick-transactions/11922277"
]
```

## Getting tx status:
```bash
$ curl "localhost:8080/v1/get-tx-status" --json '{"tick": 11400055, "digest": "c5cea11f54ca18317aef20287e3b33b2e0c9a6c94aeec91c30fe793be1d27fec"}'
{
"current_tick_of_node": 11406937,
"tick": 11400055,
"money_flew": false,
"executed": true,
"not_found": false,
"hex_digest": "c5cea11f54ca18317aef20287e3b33b2e0c9a6c94aeec91c30fe793be1d27fec"
}
```

## Send raw tx:
```bash
$ curl "localhost:8080/v1/send-raw-tx" --json '{"hex_raw_tx": "C872E68E1C0ECCCE3BC6A87BC32E187C59BBA99AB81D7CC37E7D22F7423672A70E4EAF16A2218457BA8B46991B5CCA63E65AE65FF65C575A06743E40E8DA982A0100000000000000C60DAE0000000000A1C0B21A5C15D72275F7968D30A4F0520075F85A0232E180A5FC6C0137CC414F402404CF40773F444A25BCF30B6455B18A18FF7DD105F3223EECA8C566781A00"}'
Expand Down
5 changes: 4 additions & 1 deletion app/server/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ func New(shutdown chan os.Signal, log *log.Logger, pool *nodes.Pool, osclient *o

txH := txHandler{pool: pool, opensearchClient: osclient}
app.Handle(http.MethodPost, "/v1/send-raw-tx", txH.SendRawTx)
app.Handle(http.MethodPost, "/v1/get-tx-status", txH.GetTxStatus)
//app.Handle(http.MethodPost, "/v1/get-tx-status", txH.GetTxStatus)
app.Handle(http.MethodGet, "/v1/tx/:txID", txH.GetTx)
app.Handle(http.MethodGet, "/v1/bx/:bxID", txH.GetBx)

sh := statusHandler{opensearchClient: osclient}
app.Handle(http.MethodGet, "/v1/status", sh.GetStatus)


return app
}
21 changes: 21 additions & 0 deletions app/server/handlers/status.go
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
package handlers

import (
"context"
"github.com/pkg/errors"
"github.com/qubic/qubic-http/external/opensearch"
"github.com/qubic/qubic-http/foundation/web"
"net/http"
)

type statusHandler struct {
opensearchClient *opensearch.Client
}

func (h *statusHandler) GetStatus(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
status, err := h.opensearchClient.GetStatus(ctx)
if err != nil {
return errors.Wrap(err, "getting status from opensearch")
}

return web.Respond(ctx, w, status, http.StatusOK)
}
8 changes: 8 additions & 0 deletions external/opensearch/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ type BxResponse struct {
Destination string `json:"dest"`
Amount string `json:"amount"`
}

type StatusResponse struct {
Epoch int `json:"epoch"`
BxID []int `json:"bxid"`
TxID []int `json:"txid"`
Quorum []int `json:"quorum"`
Tick []int `json:"tick"`
}
12 changes: 12 additions & 0 deletions external/opensearch/opensearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ func (c *Client) GetBx(ctx context.Context, id string) (BxResponse, error) {
return bx, nil
}

func (c *Client) GetStatus(ctx context.Context) (StatusResponse, error) {
url := c.Host + "/status/_doc/api"

var status StatusResponse
err := c.performRequest(ctx,url, http.MethodGet, nil, http.StatusOK, &status)
if err != nil {
return StatusResponse{}, errors.Wrap(err, "performing request")
}

return status, nil
}

func (c *Client) performRequest(ctx context.Context, url string, method string, payload io.Reader, expectedStatusCode int, responseDest interface{}) error {
req, err := http.NewRequestWithContext(ctx, method, url, payload)
if err != nil {
Expand Down

0 comments on commit bf0bfc6

Please sign in to comment.