fix: move latest tx to dashboard domain

This commit is contained in:
Mohamed Sohail 2022-05-25 18:57:53 +03:00
parent 5d2ac7c275
commit da9716f695
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
5 changed files with 14 additions and 25 deletions

View File

@ -28,4 +28,5 @@ func InitDashboardApi(e *echo.Echo, db *pgxpool.Pool, queries goyesql.Queries) {
g.GET("/transactions-count", handleTransactionsCount)
g.GET("/token-transactions-count/:address", handleTokenTransactionsCount)
g.GET("/token-volume/:address", handleTokenVolume)
g.GET("/latest-token-transactions/:address", handleLatestTokenTransactions)
}

View File

@ -1,14 +1,12 @@
package public
package dashboard
import (
"cic-dw/pkg/pagination"
"context"
"net/http"
"time"
"github.com/georgysavva/scany/pgxscan"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
)
type tokenTransactionsRes struct {
@ -22,27 +20,15 @@ type tokenTransactionsRes struct {
Success bool `db:"success" json:"success"`
}
func handleTokenTransactions(c echo.Context) error {
func handleLatestTokenTransactions(c echo.Context) error {
var (
api = c.Get("api").(*api)
token = c.Param("address")
pg = pagination.GetPagination(c.QueryParams())
data []tokenTransactionsRes
)
if pg.Cursor == -1 {
var max int64
if err := api.db.QueryRow(context.Background(), "SELECT MAX(id) + 10 from transactions").Scan(&max); err != nil {
return err
}
pg.Cursor = int(max)
}
log.Info().Msgf("%d", pg.Cursor)
rows, err := api.db.Query(context.Background(), api.q["latest-token-transactions"], token, pg.Cursor, pg.PerPage)
rows, err := api.db.Query(context.Background(), api.q["latest-token-transactions"], token)
if err != nil {
return err
}
@ -51,5 +37,9 @@ func handleTokenTransactions(c echo.Context) error {
return err
}
if len(data) < 1 {
data = []tokenTransactionsRes{}
}
return c.JSON(http.StatusOK, data)
}

View File

@ -37,5 +37,4 @@ func InitPublicApi(e *echo.Echo, db *pgxpool.Pool, batchBalance *batch_balance.B
g.GET("/tokens", handleTokenListQuery)
g.GET("/token/:address", handleTokenInfo)
g.GET("/token-summary/:address", handleTokenSummary)
g.GET("/latest-token-transactions/:address", handleTokenTransactions)
}

View File

@ -69,3 +69,8 @@ AND transactions.success = true
GROUP BY date_range.day
ORDER BY date_range.day
LIMIT 730;
--name: latest-token-transactions
-- Returns latest token transactions, with curosr forward query and limit
SELECT id, block_number, date_block, tx_hash, sender_address, recipient_address, tx_value, success FROM transactions
WHERE token_address = $1 AND date_block > TIMESTAMP 'yesterday' ORDER BY id DESC;

View File

@ -45,10 +45,4 @@ SELECT COUNT(*) FROM transactions
WHERE token_address = $1
AND transactions.sender_address NOT IN (SELECT sys_address FROM exclude)
AND transactions.recipient_address NOT IN (SELECT sys_address FROM exclude)
AND transactions.success = true;
--name: latest-token-transactions
-- Returns latest token transactions, with curosr forward query and limit
SELECT transactions.id, transactions.block_number, transactions.date_block, transactions.tx_hash, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success FROM transactions
WHERE transactions.token_address = $1 AND transactions.id < $2 ORDER BY transactions.id DESC LIMIT $3;
AND transactions.success = true;